From c9f220ace42582fe8f463a97098dd6bb8867ecd4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 7 Jul 2020 00:07:20 +0200 Subject: [PATCH] Fix https://t.me/greed_project/488 --- worker.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/worker.py b/worker.py index 0dc9a63..6120b5b 100644 --- a/worker.py +++ b/worker.py @@ -246,12 +246,22 @@ class Worker(threading.Thread): # Return the precheckoutquery return update.pre_checkout_query - def __wait_for_successfulpayment(self) -> telegram.SuccessfulPayment: + def __wait_for_successfulpayment(self, + cancellable: bool = False) -> Union[telegram.SuccessfulPayment, CancelSignal]: """Continue getting updates until a successfulpayment is received.""" log.debug("Waiting for a SuccessfulPayment...") while True: # Get the next update update = self.__receive_next_update() + # If a CancelSignal is received... + if isinstance(update, CancelSignal): + # And the wait is cancellable... + if cancellable: + # Return the CancelSignal + return update + else: + # Ignore the signal + continue # Ensure the update contains a message if update.message is None: continue @@ -754,7 +764,7 @@ class Worker(threading.Thread): # Accept the checkout self.bot.answer_pre_checkout_query(precheckoutquery.id, ok=True) # Wait for the payment - successfulpayment = self.__wait_for_successfulpayment() + successfulpayment = self.__wait_for_successfulpayment(cancellable=False) # Create a new database transaction transaction = db.Transaction(user=self.user, value=int(successfulpayment.total_amount) - fee,