use charge_account everywhere

remotes/1693176582716663532/tmp_refs/heads/watchparty
justcool393 2022-11-01 00:25:19 -05:00
parent 905b070437
commit 6d636e4e42
7 changed files with 15 additions and 16 deletions

View File

@ -103,7 +103,8 @@ def purchase_lottery_tickets(v, quantity=1):
if (most_recent_lottery is None):
return False, "There is no active lottery."
v.charge_account('coins', LOTTERY_TICKET_COST * quantity)
if not v.charge_account('coins', LOTTERY_TICKET_COST * quantity):
return False, "You don't have enough coins"
v.currently_held_lottery_tickets += quantity
v.total_held_lottery_tickets += quantity

View File

@ -43,8 +43,6 @@ def shop(v):
@auth_required
@feature_required('AWARDS')
def buy(v, award):
if award == 'benefactor' and not request.values.get("mb"):
abort(403, "You can only buy the Benefactor award with marseybux.")

View File

@ -21,8 +21,8 @@ def vote_option(option_id, v):
abort(403, f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}")
if option.exclusive == 2:
if v.coins < POLL_BET_COINS: abort(400, f"You don't have {POLL_BET_COINS} coins!")
v.charge_account('coins', POLL_BET_COINS)
if not v.charge_account('coins', POLL_BET_COINS):
abort(400, f"You don't have {POLL_BET_COINS} coins!")
g.db.add(v)
autojanny = get_account(AUTOJANNY_ID)
autojanny.coins += POLL_BET_COINS

View File

@ -774,10 +774,7 @@ def submit_post(v, sub=None):
if embed and len(embed) > 1500: embed = None
if request.values.get("ghost") and v.coins >= 100:
v.charge_account('coins', 100)
ghost = True
else: ghost = False
ghost = request.values.get("ghost") and v.charge_account('coins', 100)
if embed: embed = embed.strip()

View File

@ -274,9 +274,10 @@ def settings_profile_post(v):
if v.house: cost = 2000
else: cost = 500
if v.coins >= cost: v.charge_account('coins', cost)
elif v.procoins >= cost: v.charge_account('procoins', cost)
else: abort(403)
success = v.charge_account('coins', cost)
if not success:
success = v.charge_account('procoins', cost)
if not success: abort(403)
if house == "None": house = ''
v.house = house

View File

@ -329,10 +329,9 @@ def create_sub2(v):
sub = get_sub_by_name(name, graceful=True)
if not sub:
if v.coins < HOLE_COST:
if not v.charge_account('coins', HOLE_COST):
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST, error="You don't have enough coins!"), 403
v.charge_account('coins', HOLE_COST)
g.db.add(v)
if v.shadowbanned: return {"error": "Internal Server Error"}, 500

View File

@ -272,7 +272,6 @@ def transfer_currency(v:User, username:str, currency_name:Literal['coins', 'proc
amount = int(amount) if amount.isdigit() else None
if amount is None or amount <= 0: abort(400, f"Invalid number of {friendly_currency_name}")
if v.coins < amount: abort(400, f"You don't have enough {friendly_currency_name}")
if amount < MIN_CURRENCY_TRANSFER: abort(400, f"You have to gift at least {MIN_CURRENCY_TRANSFER} {friendly_currency_name}")
tax = 0
if apply_tax and not v.patron and not receiver.patron and not v.alts_patron and not receiver.alts_patron:
@ -281,11 +280,15 @@ def transfer_currency(v:User, username:str, currency_name:Literal['coins', 'proc
reason = request.values.get("reason", "").strip()
log_message = f"@{v.username} has transferred {amount} {friendly_currency_name} to @{receiver.username}"
notif_text = f":marseycapitalistmanlet: @{v.username} has gifted you {amount-tax} {friendly_currency_name}!"
if reason:
if len(reason) > TRANSFER_MESSAGE_LENGTH_LIMIT: abort(400, f"Reason is too long, max {TRANSFER_MESSAGE_LENGTH_LIMIT} characters")
notif_text += f"\n\n> {reason}"
log_message += f"\n\n> {reason}"
v.charge_account(currency_name, amount)
if not v.charge_account(currency_name, amount):
abort(400, f"You don't have enough {friendly_currency_name}")
if not v.shadowbanned:
receiver.coins += amount - tax
g.db.add(receiver)