forked from MarseyWorld/MarseyWorld
convert monthly marseybux into a cron task
parent
760aa397c8
commit
d84a4c7ce9
|
@ -8,12 +8,14 @@ import files.helpers.stats as stats
|
|||
import files.helpers.awards as awards
|
||||
import files.routes.static as route_static
|
||||
from files.routes.subs import sub_inactive_purge_task
|
||||
from files.routes.admin import give_monthly_marseybux_task
|
||||
|
||||
@app.cli.command('cron', help='Run scheduled tasks.')
|
||||
@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.')
|
||||
@click.option('--every-1h', is_flag=True, help='Call every 1 hour.')
|
||||
@click.option('--every-1d', is_flag=True, help='Call every 1 day.')
|
||||
def cron(every_5m, every_1h, every_1d):
|
||||
@click.option('--every-1mo', is_flag=True, help='Call every 1 month.')
|
||||
def cron(every_5m, every_1h, every_1d, every_1mo):
|
||||
g.db = db_session()
|
||||
|
||||
if every_5m:
|
||||
|
@ -29,4 +31,5 @@ def cron(every_5m, every_1h, every_1d):
|
|||
awards.award_timers_bots_task()
|
||||
sub_inactive_purge_task()
|
||||
|
||||
|
||||
if every_1mo:
|
||||
give_monthly_marseybux_task()
|
|
@ -22,6 +22,38 @@ from urllib.parse import quote, urlencode
|
|||
GUMROAD_ID = environ.get("GUMROAD_ID", "tfcvri").strip()
|
||||
GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN", "").strip()
|
||||
|
||||
|
||||
def give_monthly_marseybux_task():
|
||||
month = datetime.datetime.now() + datetime.timedelta(days=5)
|
||||
month = month.strftime('%B')
|
||||
|
||||
data = {'access_token': GUMROAD_TOKEN}
|
||||
|
||||
emails = [x['email'] for x in requests.get(f'https://api.gumroad.com/v2/products/{GUMROAD_ID}/subscribers', data=data, timeout=5).json()["subscribers"]]
|
||||
|
||||
for u in g.db.query(User).filter(User.patron > 0, User.patron_utc == 0).all():
|
||||
g.db.add(u)
|
||||
if u.id in (DAD_ID, A_ID) or u.email and u.email.lower() in emails:
|
||||
procoins = procoins_li[u.patron]
|
||||
u.procoins += procoins
|
||||
send_repeatable_notification(u.id, f"@Snappy has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
|
||||
else: u.patron = 0
|
||||
|
||||
if SITE == 'pcmemes.net':
|
||||
u = g.db.query(User).filter_by(id=KIPPY_ID).one()
|
||||
u.procoins += 50000
|
||||
g.db.add(u)
|
||||
|
||||
ma = ModAction(
|
||||
kind="monthly",
|
||||
user_id=v.id
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return True
|
||||
|
||||
@app.get('/admin/loggedin')
|
||||
@admin_level_required(2)
|
||||
def loggedin_list(v):
|
||||
|
@ -368,43 +400,6 @@ def club_ban(v, username):
|
|||
return {"message": f"@{username} has been kicked from the {CC_TITLE}. Deserved."}
|
||||
|
||||
|
||||
@app.post("/admin/monthly")
|
||||
@limiter.limit("1/day")
|
||||
@admin_level_required(3)
|
||||
def monthly(v):
|
||||
if SITE_NAME == 'rDrama' and v.id != AEVANN_ID: abort (403)
|
||||
|
||||
month = datetime.datetime.now() + datetime.timedelta(days=5)
|
||||
month = month.strftime('%B')
|
||||
|
||||
data = {'access_token': GUMROAD_TOKEN}
|
||||
|
||||
emails = [x['email'] for x in requests.get(f'https://api.gumroad.com/v2/products/{GUMROAD_ID}/subscribers', data=data, timeout=5).json()["subscribers"]]
|
||||
|
||||
for u in g.db.query(User).filter(User.patron > 0, User.patron_utc == 0).all():
|
||||
g.db.add(u)
|
||||
if u.id in (DAD_ID, A_ID) or u.email and u.email.lower() in emails:
|
||||
procoins = procoins_li[u.patron]
|
||||
u.procoins += procoins
|
||||
send_repeatable_notification(u.id, f"@{v.username} has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
|
||||
else: u.patron = 0
|
||||
|
||||
if request.host == 'pcmemes.net':
|
||||
u = g.db.query(User).filter_by(id=KIPPY_ID).one()
|
||||
u.procoins += 50000
|
||||
g.db.add(u)
|
||||
|
||||
ma = ModAction(
|
||||
kind="monthly",
|
||||
user_id=v.id
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "Monthly marseybux granted"}
|
||||
|
||||
|
||||
@app.get("/admin/shadowbanned")
|
||||
@auth_required
|
||||
def shadowbanned(v):
|
||||
|
|
|
@ -61,9 +61,4 @@
|
|||
<input autocomplete="off" class="btn btn-primary mt-3" type="submit" value="Grant Awards">
|
||||
|
||||
</form>
|
||||
|
||||
<pre></pre>
|
||||
{% if SITE_NAME != 'rDrama' or v.id == AEVANN_ID %}
|
||||
<div><a class="btn btn-danger" role="button" onclick="post_toast(this,'/admin/monthly')">Grant Monthly Marseybux</a></div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue