From cdff11424f699b195a4e7fc97c0039a44fd43d73 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 12 Oct 2022 18:33:00 +0200 Subject: [PATCH] use charge_account everywhere --- files/helpers/lottery.py | 3 +-- files/routes/admin.py | 4 ++-- files/routes/polls.py | 2 +- files/routes/posts.py | 2 +- files/routes/settings.py | 4 ++-- files/routes/subs.py | 2 +- files/routes/users.py | 4 ++-- files/routes/votes.py | 2 +- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/files/helpers/lottery.py b/files/helpers/lottery.py index e976e2b4d..3281eb73a 100644 --- a/files/helpers/lottery.py +++ b/files/helpers/lottery.py @@ -103,7 +103,7 @@ def purchase_lottery_tickets(v, quantity=1): if (most_recent_lottery is None): return False, "There is no active lottery." - v.coins -= LOTTERY_TICKET_COST * quantity + v.charge_account('coins', LOTTERY_TICKET_COST * quantity) v.currently_held_lottery_tickets += quantity v.total_held_lottery_tickets += quantity @@ -125,4 +125,3 @@ def grant_lottery_tickets_to_user(v, quantity): active_lottery.prize += prize_value active_lottery.tickets_sold += quantity - diff --git a/files/routes/admin.py b/files/routes/admin.py index bd2a4f82a..f7671134b 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -216,7 +216,7 @@ def distribute(v, option_id): if o.exclusive >= 2: pool += o.upvotes pool *= POLL_BET_COINS - autojanny.coins -= pool + autojanny.charge_account('coins', pool) if autojanny.coins < 0: autojanny.coins = 0 g.db.add(autojanny) @@ -1175,7 +1175,7 @@ def approve_post(post_id, v): cache.delete_memoized(frontlist) - v.coins -= 1 + v.charge_account('coins', 1) g.db.add(v) return {"message": "Post approved!"} diff --git a/files/routes/polls.py b/files/routes/polls.py index 71e6ab5f2..57c22ce9c 100644 --- a/files/routes/polls.py +++ b/files/routes/polls.py @@ -23,7 +23,7 @@ def vote_option(option_id, v): if option.exclusive == 2: if v.coins < POLL_BET_COINS: abort(400, f"You don't have {POLL_BET_COINS} coins!") - v.coins -= POLL_BET_COINS + v.charge_account('coins', POLL_BET_COINS) g.db.add(v) autojanny = get_account(AUTOJANNY_ID) autojanny.coins += POLL_BET_COINS diff --git a/files/routes/posts.py b/files/routes/posts.py index 7b474197c..4df9ed517 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -879,7 +879,7 @@ def submit_post(v, sub=None): is_bot = v.id != BBBB_ID and bool(request.headers.get("Authorization")) or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID) if request.values.get("ghost") and v.coins >= 100: - v.coins -= 100 + v.charge_account('coins', 100) ghost = True else: ghost = False diff --git a/files/routes/settings.py b/files/routes/settings.py index 27a128bd6..7a2480944 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -276,8 +276,8 @@ def settings_profile_post(v): if v.house: cost = 2000 else: cost = 500 - if v.coins >= cost: v.coins -= cost - elif v.procoins >= cost: v.procoins -= cost + if v.coins >= cost: v.charge_account('coins', cost) + elif v.procoins >= cost: v.charge_account('procoins', cost) else: abort(403) if house == "None": house = '' diff --git a/files/routes/subs.py b/files/routes/subs.py index 8784b0f9e..cf3e73af1 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -332,7 +332,7 @@ def create_sub2(v): if v.coins < HOLE_COST: return render_template("sub/create_hole.html", v=v, cost=HOLE_COST, error="You don't have enough coins!"), 403 - v.coins -= HOLE_COST + v.charge_account('coins', HOLE_COST) g.db.add(v) if v.shadowbanned: return {"error": "Internal Server Error"}, 500 diff --git a/files/routes/users.py b/files/routes/users.py index d71c7fb44..9ef49d1b1 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -271,7 +271,7 @@ def transfer_coins(v, username): if not v.patron and not receiver.patron and not v.alts_patron and not receiver.alts_patron: tax = math.ceil(amount*0.03) else: tax = 0 - v.coins -= amount + v.charge_account('coins', amount) if not v.shadowbanned: receiver.coins += amount - tax @@ -310,7 +310,7 @@ def transfer_bux(v, username): if v.procoins < amount: abort(400, "You don't have enough marseybux") if amount < 100: abort(400, "You have to gift at least 100 marseybux.") - v.procoins -= amount + v.charge_account('procoins', amount) if not v.shadowbanned: receiver.procoins += amount diff --git a/files/routes/votes.py b/files/routes/votes.py index 76a3df77d..cbf3e12de 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -86,7 +86,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls): existing.vote_type = new g.db.add(existing) elif existing.vote_type != 0 and new == 0: - target.author.coins -= coin_delta * coin_mult + target.author.charge_account('coins', coin_delta * coin_mult) target.author.truecoins -= coin_delta g.db.add(target.author) g.db.delete(existing)