fix awards remaining in "give award" after homoween was gone

pull/216/head
Aevann 2023-11-01 23:52:46 +03:00
parent 920836663e
commit 1592f103ec
3 changed files with 9 additions and 11 deletions

View File

@ -543,7 +543,7 @@ class User(Base):
@property
@lazy
def user_awards(self):
return_value = list(AWARDS_ENABLED.values())
return_value = list(AWARDS_ENABLED().values())
if self.house:
return_value.append(HOUSE_AWARDS[self.house])

View File

@ -971,10 +971,8 @@ AWARDS = {
},
}
AWARDS_ENABLED = {}
for k, val in AWARDS.items():
if val["enabled"]:
AWARDS_ENABLED[k] = val
def AWARDS_ENABLED():
return {k: v for k, v in AWARDS.items() if v["enabled"]}
LOOTBOX_ITEM_COUNT = 5

View File

@ -33,7 +33,7 @@ def shop_awards(v):
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def shop(v):
AWARDS = deepcopy(AWARDS_ENABLED)
AWARDS = deepcopy(AWARDS_ENABLED())
if v.house:
AWARDS[v.house] = deepcopy(HOUSE_AWARDS[v.house])
@ -84,7 +84,7 @@ def buy_award(v, kind, AWARDS):
if kind == "lootbox":
lootbox_items = []
for _ in range(LOOTBOX_ITEM_COUNT): # five items per lootbox
LOOTBOX_CONTENTS = [x["kind"] for x in AWARDS_ENABLED.values() if x["included_in_lootbox"]]
LOOTBOX_CONTENTS = [x["kind"] for x in AWARDS_ENABLED().values() if x["included_in_lootbox"]]
lb_award = random.choice(LOOTBOX_CONTENTS)
lootbox_items.append(AWARDS[lb_award]['title'])
lb_award = AwardRelationship(user_id=v.id, kind=lb_award, price_paid=price // LOOTBOX_ITEM_COUNT)
@ -122,7 +122,7 @@ def buy_award(v, kind, AWARDS):
@limiter.limit("100/minute;200/hour;1000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def buy(v, kind):
AWARDS = deepcopy(AWARDS_ENABLED)
AWARDS = deepcopy(AWARDS_ENABLED())
if v.house:
AWARDS[v.house] = HOUSE_AWARDS[v.house]
@ -162,7 +162,7 @@ def award_thing(v, thing_type, id):
author = obj.author
AWARDS = deepcopy(AWARDS_ENABLED)
AWARDS = deepcopy(AWARDS_ENABLED())
if v.house:
AWARDS[v.house] = HOUSE_AWARDS[v.house]
@ -648,12 +648,12 @@ def trick_or_treat(v):
if result == 0:
message = "Trick!"
else:
choices = [x["kind"] for x in AWARDS_ENABLED.values() if x["included_in_lootbox"]]
choices = [x["kind"] for x in AWARDS_ENABLED().values() if x["included_in_lootbox"]]
award = random.choice(choices)
award_object = AwardRelationship(user_id=v.id, kind=award)
g.db.add(award_object)
award_title = AWARDS_ENABLED[award]['title']
award_title = AWARDS_ENABLED()[award]['title']
message = f"Treat! You got a {award_title} award!"
return {"message": f"{message}", "result": f"{result}"}