1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-24 14:54:18 +00:00

#44: Change CancelSignal handling

This commit is contained in:
Steffo 2020-04-08 14:51:44 +02:00
parent 357b0e5680
commit 279b8f1539

View file

@ -153,8 +153,9 @@ class ChatWorker(threading.Thread):
while True: while True:
# Get the next update # Get the next update
update = self.__receive_next_update() update = self.__receive_next_update()
# Ensure the update isn't a CancelSignal # If a CancelSignal is received...
if isinstance(update, CancelSignal): if isinstance(update, CancelSignal):
# And the wait is cancellable...
if cancellable: if cancellable:
# Return the CancelSignal # Return the CancelSignal
return update return update
@ -178,10 +179,15 @@ class ChatWorker(threading.Thread):
while True: while True:
# Get the next update # Get the next update
update = self.__receive_next_update() update = self.__receive_next_update()
# Ensure the update isn't a CancelSignal # If a CancelSignal is received...
if cancellable and isinstance(update, CancelSignal): if isinstance(update, CancelSignal):
# Return the CancelSignal # And the wait is cancellable...
return update if cancellable:
# Return the CancelSignal
return update
else:
# Ignore the signal
continue
# Ensure the update contains a message # Ensure the update contains a message
if update.message is None: if update.message is None:
continue continue
@ -203,10 +209,15 @@ class ChatWorker(threading.Thread):
while True: while True:
# Get the next update # Get the next update
update = self.__receive_next_update() update = self.__receive_next_update()
# Ensure the update isn't a CancelSignal # If a CancelSignal is received...
if cancellable and isinstance(update, CancelSignal): if isinstance(update, CancelSignal):
# Return the CancelSignal # And the wait is cancellable...
return update if cancellable:
# Return the CancelSignal
return update
else:
# Ignore the signal
continue
# Ensure the update contains a precheckoutquery # Ensure the update contains a precheckoutquery
if update.pre_checkout_query is None: if update.pre_checkout_query is None:
continue continue
@ -232,10 +243,15 @@ class ChatWorker(threading.Thread):
while True: while True:
# Get the next update # Get the next update
update = self.__receive_next_update() update = self.__receive_next_update()
# Ensure the update isn't a CancelSignal # If a CancelSignal is received...
if cancellable and isinstance(update, CancelSignal): if isinstance(update, CancelSignal):
# Return the CancelSignal # And the wait is cancellable...
return update if cancellable:
# Return the CancelSignal
return update
else:
# Ignore the signal
continue
# Ensure the update contains a message # Ensure the update contains a message
if update.message is None: if update.message is None:
continue continue
@ -245,16 +261,21 @@ class ChatWorker(threading.Thread):
# Return the photo array # Return the photo array
return update.message.photo return update.message.photo
def __wait_for_inlinekeyboard_callback(self, cancellable: bool = True) \ def __wait_for_inlinekeyboard_callback(self, cancellable: bool = False) \
-> Union[telegram.CallbackQuery, CancelSignal]: -> Union[telegram.CallbackQuery, CancelSignal]:
"""Continue getting updates until an inline keyboard callback is received, then return it.""" """Continue getting updates until an inline keyboard callback is received, then return it."""
while True: while True:
# Get the next update # Get the next update
update = self.__receive_next_update() update = self.__receive_next_update()
# Ensure the update isn't a CancelSignal # If a CancelSignal is received...
if cancellable and isinstance(update, CancelSignal): if isinstance(update, CancelSignal):
# Return the CancelSignal # And the wait is cancellable...
return update if cancellable:
# Return the CancelSignal
return update
else:
# Ignore the signal
continue
# Ensure the update is a CallbackQuery # Ensure the update is a CallbackQuery
if update.callback_query is None: if update.callback_query is None:
continue continue
@ -1229,7 +1250,7 @@ class ChatWorker(threading.Thread):
callback = self.__wait_for_inlinekeyboard_callback() callback = self.__wait_for_inlinekeyboard_callback()
# Toggle the correct property # Toggle the correct property
if callback.data == "toggle_edit_products": if callback.data == "toggle_edit_products":
admin.edit_products = not admin.edit_products admin.edit_products = not admin.edit_products1
elif callback.data == "toggle_receive_orders": elif callback.data == "toggle_receive_orders":
admin.receive_orders = not admin.receive_orders admin.receive_orders = not admin.receive_orders
elif callback.data == "toggle_create_transactions": elif callback.data == "toggle_create_transactions":