add completeness to milestones
This commit is contained in:
parent
9d910e58ce
commit
49053ee4f4
|
@ -110,7 +110,7 @@ def refresh_milestones():
|
|||
)
|
||||
if cursor.fetchone() is None:
|
||||
cursor.execute(
|
||||
"INSERT INTO milestones(name, progress, goal) VALUES(?, 0, ?)",
|
||||
"INSERT INTO milestones(name, progress, goal, complete) VALUES(?, 0, ?, FALSE)",
|
||||
(redeem, redeem_info['goal'])
|
||||
)
|
||||
db.commit()
|
||||
|
|
|
@ -214,8 +214,7 @@ def add_to_milestone(db, user_id, redeem_name, points_donated):
|
|||
current_app.logger.warning("Maybe you forgot to run the refresh-milestones CLI command "
|
||||
"after you added a new milestone to the config?")
|
||||
return False
|
||||
progress = row[0]
|
||||
goal = row[1]
|
||||
progress, goal = row
|
||||
if progress + points_donated > goal:
|
||||
points_donated = goal - progress
|
||||
if use_points(db, user_id, points_donated):
|
||||
|
@ -230,6 +229,46 @@ def add_to_milestone(db, user_id, redeem_name, points_donated):
|
|||
return False
|
||||
|
||||
|
||||
def milestone_complete(db, redeem_name):
|
||||
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?")
|
||||
return row[0]
|
||||
except Error as e:
|
||||
current_app.logger.error(f"Error occured checking if milestone is complete: {e.args[0]}")
|
||||
|
||||
|
||||
def check_apply_milestone_completion(db, redeem_name):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
"SELECT progress, goal 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?")
|
||||
progress, goal = row
|
||||
if progress == goal:
|
||||
cursor = db.execute(
|
||||
"UPDATE milestones SET complete = TRUE WHERE name = ?",
|
||||
(redeem_name,)
|
||||
)
|
||||
return True
|
||||
return False
|
||||
except Error as e:
|
||||
current_app.logger.error(f"Error occured applying milestone completion: {e.args[0]}")
|
||||
return False
|
||||
|
||||
|
||||
def all_milestones(db):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
|
|
|
@ -47,7 +47,9 @@ def handle_redeem(message, user_id):
|
|||
else:
|
||||
send_chat(f"Redeeming {redeem} failed.")
|
||||
elif redeem_type == "milestone":
|
||||
if not note:
|
||||
if milestone_complete(db, redeem):
|
||||
send_chat(f"Can't redeem {redeem}, that milestone was already completed!")
|
||||
elif not note:
|
||||
send_chat(f"Cannot redeem {redeem}, no amount of points specified.")
|
||||
elif not note.isdigit():
|
||||
send_chat(f"Cannot redeem {redeem}, amount of points is not an integer.")
|
||||
|
@ -55,5 +57,7 @@ def handle_redeem(message, user_id):
|
|||
send_chat(f"Can't redeem {redeem}, you don't have enough 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):
|
||||
send_chat(f"Milestone goal {redeem} complete!")
|
||||
else:
|
||||
send_chat(f"{redeem} not redeemed, type of redeem not found.")
|
||||
|
|
|
@ -12,7 +12,8 @@ CREATE TABLE milestones (
|
|||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
progress INTEGER NOT NULL,
|
||||
goal INTEGER NOT NULL
|
||||
goal INTEGER NOT NULL,
|
||||
complete BOOLEAN NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE counters (
|
||||
|
|
Loading…
Reference in New Issue