make hat designers gets their own hat for free

master
Aevann1 2022-09-05 09:59:24 +02:00
parent 64f95f1fca
commit b166fdcaf3
2 changed files with 12 additions and 7 deletions

View File

@ -290,17 +290,23 @@ def comment(v):
copyfile(oldname, filename) copyfile(oldname, filename)
process_image(filename, 200) process_image(filename, 200)
hat = HatDef( hat_def = HatDef(
name=name, name=name,
description=hat["description"], description=hat["description"],
author_id=user.id, author_id=user.id,
price=hat["price"] price=hat["price"]
) )
g.db.add(hat_def)
g.db.flush()
hat = Hat(
user_id=user.id,
hat_id=hat_def.id
)
g.db.add(hat) g.db.add(hat)
all_by_author = g.db.query(HatDef).filter_by(author_id=user.id).count() all_by_author = g.db.query(HatDef).filter_by(author_id=user.id).count()
# off-by-one: newly added hat isn't counted
if all_by_author >= 250: if all_by_author >= 250:
badge_grant(badge_id=166, user=user) badge_grant(badge_id=166, user=user)
elif all_by_author >= 100: elif all_by_author >= 100:

View File

@ -58,11 +58,10 @@ def buy_hat(v, hat_id):
g.db.add(v) g.db.add(v)
g.db.add(hat.author) g.db.add(hat.author)
if v.id != hat.author.id: send_repeatable_notification(
send_repeatable_notification( hat.author.id,
hat.author.id, f":marseycapitalistmanlet: @{v.username} has just bought `{hat.name}`, you have received your 10% cut ({int(hat.price * 0.1)} {currency}) :!marseycapitalistmanlet:"
f":marseycapitalistmanlet: @{v.username} has just bought `{hat.name}`, you have received your 10% cut ({int(hat.price * 0.1)} {currency}) :!marseycapitalistmanlet:" )
)
if v.num_of_owned_hats >= 250: if v.num_of_owned_hats >= 250:
badge_grant(user=v, badge_id=154) badge_grant(user=v, badge_id=154)