better handling of errors in redeems situations
short circuit execution that doesnt take away points + better message
This commit is contained in:
parent
c978b27799
commit
b666211142
|
@ -159,9 +159,11 @@ def add_to_counter(db, counter_name):
|
||||||
(counter_name,)
|
(counter_name,)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
return True
|
||||||
except Error as e:
|
except Error as e:
|
||||||
current_app.logger.error("Error occured adding to counter:", e.args[0])
|
current_app.logger.error("Error occured adding to counter:", e.args[0])
|
||||||
current_app.logger.error("To counter:", counter_name)
|
current_app.logger.error("To counter:", counter_name)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
||||||
|
@ -171,10 +173,12 @@ def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
||||||
(redeem_name, user_id, note)
|
(redeem_name, user_id, note)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
return True
|
||||||
except Error as e:
|
except Error as e:
|
||||||
current_app.logger.error("Error occured adding to redeem queue:", e.args[0])
|
current_app.logger.error("Error occured adding to redeem queue:", e.args[0])
|
||||||
current_app.logger.error("To user:", user_id, " with redeem:",
|
current_app.logger.error("To user:", user_id, " with redeem:",
|
||||||
redeem_name, "with note:", note)
|
redeem_name, "with note:", note)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def all_counters(db):
|
def all_counters(db):
|
||||||
|
|
|
@ -26,19 +26,22 @@ def handle_redeem(message, user_id):
|
||||||
return
|
return
|
||||||
|
|
||||||
if redeem_type == "counter":
|
if redeem_type == "counter":
|
||||||
add_to_counter(db, redeem)
|
if add_to_counter(db, redeem) and use_points(db, user_id, price):
|
||||||
use_points(db, user_id, price)
|
send_chat(f"{redeem} redeemed for {price} points.")
|
||||||
send_chat(f"{redeem} redeemed for {price} points.")
|
else:
|
||||||
|
send_chat(f"Redeeming {redeem} failed.")
|
||||||
elif redeem_type == "list":
|
elif redeem_type == "list":
|
||||||
add_to_redeem_queue(db, user_id, redeem)
|
if add_to_redeem_queue(db, user_id, redeem) and use_points(db, user_id, price):
|
||||||
use_points(db, user_id, price)
|
send_chat(f"{redeem} redeemed for {price} points.")
|
||||||
send_chat(f"{redeem} redeemed for {price} points.")
|
else:
|
||||||
|
send_chat(f"Redeeming {redeem} failed.")
|
||||||
elif redeem_type == "note":
|
elif redeem_type == "note":
|
||||||
if not note:
|
if not note:
|
||||||
send_chat(f"Cannot redeem {redeem}, no note included.")
|
send_chat(f"Cannot redeem {redeem}, no note included.")
|
||||||
return
|
return
|
||||||
add_to_redeem_queue(db, user_id, redeem, note)
|
if add_to_redeem_queue(db, user_id, redeem, note) and use_points(db, user_id, price):
|
||||||
use_points(db, user_id, price)
|
send_chat(f"{redeem} redeemed for {price} points.")
|
||||||
send_chat(f"{redeem} redeemed for {price} points.")
|
else:
|
||||||
|
send_chat(f"Redeeming {redeem} failed.")
|
||||||
else:
|
else:
|
||||||
send_chat(f"{redeem} not redeemed because of an error.")
|
send_chat(f"{redeem} not redeemed, type of redeem not found.")
|
||||||
|
|
Loading…
Reference in New Issue