From b166fdcaf35ff4c15af476ca2a8b009208702c68 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 5 Sep 2022 09:59:24 +0200 Subject: [PATCH] make hat designers gets their own hat for free --- files/routes/comments.py | 10 ++++++++-- files/routes/hats.py | 9 ++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index 82d84a87a..ae574206a 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -290,17 +290,23 @@ def comment(v): copyfile(oldname, filename) process_image(filename, 200) - hat = HatDef( + hat_def = HatDef( name=name, description=hat["description"], author_id=user.id, 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) 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: badge_grant(badge_id=166, user=user) elif all_by_author >= 100: diff --git a/files/routes/hats.py b/files/routes/hats.py index 7bdfe8969..2ad379376 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -58,11 +58,10 @@ def buy_hat(v, hat_id): g.db.add(v) g.db.add(hat.author) - if v.id != hat.author.id: - send_repeatable_notification( - 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:" - ) + send_repeatable_notification( + 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:" + ) if v.num_of_owned_hats >= 250: badge_grant(user=v, badge_id=154)