From 32596ab4e59fcd210d06b3b1d978f8af7b7a18e8 Mon Sep 17 00:00:00 2001 From: Lili Date: Wed, 10 Dec 2025 19:44:03 +0100 Subject: [PATCH] add poll db commands to init, fix db poll commands --- tlapbot/__init__.py | 2 ++ tlapbot/db.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tlapbot/__init__.py b/tlapbot/__init__.py index c0a2a6c..e9f8519 100644 --- a/tlapbot/__init__.py +++ b/tlapbot/__init__.py @@ -62,6 +62,8 @@ def create_app(test_config: None = None) -> Flask: app.cli.add_command(db.refresh_milestones_command) app.cli.add_command(db.reset_milestone_command) app.cli.add_command(db.hard_reset_milestone_command) + app.cli.add_command(db.refresh_polls_command) + app.cli.add_command(db.reset_poll_command) # scheduler job for giving points to users def proxy_job() -> None: diff --git a/tlapbot/db.py b/tlapbot/db.py index 46d9f2d..d90eca8 100644 --- a/tlapbot/db.py +++ b/tlapbot/db.py @@ -105,16 +105,24 @@ def refresh_polls() -> bool: def reset_poll(poll: str) -> bool: + if poll not in current_app.config['POLLS']: + print(f"Failed resetting poll, {poll} not in polls file.") + return False try: db = get_db() db.execute( - "UPDATE polls SET points = 0 WHERE poll_name = ?", + "DELETE FROM polls WHERE poll_name = ?", (poll,) ) + for option in current_app.config['POLLS'][poll]: + db.execute( + "INSERT INTO polls(poll_name, points, option) VALUES(?, ?, ?)", + (poll, 0, option) + ) db.commit() return True except sqlite3.Error as e: - current_app.logger.error(f"Error occurred adding a milestone: {e.args[0]}") + current_app.logger.error(f"Error occurred resetting poll: {e.args[0]}") return False @@ -257,8 +265,8 @@ def refresh_polls_command() -> None: click.echo('Refreshed polls.') -@click.command('reset-polls') -@click.argument('milestone') +@click.command('reset-poll') +@click.argument('poll') def reset_poll_command(poll: str) -> None: """Resets polls progress back to zero.""" if reset_poll(poll):