forked from rDrama/rDrama
cron: Add lottery as scheduled task.
parent
690d4d72ed
commit
ace0a62f69
|
@ -1,6 +1,6 @@
|
||||||
from files.cli import g, app, db_session
|
from files.cli import g, app, db_session
|
||||||
import click
|
import click
|
||||||
import files.helpers.lottery
|
import files.helpers.lottery as lottery
|
||||||
|
|
||||||
@app.cli.command('cron', help='Run scheduled tasks.')
|
@app.cli.command('cron', help='Run scheduled tasks.')
|
||||||
@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.')
|
@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.')
|
||||||
|
@ -10,7 +10,7 @@ def cron(every_5m, every_1h, every_1d):
|
||||||
g.db = db_session()
|
g.db = db_session()
|
||||||
|
|
||||||
if every_5m:
|
if every_5m:
|
||||||
pass
|
lottery.check_if_end_lottery_task()
|
||||||
if every_1h:
|
if every_1h:
|
||||||
pass
|
pass
|
||||||
if every_1d:
|
if every_1d:
|
||||||
|
|
|
@ -81,6 +81,18 @@ def start_new_lottery_session():
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def check_if_end_lottery_task():
|
||||||
|
active_lottery = get_active_lottery()
|
||||||
|
|
||||||
|
if active_lottery is None:
|
||||||
|
return False
|
||||||
|
elif active_lottery.timeleft > 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
start_new_lottery_session()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def purchase_lottery_tickets(v, quantity=1):
|
def purchase_lottery_tickets(v, quantity=1):
|
||||||
if (v.coins < LOTTERY_TICKET_COST * quantity):
|
if (v.coins < LOTTERY_TICKET_COST * quantity):
|
||||||
return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} dramacoins each.'
|
return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} dramacoins each.'
|
||||||
|
|
Loading…
Reference in New Issue