fix redeem handler for redeems with no price
milestone needs to be handled first
This commit is contained in:
parent
d484a0a363
commit
80037593a9
|
@ -22,10 +22,29 @@ def handle_redeem(message, user_id):
|
||||||
return
|
return
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
price = current_app.config['REDEEMS'][redeem]["price"]
|
|
||||||
redeem_type = current_app.config['REDEEMS'][redeem]["type"]
|
redeem_type = current_app.config['REDEEMS'][redeem]["type"]
|
||||||
points = read_users_points(db, user_id)
|
points = read_users_points(db, user_id)
|
||||||
|
|
||||||
|
# handle milestone first because it doesn't have a price
|
||||||
|
if redeem_type == "milestone":
|
||||||
|
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.")
|
||||||
|
elif int(note) > points:
|
||||||
|
send_chat(f"Can't redeem {redeem}, you're donating more points than you have.")
|
||||||
|
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"Redeeming milestone {redeem} failed.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# handle redeems with price argument
|
||||||
|
price = current_app.config['REDEEMS'][redeem]["price"]
|
||||||
if not points or points < price:
|
if not points or points < price:
|
||||||
send_chat(f"Can't redeem {redeem}, you don't have enough points.")
|
send_chat(f"Can't redeem {redeem}, you don't have enough points.")
|
||||||
return
|
return
|
||||||
|
@ -50,20 +69,5 @@ def handle_redeem(message, user_id):
|
||||||
send_chat(f"{redeem} redeemed for {price} points.")
|
send_chat(f"{redeem} redeemed for {price} points.")
|
||||||
else:
|
else:
|
||||||
send_chat(f"Redeeming {redeem} failed.")
|
send_chat(f"Redeeming {redeem} failed.")
|
||||||
elif redeem_type == "milestone":
|
|
||||||
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.")
|
|
||||||
elif int(note) > points:
|
|
||||||
send_chat(f"Can't redeem {redeem}, you're donating more points than you have.")
|
|
||||||
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"Redeeming {redeem} failed.")
|
|
||||||
else:
|
else:
|
||||||
send_chat(f"{redeem} not redeemed, type of redeem not found.")
|
send_chat(f"{redeem} not redeemed, type of redeem not found.")
|
||||||
|
|
Loading…
Reference in New Issue