mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-25 15:24:17 +00:00
#2: Do not crash when a not existing product message tries to add something to the cart
This commit is contained in:
parent
15438ccaaf
commit
6680797a72
1 changed files with 10 additions and 4 deletions
14
worker.py
14
worker.py
|
@ -312,8 +312,11 @@ class ChatWorker(threading.Thread):
|
||||||
return
|
return
|
||||||
# If a Add to Cart button has been pressed...
|
# If a Add to Cart button has been pressed...
|
||||||
elif callback.data == "cart_add":
|
elif callback.data == "cart_add":
|
||||||
# Get the selected product
|
# Get the selected product, ensuring it exists
|
||||||
product = cart[callback.message.message_id][0]
|
p = cart.get(callback.message.message_id)
|
||||||
|
if p is None:
|
||||||
|
continue
|
||||||
|
product = p[0]
|
||||||
# Add 1 copy to the cart
|
# Add 1 copy to the cart
|
||||||
cart[callback.message.message_id][1] += 1
|
cart[callback.message.message_id][1] += 1
|
||||||
# Create the product inline keyboard
|
# Create the product inline keyboard
|
||||||
|
@ -354,8 +357,11 @@ class ChatWorker(threading.Thread):
|
||||||
reply_markup=final_inline_keyboard)
|
reply_markup=final_inline_keyboard)
|
||||||
# If the Remove from cart button has been pressed...
|
# If the Remove from cart button has been pressed...
|
||||||
elif callback.data == "cart_remove":
|
elif callback.data == "cart_remove":
|
||||||
# Get the selected product
|
# Get the selected product, ensuring it exists
|
||||||
product = cart[callback.message.message_id][0]
|
p = cart.get(callback.message.message_id)
|
||||||
|
if p is None:
|
||||||
|
continue
|
||||||
|
product = p[0]
|
||||||
# Remove 1 copy from the cart
|
# Remove 1 copy from the cart
|
||||||
if cart[callback.message.message_id][1] > 0:
|
if cart[callback.message.message_id][1] > 0:
|
||||||
cart[callback.message.message_id][1] -= 1
|
cart[callback.message.message_id][1] -= 1
|
||||||
|
|
Loading…
Reference in a new issue