From ace0a62f69ce426fa5e36c8d661dd52eb81c1113 Mon Sep 17 00:00:00 2001 From: TLSM Date: Tue, 7 Jun 2022 07:36:55 -0400 Subject: [PATCH] cron: Add lottery as scheduled task. --- files/helpers/cron.py | 4 ++-- files/helpers/lottery.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index f748a3bd1..9e85198d0 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -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: diff --git a/files/helpers/lottery.py b/files/helpers/lottery.py index a523931b3..b5322d78e 100644 --- a/files/helpers/lottery.py +++ b/files/helpers/lottery.py @@ -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.'