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 @@