From d1f81628733ce03d72540d72327ed42638fffebc Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 4 Oct 2023 13:18:08 +0300 Subject: [PATCH] make deflector apply to "shit" and "unpin" award --- files/classes/user.py | 4 ++-- files/helpers/config/awards.py | 4 ++-- files/routes/awards.py | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index c6cf8b511..4ab8c0644 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -562,12 +562,12 @@ class User(Base): @property @lazy def awards_content_effect(self): - return [x for x in self.user_awards if not x['deflectable'] and x['kind'] != 'benefactor'] + return [x for x in self.user_awards if x['cosmetic'] or x['kind'] in {"pin", "unpin"}] @property @lazy def awards_author_effect(self): - return [x for x in self.user_awards if x not in self.awards_content_effect] + return [x for x in self.user_awards if not x['cosmetic'] and x['kind'] not in {"pin", "unpin"}] @property @lazy diff --git a/files/helpers/config/awards.py b/files/helpers/config/awards.py index 0b7171420..720dd9de9 100644 --- a/files/helpers/config/awards.py +++ b/files/helpers/config/awards.py @@ -431,7 +431,7 @@ AWARDS = { "icon": "fas fa-poop", "color": "text-black-50", "price": 300, - "deflectable": False, + "deflectable": True, "cosmetic": True, "ghost": True, "enabled": True, @@ -639,7 +639,7 @@ AWARDS = { "icon": "fas fa-thumbtack fa-rotate--45", "color": "text-black", "price": 1000, - "deflectable": False, + "deflectable": True, "cosmetic": False, "ghost": True, "enabled": True, diff --git a/files/routes/awards.py b/files/routes/awards.py index 262e1c3dc..7f5b79b92 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -209,6 +209,11 @@ def award_thing(v, thing_type, id): send_repeatable_notification(v.id, msg) author = v safe_username = f"Your award has been deflected but failed since you're" + + if kind == 'shit': + awarded_coins = int(AWARDS[kind]['price'] * COSMETIC_AWARD_COIN_AWARD_PCT) + v.charge_account('coins', awarded_coins, should_check_balance=False) + thing.author.pay_account('coins', awarded_coins) elif kind != 'spider': if AWARDS[kind]['cosmetic']: awarded_coins = int(AWARDS[kind]['price'] * COSMETIC_AWARD_COIN_AWARD_PCT) @@ -309,19 +314,20 @@ def award_thing(v, thing_type, id): cache.delete_memoized(frontlist) elif kind == "unpin": if not thing.stickied_utc: abort(400) - if thing.author_id == LAWLZ_ID and SITE_NAME == 'rDrama': abort(403, "You can't unpin lawlzposts!") + if not thing.author.deflector: + if thing.author_id == LAWLZ_ID and SITE_NAME == 'rDrama': abort(403, "You can't unpin lawlzposts!") - if thing_type == 'comment': - t = thing.stickied_utc - 3600*6 - else: - t = thing.stickied_utc - 3600 + if thing_type == 'comment': + t = thing.stickied_utc - 3600*6 + else: + t = thing.stickied_utc - 3600 - if time.time() > t: - thing.stickied = None - thing.stickied_utc = None - cache.delete_memoized(frontlist) - else: thing.stickied_utc = t - g.db.add(thing) + if time.time() > t: + thing.stickied = None + thing.stickied_utc = None + cache.delete_memoized(frontlist) + else: thing.stickied_utc = t + g.db.add(thing) elif kind == "queen": if author.chud: abort(409, f"{safe_username} under the effect of a conflicting award: Chud award!")