From c28049b94cbccdd651b72aac4c86ecabec29f733 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 13 Jan 2024 04:49:25 +0100 Subject: [PATCH] fix: cleanup message & fix user query --- notifications.py | 11 ++++++----- server.py | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/notifications.py b/notifications.py index 71cb4c5..d6b8b55 100644 --- a/notifications.py +++ b/notifications.py @@ -10,12 +10,13 @@ def send_notification(app, target_user, mapname, old_replay, new_replay): 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()) + message = "TM: Record broken on {}\n\n".format(mapname) + message += "Old time: {}\n".format(old_replay.get_human_readable_time()) + message += "New time: {}\n".format(new_replay.get_human_readable_time()) + message += "\nby {}".format(new_replay.clean_login()) + + payload = { "users": [target_user], "msg" : message } - payload = { "users": [user], "msg" : message } r = requests.post(app.config["DISPATCH_SERVER"] + "/smart-send", json=payload, auth=app.config["DISPATCH_AUTH"]) diff --git a/server.py b/server.py index 195a89c..26e29a1 100755 --- a/server.py +++ b/server.py @@ -10,6 +10,7 @@ import datetime from pygbx import Gbx, GbxType import tm2020parser +import notifications import sqlalchemy from sqlalchemy import Column, Integer, String, Boolean, or_, and_, asc, desc @@ -421,12 +422,13 @@ def upload(): def check_replay_trigger(replay): - map_obj = db.session.get(Map).filter(Map.map_uid == replay.map_uid).first() - assert(map_uid) - + map_obj = db.session.query(Map).filter(Map.map_uid == replay.map_uid).first() best = map_obj.get_best_replay() second = map_obj.get_second_best_replay() + if not second: + return + if replay.filehash != best.filehash: return