remove the complete column from milestones table
This commit is contained in:
parent
4e363876e7
commit
56cb94e1a0
@ -109,7 +109,7 @@ def refresh_milestones() -> bool:
|
||||
result = cursor.fetchone()
|
||||
if result is None:
|
||||
cursor.execute(
|
||||
"INSERT INTO milestones(name, progress, goal, complete) VALUES(?, 0, ?, FALSE)",
|
||||
"INSERT INTO milestones(name, progress, goal) VALUES(?, 0, ?)",
|
||||
(redeem, redeem_info['goal'])
|
||||
)
|
||||
# update existing milestone to new goal
|
||||
@ -136,7 +136,7 @@ def reset_milestone(milestone: str) -> bool:
|
||||
(milestone,)
|
||||
)
|
||||
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'])
|
||||
)
|
||||
db.commit()
|
||||
|
@ -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]}")
|
||||
return False
|
||||
|
||||
# TODO: milestone is complete when progress equals goal?
|
||||
def milestone_complete(db: Connection, redeem_name: str) -> bool | None:
|
||||
"""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:
|
||||
cursor = db.execute(
|
||||
"SELECT progress, goal FROM milestones WHERE name = ?",
|
||||
@ -113,16 +95,11 @@ def check_apply_milestone_completion(db: Connection, redeem_name: str) -> bool:
|
||||
else:
|
||||
progress, goal = row
|
||||
if progress == goal:
|
||||
cursor = db.execute(
|
||||
"UPDATE milestones SET complete = TRUE WHERE name = ?",
|
||||
(redeem_name,)
|
||||
)
|
||||
db.commit()
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
except Error as e:
|
||||
current_app.logger.error(f"Error occurred applying milestone completion: {e.args[0]}")
|
||||
return False
|
||||
current_app.logger.error(f"Error occurred checking if milestone is complete: {e.args[0]}")
|
||||
|
||||
|
||||
|
||||
def all_milestones(db: Connection) -> list[Tuple[str, int, int]] | None:
|
||||
|
@ -2,7 +2,7 @@ from flask import current_app
|
||||
from tlapbot.db import get_db
|
||||
from tlapbot.owncast_requests import send_chat
|
||||
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
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ def handle_redeem(message: str, user_id: str) -> None:
|
||||
send_chat(f"Can't donate zero points.")
|
||||
elif add_to_milestone(db, user_id, redeem, int(note)):
|
||||
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!")
|
||||
else:
|
||||
send_chat(f"Redeeming milestone {redeem} failed.")
|
||||
|
@ -12,8 +12,7 @@ CREATE TABLE milestones (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
progress INTEGER NOT NULL,
|
||||
goal INTEGER NOT NULL,
|
||||
complete BOOLEAN NOT NULL
|
||||
goal INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE counters (
|
||||
|
Loading…
x
Reference in New Issue
Block a user