cron: Add lottery as scheduled task.

master
Snakes 2022-06-07 07:36:55 -04:00
parent 690d4d72ed
commit ace0a62f69
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,6 @@
from files.cli import g, app, db_session
import click
import files.helpers.lottery
import files.helpers.lottery as lottery
@app.cli.command('cron', help='Run scheduled tasks.')
@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()
if every_5m:
pass
lottery.check_if_end_lottery_task()
if every_1h:
pass
if every_1d:

View File

@ -81,6 +81,18 @@ def start_new_lottery_session():
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):
if (v.coins < LOTTERY_TICKET_COST * quantity):
return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} dramacoins each.'