User.pay_account everywhere, fix lottery payout.

pull/2/head
Snakes 2022-11-20 05:50:02 -05:00
parent 858ccab4ec
commit db329f487f
Signed by: Snakes
GPG Key ID: E745A82778055C7E
12 changed files with 31 additions and 27 deletions

View File

@ -159,7 +159,7 @@ def execute_snappy(post, v):
check_slots_command(v, snappy, c)
snappy.comment_count += 1
snappy.coins += 1
snappy.pay_account('coins', 1)
g.db.add(snappy)
if FEATURES['PINS'] and (body.startswith(':#marseypin:') or body.startswith(':#marseypin2:')):
@ -241,7 +241,7 @@ def execute_zozbot(c, level, parent_submission, v):
zozbot = get_account(ZOZBOT_ID)
zozbot.comment_count += 3
zozbot.coins += 3
zozbot.pay_account('coins', 1)
g.db.add(zozbot)
def execute_longpostbot(c, level, body, body_html, parent_submission, v):
@ -273,7 +273,7 @@ def execute_longpostbot(c, level, body, body_html, parent_submission, v):
longpostbot = get_account(LONGPOSTBOT_ID)
longpostbot.comment_count += 1
longpostbot.coins += 1
longpostbot.pay_account('coins', 1)
g.db.add(longpostbot)
g.db.flush()
n = Notification(comment_id=c2.id, user_id=v.id)

View File

@ -120,9 +120,9 @@ def _give_monthly_marseybux_task():
emails = [x['email'] for x in requests.get(f'https://api.gumroad.com/v2/products/{GUMROAD_ID}/subscribers', data=data, timeout=5).json()["subscribers"]]
def give_procoins(u):
procoins = procoins_li[u.patron]
u.procoins += procoins
send_repeatable_notification(u.id, f"@AutoJanny has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
procoins_reward = procoins_li[u.patron]
u.pay_account('procoins', procoins_reward)
send_repeatable_notification(u.id, f"@AutoJanny has given you {procoins_reward} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
for badge in g.db.query(Badge).filter(Badge.badge_id > 20, Badge.badge_id < 28).all():
g.db.delete(badge)
@ -173,9 +173,9 @@ def _give_monthly_marseybux_task_kofi():
u.patron = 0
continue
procoins = procoins_li[u.patron]
u.procoins += procoins
send_repeatable_notification(u.id, f"@AutoJanny has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
procoins_reward = procoins_li[u.patron]
u.pay_account('procoins', procoins_reward)
send_repeatable_notification(u.id, f"@AutoJanny has given you {procoins_reward} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
ma = ModAction(
kind="monthly",

View File

@ -48,7 +48,7 @@ def end_lottery_session():
winner = choice(raffle)
active_lottery.winner_id = winner
winning_user = next(filter(lambda x: x.id == winner, participating_users))
winning_user.coins += active_lottery.prize
winning_user.pay_account('coins', active_lottery.prize)
winning_user.total_lottery_winnings += active_lottery.prize
badge_grant(user=winning_user, badge_id=LOTTERY_WINNER_BADGE_ID)
@ -65,6 +65,10 @@ def end_lottery_session():
active_lottery.is_active = False
g.db.add(winning_user)
g.db.add(active_lottery)
g.db.commit() # Intentionally commit early because cron runs with other tasks
return True, f'{winning_user.username} won {active_lottery.prize} coins!'
@ -80,6 +84,7 @@ def start_new_lottery_session():
lottery.is_active = True
g.db.add(lottery)
g.db.commit() # Intentionally commit early, not autocommitted from cron
def check_if_end_lottery_task():

View File

@ -42,6 +42,5 @@ def check_for_treasure(in_text, from_comment):
from_comment.treasure_amount = f'l{ticket_count}'
return
user.coins += amount
user.pay_account('coins', amount)
from_comment.treasure_amount = str(amount)

View File

@ -24,7 +24,7 @@ from .front import frontlist
def kippy(v):
if SITE != 'pcmemes.net': abort(404)
kippy = get_account(KIPPY_ID)
kippy.procoins += 10000
kippy.pay_account('procoins', 10000)
g.db.add(kippy)
return '10k marseybux printed!'
@ -224,7 +224,7 @@ def distribute(v, option_id):
cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:")
for vote in votes:
u = vote.user
u.coins += coinsperperson
u.pay_account('coins', coinsperperson)
add_notif(cid, u.id)
@ -1188,7 +1188,7 @@ def remove_post(post_id, v):
cache.delete_memoized(frontlist)
v.coins += 1
v.pay_account('coins', 1)
g.db.add(v)
purge_files_in_cache(f"https://{SITE}/")
return {"message": "Post removed!"}

View File

@ -153,7 +153,7 @@ def approve_marsey(v, name):
new_path = f'/asset_submissions/marseys/original/{name}.{i.format.lower()}'
rename(highquality, new_path)
author.coins += 250
author.pay_account('coins', 250)
g.db.add(author)
if v.id != author.id:

View File

@ -201,7 +201,7 @@ def award_thing(v, thing_type, id):
elif kind != 'spider':
awarded_coins = int(AWARDS[kind]['price'] * COSMETIC_AWARD_COIN_AWARD_PCT) if AWARDS[kind]['cosmetic'] else 0
if AWARDS[kind]['cosmetic']:
author.coins += awarded_coins
author.pay_account('coins', awarded_coins)
msg = f"@{v.username} has given your [{thing_type}]({thing.shortlink}) the {AWARDS[kind]['title']} Award"
if awarded_coins > 0:
@ -331,7 +331,7 @@ def award_thing(v, thing_type, id):
author.patron = 1
if author.patron_utc: author.patron_utc += 2629746
else: author.patron_utc = int(time.time()) + 2629746
author.procoins += 2500
author.pay_account('procoins', 2500)
badge_grant(user=v, badge_id=103)
elif kind == "rehab":
if author.rehab: author.rehab += 86400

View File

@ -51,14 +51,14 @@ def buy_hat(v, hat_id):
charged = v.charge_account('procoins', hat.price)
if not charged: abort(400, "Not enough marseybux.")
hat.author.procoins += hat.price * 0.1
hat.author.pay_account('procoins', hat.price * 0.1)
currency = "marseybux"
else:
charged = v.charge_account('coins', hat.price)
if not charged: abort(400, "Not enough coins.")
v.coins_spent_on_hats += hat.price
hat.author.coins += hat.price * 0.1
hat.author.pay_account('coins', hat.price * 0.1)
currency = "coins"
new_hat = Hat(user_id=v.id, hat_id=hat.id)

View File

@ -24,7 +24,7 @@ def vote_option(option_id, v):
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
autojanny.pay_account('coins', POLL_BET_COINS)
g.db.add(autojanny)
if option.exclusive:

View File

@ -366,7 +366,7 @@ def gumroad(v):
v.patron = tier
v.procoins += procoins
v.pay_account('procoins', procoins)
send_repeatable_notification(v.id, f"You have received {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).")
g.db.add(v)

View File

@ -302,9 +302,9 @@ def transfer_currency(v:User, username:str, currency_name:Literal['coins', 'proc
if not v.shadowbanned:
if currency_name == 'procoins':
receiver.procoins += amount - tax
receiver.pay_account('procoins', amount - tax)
elif currency_name == 'coins':
receiver.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)
@ -1108,7 +1108,7 @@ def settings_kofi(v):
tier = kofi_tiers[transaction.amount]
procoins = procoins_li[tier]
v.procoins += procoins
v.pay_account('procoins', procoins)
send_repeatable_notification(v.id, f"You have received {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).")
g.db.add(v)

View File

@ -82,7 +82,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
if existing and existing.vote_type == new: return "", 204
if existing:
if existing.vote_type == 0 and new != 0:
target.author.coins += coin_value
target.author.pay_account('coins', coin_value)
target.author.truescore += coin_delta
g.db.add(target.author)
existing.vote_type = new
@ -97,7 +97,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
existing.vote_type = new
g.db.add(existing)
elif new != 0:
target.author.coins += coin_value
target.author.pay_account('coins', coin_value)
target.author.truescore += coin_delta
g.db.add(target.author)