forked from MarseyWorld/MarseyWorld
make patron rewards automatic in WPD
parent
e18b5fd29d
commit
d34f836052
|
@ -42,9 +42,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
|
||||||
site_stats = stats.stats(SITE_NAME)
|
site_stats = stats.stats(SITE_NAME)
|
||||||
cache.set(f'{SITE}_stats', site_stats)
|
cache.set(f'{SITE}_stats', site_stats)
|
||||||
|
|
||||||
if every_1mo:
|
if every_1mo and not KOFI_LINK:
|
||||||
if KOFI_LINK: _give_monthly_marseybux_task_kofi()
|
_give_monthly_marseybux_task()
|
||||||
else: _give_monthly_marseybux_task()
|
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
g.db.close()
|
g.db.close()
|
||||||
|
@ -160,29 +159,3 @@ def _give_monthly_marseybux_task():
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _give_monthly_marseybux_task_kofi():
|
|
||||||
month = datetime.datetime.now() + datetime.timedelta(days=5)
|
|
||||||
month = month.strftime('%B')
|
|
||||||
|
|
||||||
tx_emails = [x[0] for x in g.db.query(Transaction.email).distinct().all()]
|
|
||||||
|
|
||||||
for u in g.db.query(User).filter(User.patron > 0, User.patron_utc == 0).all():
|
|
||||||
g.db.add(u)
|
|
||||||
|
|
||||||
if not (u.is_activated and u.email in tx_emails):
|
|
||||||
u.patron = 0
|
|
||||||
continue
|
|
||||||
|
|
||||||
marseybux_reward = marseybux_li[u.patron]
|
|
||||||
u.pay_account('marseybux', marseybux_reward)
|
|
||||||
send_repeatable_notification(u.id, f"@AutoJanny has given you {marseybux_reward} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
|
|
||||||
|
|
||||||
ma = ModAction(
|
|
||||||
kind="monthly",
|
|
||||||
user_id=AUTOJANNY_ID,
|
|
||||||
)
|
|
||||||
g.db.add(ma)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
|
@ -1271,6 +1271,42 @@ def bid_list(v:User, bid):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kofi_tiers={
|
||||||
|
5: 1,
|
||||||
|
10: 2,
|
||||||
|
20: 3,
|
||||||
|
50: 4,
|
||||||
|
100: 5,
|
||||||
|
200: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
def claim_rewards(v):
|
||||||
|
g.db.flush()
|
||||||
|
transactions = g.db.query(Transaction).filter_by(email=v.email, claimed=None).all()
|
||||||
|
|
||||||
|
highest_tier = 0
|
||||||
|
marseybux = 0
|
||||||
|
|
||||||
|
for transaction in transactions:
|
||||||
|
tier = kofi_tiers[transaction.amount]
|
||||||
|
marseybux += marseybux_li[tier]
|
||||||
|
if transaction.type == 'Subscription' and tier > highest_tier:
|
||||||
|
highest_tier = tier
|
||||||
|
transaction.claimed = True
|
||||||
|
g.db.add(transaction)
|
||||||
|
|
||||||
|
v.pay_account('marseybux', marseybux)
|
||||||
|
send_repeatable_notification(v.id, f"You have received {marseybux} Marseybux! You can use them to buy awards in the [shop](/shop).")
|
||||||
|
g.db.add(v)
|
||||||
|
|
||||||
|
if highest_tier > v.patron:
|
||||||
|
v.patron = highest_tier
|
||||||
|
for badge in g.db.query(Badge).filter(Badge.user_id == v.id, Badge.badge_id > 20, Badge.badge_id < 28).all():
|
||||||
|
g.db.delete(badge)
|
||||||
|
badge_grant(badge_id=20+highest_tier, user=v)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/kofi")
|
@app.post("/kofi")
|
||||||
def kofi():
|
def kofi():
|
||||||
if not KOFI_TOKEN: abort(404)
|
if not KOFI_TOKEN: abort(404)
|
||||||
|
@ -1297,16 +1333,13 @@ def kofi():
|
||||||
)
|
)
|
||||||
|
|
||||||
g.db.add(transaction)
|
g.db.add(transaction)
|
||||||
|
|
||||||
|
user = g.db.query(User).filter_by(email=email, is_activated=True).order_by(User.truescore.desc()).first()
|
||||||
|
if user:
|
||||||
|
claim_rewards(user)
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
kofi_tiers={
|
|
||||||
5: 1,
|
|
||||||
10: 2,
|
|
||||||
20: 3,
|
|
||||||
50: 4,
|
|
||||||
100: 5,
|
|
||||||
200: 6
|
|
||||||
}
|
|
||||||
|
|
||||||
@app.post("/settings/kofi")
|
@app.post("/settings/kofi")
|
||||||
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
|
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
|
||||||
|
@ -1323,26 +1356,7 @@ def settings_kofi(v:User):
|
||||||
if not transactions:
|
if not transactions:
|
||||||
abort(400, f"{patron} rewards already claimed")
|
abort(400, f"{patron} rewards already claimed")
|
||||||
|
|
||||||
highest_tier = 0
|
claim_rewards(v)
|
||||||
marseybux = 0
|
|
||||||
|
|
||||||
for transaction in transactions:
|
|
||||||
tier = kofi_tiers[transaction.amount]
|
|
||||||
marseybux += marseybux_li[tier]
|
|
||||||
if transaction.type == 'Subscription' and tier > highest_tier:
|
|
||||||
highest_tier = tier
|
|
||||||
transaction.claimed = True
|
|
||||||
g.db.add(transaction)
|
|
||||||
|
|
||||||
v.pay_account('marseybux', marseybux)
|
|
||||||
send_repeatable_notification(v.id, f"You have received {marseybux} Marseybux! You can use them to buy awards in the [shop](/shop).")
|
|
||||||
g.db.add(v)
|
|
||||||
|
|
||||||
if highest_tier > v.patron:
|
|
||||||
v.patron = highest_tier
|
|
||||||
for badge in g.db.query(Badge).filter(Badge.user_id == v.id, Badge.badge_id > 20, Badge.badge_id < 28).all():
|
|
||||||
g.db.delete(badge)
|
|
||||||
badge_grant(badge_id=20+highest_tier, user=v)
|
|
||||||
|
|
||||||
return {"message": f"{patron} rewards claimed!"}
|
return {"message": f"{patron} rewards claimed!"}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue