From f8614d79cd8d036afce08123d58247bfd6a9fb43 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 16 Feb 2024 16:27:28 +0200 Subject: [PATCH] make top poster of the day get a badge --- files/helpers/useractions.py | 2 +- files/routes/jinja2.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/files/helpers/useractions.py b/files/helpers/useractions.py index bd7a32833..0cfc483e0 100644 --- a/files/helpers/useractions.py +++ b/files/helpers/useractions.py @@ -27,4 +27,4 @@ def badge_grant(user, badge_id, description=None, url=None, notify=True): if notify: send_repeatable_notification(user.id, "@AutoJanny has given you the following profile badge:\n\n" + - f"{badge.path}\n\n**{badge.name}**\n\n{badge.badge.description}") + f"{badge.path}\n\n**{badge.name}**\n\n{badge.badge.description}").created_utc += 1 diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index e2ec4f40b..407ad2acf 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -21,6 +21,7 @@ from files.helpers.cloudflare import * from files.helpers.sorting_and_time import make_age_string from files.helpers.can_see import * from files.helpers.alerts import send_notification +from files.helpers.useractions import * from files.routes.routehelpers import get_alt_graph, get_formkey from files.routes.wrappers import calc_users from files.__main__ import app, cache @@ -136,13 +137,15 @@ def poster_of_the_day_id(): db = db_session() - uid = db.query(User.id, func.sum(Post.upvotes)).join(Post, Post.author_id == User.id).filter( + user = db.query(User, func.sum(Post.upvotes)).join(Post, Post.author_id == User.id).filter( Post.created_utc > t, User.admin_level == 0, ).group_by(User.id).order_by(func.sum(Post.upvotes).desc()).first()[0] t = datetime.datetime.now() - send_notification(uid, f":marseyjam: You're the top poster of the day for the day of {t.year}-{t.month}-{t.day} :marseyjam:") + send_notification(user.id, f":marseyjam: You're the top poster of the day for the day of {t.year}-{t.month}-{t.day} :marseyjam:") + badge_grant(badge_id=327, user=user) + uid = user.id db.commit() db.close()