better handling of errors in redeems situations

short circuit execution that doesnt take away points + better message
This commit is contained in:
2023-01-05 11:27:10 +01:00
parent c978b27799
commit b666211142
2 changed files with 17 additions and 10 deletions
+13 -10
View File
@@ -26,19 +26,22 @@ def handle_redeem(message, user_id):
return
if redeem_type == "counter":
add_to_counter(db, redeem)
use_points(db, user_id, price)
send_chat(f"{redeem} redeemed for {price} points.")
if add_to_counter(db, redeem) and use_points(db, user_id, price):
send_chat(f"{redeem} redeemed for {price} points.")
else:
send_chat(f"Redeeming {redeem} failed.")
elif redeem_type == "list":
add_to_redeem_queue(db, user_id, redeem)
use_points(db, user_id, price)
send_chat(f"{redeem} redeemed for {price} points.")
if add_to_redeem_queue(db, user_id, redeem) and use_points(db, user_id, price):
send_chat(f"{redeem} redeemed for {price} points.")
else:
send_chat(f"Redeeming {redeem} failed.")
elif redeem_type == "note":
if not note:
send_chat(f"Cannot redeem {redeem}, no note included.")
return
add_to_redeem_queue(db, user_id, redeem, note)
use_points(db, user_id, price)
send_chat(f"{redeem} redeemed for {price} points.")
if add_to_redeem_queue(db, user_id, redeem, note) and use_points(db, user_id, price):
send_chat(f"{redeem} redeemed for {price} points.")
else:
send_chat(f"Redeeming {redeem} failed.")
else:
send_chat(f"{redeem} not redeemed because of an error.")
send_chat(f"{redeem} not redeemed, type of redeem not found.")