diff --git a/files/classes/user.py b/files/classes/user.py index 10d3f3458..8e4cc0a24 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -98,6 +98,7 @@ class User(Base): sigs_disabled = Column(Boolean) fish = Column(Boolean) progressivestack = Column(Integer) + deflector = Column(Integer) friends = deferred(Column(String)) friends_html = deferred(Column(String)) enemies = deferred(Column(String)) diff --git a/files/helpers/const.py b/files/helpers/const.py index 81a04f607..eacdc70de 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -470,6 +470,14 @@ AWARDS = { "color": "text-blue", "price": 4000 }, + "deflector": { + "kind": "deflector", + "title": "deflector", + "description": "Causes all awards received for the next 10 hours to be deflected back at their giver.", + "icon": "fas fa-shield", + "color": "text-pink", + "price": 7000 + }, "grass": { "kind": "grass", "title": "Grass", diff --git a/files/routes/awards.py b/files/routes/awards.py index e5fb9fc5a..b890cb9f9 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -229,14 +229,20 @@ def award_post(pid, v): if author.id == PIZZASHILL_ID: return {"error": "Pizzashill is immune to awards."}, 403 - if v.id != author.id: + if kind == "benefactor" and author.id == v.id: + return {"error": "You can't use this award on yourself."}, 400 + + if author.deflector: + msg = f"@{v.username} has tried to give your [post]({post.shortlink}) the {AWARDS[kind]['title']} Award but it was deflected and applied to them :marseytroll:" + send_repeatable_notification(author.id, msg) + msg = f"@{author.username} is under the effect of a deflector award; your {AWARDS[kind]['title']} Award has been deflected back to you :marseytroll:" + send_repeatable_notification(v.id, msg) + author = v + elif v.id != author.id: msg = f"@{v.username} has given your [post]({post.shortlink}) the {AWARDS[kind]['title']} Award!" if note: msg += f"\n\n> {note}" send_repeatable_notification(author.id, msg) - if kind == "benefactor" and author.id == v.id: - return {"error": "You can't use this award on yourself."}, 400 - if kind == "ban": link = f"[this post]({post.shortlink})" @@ -402,6 +408,9 @@ def award_post(pid, v): g.db.add(badge) g.db.flush() send_notification(author.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") + elif kind == "deflector": + if author.deflector: author.deflector += 36000 + else: author.deflector = int(time.time()) + 36000 if author.received_award_count: author.received_award_count += 1 else: author.received_award_count = 1 @@ -450,7 +459,13 @@ def award_comment(cid, v): if author.id == PIZZASHILL_ID: return {"error": "Pizzashill is immune to awards."}, 403 - if v.id != author.id: + if author.deflector: + msg = f"@{v.username} has tried to give your [comment]({c.shortlink}) the {AWARDS[kind]['title']} Award but it was deflected and applied to them :marseytroll:" + send_repeatable_notification(author.id, msg) + msg = f"@{author.username} is under the effect of a deflector award; your {AWARDS[kind]['title']} Award has been deflected back to you :marseytroll:" + send_repeatable_notification(v.id, msg) + author = v + elif v.id != author.id: msg = f"@{v.username} has given your [comment]({c.shortlink}) the {AWARDS[kind]['title']} Award!" if note: msg += f"\n\n> {note}" send_repeatable_notification(author.id, msg) @@ -458,6 +473,8 @@ def award_comment(cid, v): if kind == "benefactor" and author.id == v.id: return {"error": "You can't use this award on yourself."}, 400 + if author.deflector: author = v + if kind == "ban": link = f"[this comment]({c.shortlink})" @@ -620,6 +637,9 @@ def award_comment(cid, v): g.db.add(badge) g.db.flush() send_notification(author.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") + elif kind == "deflector": + if author.deflector: author.deflector += 36000 + else: author.deflector = int(time.time()) + 36000 if author.received_award_count: author.received_award_count += 1 else: author.received_award_count = 1 diff --git a/files/routes/front.py b/files/routes/front.py index aa53e4d73..3732b67db 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -271,6 +271,12 @@ def front_all(v, sub=None, subdomain=None): if badge: g.db.delete(badge) g.db.commit() + if v.deflector and v.deflector < time.time(): + v.deflector = None + send_repeatable_notification(v.id, "Your deflector has expired!") + g.db.add(v) + g.db.commit() + if request.headers.get("Authorization"): return {"data": [x.json for x in posts], "next_exists": next_exists} return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, ccmode=ccmode, sub=sub, home=True) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 2a40d325e..27e816dc6 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 33f9a4ee1..1d3a81cee 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -19,11 +19,6 @@
{{award.owned}} owned
{% endfor %} - - -
 
-
 
-
diff --git a/files/templates/default.html b/files/templates/default.html index 4c8c53530..8035690d3 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -12,7 +12,7 @@ --primary55:#{{v.themecolor}}55; } - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 34687a216..032e76994 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 4e59d64b2..01e008782 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 53ef86f6c..96eb9bb20 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 2ee829995..723e8293c 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index bd6431091..18cc247bc 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 4fb91516d..e549965ad 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index c371e0f28..e6b298ff3 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %}