Skip to content

Instantly share code, notes, and snippets.

@trashguy
Last active June 7, 2019 20:49
Show Gist options
  • Save trashguy/910e4700671989c3303529e1bf21b651 to your computer and use it in GitHub Desktop.
Save trashguy/910e4700671989c3303529e1bf21b651 to your computer and use it in GitHub Desktop.
ATLAS Company Alert Relay
import tornado.httpserver
import tornado.ioloop
import tornado.web
import requests
"""
ATLAS requires the endpoint to have SSL and not use a port :(
https://atlas-relay.somesite.com
I used tornado to handle SSL but you could just toss it behind ngnix as well. LetsEncrypt is easy mode.
Requires tornado, easy to run in a docker container etc...
Example payload:
{'content': "**TC Holdings LLC (1818128628)**\nDay 1564, 11:05:50: Trashguy Maybe demolished a 'Thatch Square Ceiling' at A8 [Long: -92.82 / Lat: 3.47]!\nDay 1564, 12:52:29: Trashguy Maybe demolished a 'Thatch Square Ceiling' at A8 [Long: -92.82 / Lat: 3.47]!\n"}
"""
#Webhook for normal company log channel
RELAY_WEBHOOK = 'https://discordapp.com/api/webhooks/somewebhook'
#Webhoook for ALERT channel
ALERT_WEBHOOK = 'https://discordapp.com/api/webhooks/somewebhook'
#Keywords to look for in company log to forward to ALERT channel. IE O11 NPC has been killed...
KEYWORDS = [
'Your \'Stone Wall\' was destroyed!',
'(Crewmember) was killed',
'Wood Plank\' was destroyed!',
'Your \'Puckle\' was destroyed!'
]
class MainHandler(tornado.web.RequestHandler):
def post(self):
#If keyword then forward to alert channel
if any(keyword in tornado.escape.json_decode(self.request.body)['content'] for keyword in KEYWORDS):
requests.post(ALERT_WEBHOOK,json=tornado.escape.json_decode(self.request.body))
requests.post(RELAY_WEBHOOK,json=tornado.escape.json_decode(self.request.body))
else:
requests.post(RELAY_WEBHOOK,json=tornado.escape.json_decode(self.request.body))
application = tornado.web.Application([
(r'/', MainHandler),
])
if __name__ == '__main__':
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
"certfile": "/etc/letsencrypt/live/somesite/fullchain.pem",
"keyfile": "/etc/letsencrypt/live/somesite/privkey.pem",
})
http_server.listen(443)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment