From f8ae2a3d17c6be457b76c596e205430896b16cd0 Mon Sep 17 00:00:00 2001 From: TLSM Date: Wed, 15 Jun 2022 16:08:26 -0400 Subject: [PATCH] Amend 3bc98f0a6b84: minor logic, style. --- files/helpers/actions.py | 16 ++++++++++------ files/routes/comments.py | 5 +---- files/routes/login.py | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 624f6a356..0cd7f10e1 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -2,16 +2,20 @@ from flask import g from files.classes.badges import Badge from files.helpers.alerts import send_repeatable_notification -def badge_grant(user, badge_id): - - if user.has_badge(badge_id): return +def badge_grant(user, badge_id, description=None, url=None): + if not user or user.has_badge(badge_id): + return badge = Badge( - badge_id=int(badge_id), - user_id=user.id + badge_id=int(badge_id), + user_id=user.id, + description=description, + url=url, ) g.db.add(badge) g.db.flush() - send_repeatable_notification(user.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") + send_repeatable_notification(user.id, + f"@AutoJanny has given you the following profile badge:\n\n" + + f"![]({badge.path})\n\n{badge.name}") diff --git a/files/routes/comments.py b/files/routes/comments.py index 5edf7491f..3d6d05493 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -279,14 +279,11 @@ def api_comment(v): all_by_author = g.db.query(Marsey).filter_by(author_id=user.id).count() - if all_by_author >= 9: + if all_by_author >= 10: badge_grant(badge_id=16, user=user) - - else: badge_grant(badge_id=17, user=user) - requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data='{"files": ["https://%s/e/%s.webp"]}' % (request.host, name), timeout=5) cache.delete_memoized(marsey_list) diff --git a/files/routes/login.py b/files/routes/login.py index da204d87b..03c12c2a9 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -338,9 +338,9 @@ def sign_up_post(v): if ref_user: badge_grant(user=ref_user, badge_id=10) - if ref_user.referral_count >= 9: + if ref_user.referral_count >= 10: badge_grant(user=ref_user, badge_id=11) - if ref_user.referral_count >= 99: + if ref_user.referral_count >= 100: badge_grant(user=ref_user, badge_id=12) if email: