remove the complete column from milestones table

This commit is contained in:
Lili (Tlapka) 2025-03-07 23:11:42 +01:00
parent 4e363876e7
commit 56cb94e1a0
4 changed files with 8 additions and 32 deletions

View File

@ -109,7 +109,7 @@ def refresh_milestones() -> bool:
result = cursor.fetchone() result = cursor.fetchone()
if result is None: if result is None:
cursor.execute( cursor.execute(
"INSERT INTO milestones(name, progress, goal, complete) VALUES(?, 0, ?, FALSE)", "INSERT INTO milestones(name, progress, goal) VALUES(?, 0, ?)",
(redeem, redeem_info['goal']) (redeem, redeem_info['goal'])
) )
# update existing milestone to new goal # update existing milestone to new goal
@ -136,7 +136,7 @@ def reset_milestone(milestone: str) -> bool:
(milestone,) (milestone,)
) )
db.execute( db.execute(
"INSERT INTO milestones(name, progress, goal, complete) VALUES(?, ?, ?, FALSE)", "INSERT INTO milestones(name, progress, goal) VALUES(?, ?, ?)",
(milestone, 0, current_app.config['REDEEMS'][milestone]['goal']) (milestone, 0, current_app.config['REDEEMS'][milestone]['goal'])
) )
db.commit() db.commit()

View File

@ -80,26 +80,8 @@ def add_to_milestone(db: Connection, user_id: str, redeem_name: str, points_dona
current_app.logger.error(f"Error occurred updating milestone: {e.args[0]}") current_app.logger.error(f"Error occurred updating milestone: {e.args[0]}")
return False return False
# TODO: milestone is complete when progress equals goal?
def milestone_complete(db: Connection, redeem_name: str) -> bool | None: def milestone_complete(db: Connection, redeem_name: str) -> bool | None:
"""Returns None only if error was logged.""" """Returns None only if error was logged."""
try:
cursor = db.execute(
"SELECT complete FROM milestones WHERE name = ?",
(redeem_name,)
)
row = cursor.fetchone()
if row is None:
current_app.logger.warning("Milestone not found in database.")
current_app.logger.warning("Maybe you forgot to run the refresh-milestones CLI command "
"after you added a new milestone to the config?")
else:
return row[0]
except Error as e:
current_app.logger.error(f"Error occurred checking if milestone is complete: {e.args[0]}")
def check_apply_milestone_completion(db: Connection, redeem_name: str) -> bool:
try: try:
cursor = db.execute( cursor = db.execute(
"SELECT progress, goal FROM milestones WHERE name = ?", "SELECT progress, goal FROM milestones WHERE name = ?",
@ -113,16 +95,11 @@ def check_apply_milestone_completion(db: Connection, redeem_name: str) -> bool:
else: else:
progress, goal = row progress, goal = row
if progress == goal: if progress == goal:
cursor = db.execute(
"UPDATE milestones SET complete = TRUE WHERE name = ?",
(redeem_name,)
)
db.commit()
return True return True
return False return False
except Error as e: except Error as e:
current_app.logger.error(f"Error occurred applying milestone completion: {e.args[0]}") current_app.logger.error(f"Error occurred checking if milestone is complete: {e.args[0]}")
return False
def all_milestones(db: Connection) -> list[Tuple[str, int, int]] | None: def all_milestones(db: Connection) -> list[Tuple[str, int, int]] | None:

View File

@ -2,7 +2,7 @@ from flask import current_app
from tlapbot.db import get_db from tlapbot.db import get_db
from tlapbot.owncast_requests import send_chat from tlapbot.owncast_requests import send_chat
from tlapbot.redeems import (add_to_redeem_queue, add_to_counter, add_to_milestone, from tlapbot.redeems import (add_to_redeem_queue, add_to_counter, add_to_milestone,
check_apply_milestone_completion, milestone_complete, is_redeem_active) milestone_complete, is_redeem_active)
from tlapbot.owncast_helpers import use_points, read_users_points from tlapbot.owncast_helpers import use_points, read_users_points
@ -44,7 +44,7 @@ def handle_redeem(message: str, user_id: str) -> None:
send_chat(f"Can't donate zero points.") send_chat(f"Can't donate zero points.")
elif add_to_milestone(db, user_id, redeem, int(note)): elif add_to_milestone(db, user_id, redeem, int(note)):
send_chat(f"Succesfully donated to {redeem} milestone!") send_chat(f"Succesfully donated to {redeem} milestone!")
if check_apply_milestone_completion(db, redeem): if milestone_complete(db, redeem):
send_chat(f"Milestone goal {redeem} complete!") send_chat(f"Milestone goal {redeem} complete!")
else: else:
send_chat(f"Redeeming milestone {redeem} failed.") send_chat(f"Redeeming milestone {redeem} failed.")

View File

@ -12,8 +12,7 @@ CREATE TABLE milestones (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, name TEXT NOT NULL,
progress INTEGER NOT NULL, progress INTEGER NOT NULL,
goal INTEGER NOT NULL, goal INTEGER NOT NULL
complete BOOLEAN NOT NULL
); );
CREATE TABLE counters ( CREATE TABLE counters (