From 59af2e0ec6638a9bcce2f70bdb05443b701be508 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 13 Jan 2024 04:27:07 +0100 Subject: [PATCH] feat: notification connection --- notifications.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 notifications.py diff --git a/notifications.py b/notifications.py new file mode 100644 index 0000000..71cb4c5 --- /dev/null +++ b/notifications.py @@ -0,0 +1,24 @@ +import sys +import requests + +def send_notification(app, target_user, mapname, old_replay, new_replay): + '''Build notification and handoff to dispatcher''' + + url = app.config["DISPATCH_SERVER"] + + if not url: + return + + # send to event dispatcher # + message = "Trackmania: Record broken on {}".format(mapname) + message += "Old time: {}".format(old_replay.get_human_readable_time()) + message += "New time: {}".format(new_replay.get_human_readable_time()) + message += "by {}".format(new_replay.clean_login()) + + payload = { "users": [user], "msg" : message } + + r = requests.post(app.config["DISPATCH_SERVER"] + "/smart-send", + json=payload, auth=app.config["DISPATCH_AUTH"]) + + if not r.ok: + print("Error handing off notification to dispatch ({})".format(r.status_code), file=sys.stderr)