forked from rDrama/rDrama
fix this https://rdrama.net/post/18459/marseycapywalking-megathread-for-bugs-and-suggestions/4691321#context
parent
9bb1482278
commit
10d138db5d
|
@ -203,11 +203,12 @@ class User(Base):
|
|||
if SITE == 'watchpeopledie.tv' and self.id == 5222:
|
||||
return
|
||||
|
||||
user_query = g.db.query(User).options(load_only(User.id)).filter_by(id=self.id)
|
||||
|
||||
if currency == 'coins':
|
||||
self.coins += amount
|
||||
user_query.update({ User.coins: User.coins + amount })
|
||||
else:
|
||||
self.marseybux += amount
|
||||
|
||||
user_query.update({ User.marseybux: User.marseybux + amount })
|
||||
|
||||
def charge_account(self, currency, amount, **kwargs):
|
||||
succeeded = False
|
||||
|
@ -215,18 +216,20 @@ class User(Base):
|
|||
|
||||
should_check_balance = kwargs.get('should_check_balance', True)
|
||||
|
||||
user_query = g.db.query(User).options(load_only(User.id)).filter_by(id=self.id)
|
||||
|
||||
if currency == 'coins':
|
||||
account_balance = self.coins
|
||||
|
||||
if not should_check_balance or account_balance >= amount:
|
||||
self.coins -= amount
|
||||
user_query.update({ User.coins: User.coins - amount })
|
||||
succeeded = True
|
||||
charged_coins = amount
|
||||
elif currency == 'marseybux':
|
||||
account_balance = self.marseybux
|
||||
|
||||
if not should_check_balance or account_balance >= amount:
|
||||
self.marseybux -= amount
|
||||
user_query.update({ User.marseybux: User.marseybux - amount })
|
||||
succeeded = True
|
||||
elif currency == 'combined':
|
||||
if self.marseybux >= amount:
|
||||
|
@ -238,8 +241,10 @@ class User(Base):
|
|||
if subtracted_coins > self.coins:
|
||||
return (False, 0)
|
||||
|
||||
self.coins -= subtracted_coins
|
||||
self.marseybux -= subtracted_mbux
|
||||
user_query.update({
|
||||
User.marseybux: User.marseybux - subtracted_mbux,
|
||||
User.coins: User.coins - subtracted_coins,
|
||||
})
|
||||
succeeded = True
|
||||
charged_coins = subtracted_coins
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None):
|
|||
if cost > v.coins:
|
||||
abort(403, f"You need {cost} coins to mention these ping groups!")
|
||||
|
||||
g.db.query(User).options(load_only(User.coins)).update({ User.coins: User.coins + 10 })
|
||||
g.db.query(User).options(load_only(User.id)).update({ User.coins: User.coins + 10 })
|
||||
|
||||
v.charge_account('coins', cost)
|
||||
if log_cost:
|
||||
|
@ -185,7 +185,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None):
|
|||
log_cost.ping_cost = cost
|
||||
|
||||
if total_members:
|
||||
g.db.query(User).options(load_only(User.coins)).filter(User.id.in_(total_members)).update({ User.coins: User.coins + 10 })
|
||||
g.db.query(User).options(load_only(User.id)).filter(User.id.in_(total_members)).update({ User.coins: User.coins + 10 })
|
||||
|
||||
v.charge_account('coins', cost)
|
||||
|
||||
|
|
|
@ -126,15 +126,12 @@ def transfer_currency(v, username, currency_name, apply_tax):
|
|||
abort(400, f"You don't have enough {currency_name}")
|
||||
|
||||
if not v.shadowbanned:
|
||||
user_query = g.db.query(User).filter_by(id=receiver.id)
|
||||
if currency_name == 'marseybux':
|
||||
user_query.options(load_only(User.marseybux)).update({ User.marseybux: User.marseybux + amount - tax })
|
||||
receiver.pay_account('marseybux', amount - tax)
|
||||
elif currency_name == 'coins':
|
||||
user_query.options(load_only(User.coins)).update({ User.coins: User.coins + amount - tax })
|
||||
receiver.pay_account('coins', amount - tax)
|
||||
else:
|
||||
raise ValueError(f"Invalid currency '{currency_name}' got when transferring {amount} from {v.id} to {receiver.id}")
|
||||
g.db.add(receiver)
|
||||
g.db.flush()
|
||||
if GIFT_NOTIF_ID: send_repeatable_notification(GIFT_NOTIF_ID, log_message)
|
||||
send_repeatable_notification(receiver.id, notif_text)
|
||||
g.db.add(v)
|
||||
|
|
Loading…
Reference in New Issue