From 13ca9c53910c113f099ed54cef523ac5e624da2a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 16 Apr 2018 12:28:00 +0200 Subject: [PATCH] Delete cancelled refund messages --- utils.py | 5 ++++- worker.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index bfe39e6..8953e00 100644 --- a/utils.py +++ b/utils.py @@ -109,7 +109,6 @@ def telegram_html_escape(string: str): .replace('"', """) - def catch_telegram_errors(func): """Decorator, can be applied to any function to retry in case of Telegram errors.""" def result_func(*args, **kwargs): @@ -186,4 +185,8 @@ class DuckBot: def send_chat_action(self, *args, **kwargs): return self.bot.send_chat_action(*args, **kwargs) + @catch_telegram_errors + def delete_message(self, *args, **kwargs): + return self.bot.delete_message(*args, **kwargs) + # TODO: add more methods diff --git a/worker.py b/worker.py index 5d896a8..8d02150 100644 --- a/worker.py +++ b/worker.py @@ -874,11 +874,13 @@ class ChatWorker(threading.Thread): # If the user pressed the refund order button, refund the order... elif update.data == "order_refund": # Ask for a refund reason - self.bot.send_message(self.chat.id, strings.ask_refund_reason, reply_markup=cancel_keyboard) + reason_msg = self.bot.send_message(self.chat.id, strings.ask_refund_reason, reply_markup=cancel_keyboard) # Wait for a reply reply = self.__wait_for_regex("(.*)", cancellable=True) # If the user pressed the cancel button, cancel the refund if isinstance(reply, CancelSignal): + # Delete the message asking for the refund reason + self.bot.delete_message(self.chat.id, reason_msg.message_id) continue # Mark the order as refunded order.refund_date = datetime.datetime.now() @@ -897,6 +899,8 @@ class ChatWorker(threading.Thread): # Notify the user of the refund self.bot.send_message(order.user_id, strings.notification_order_refunded.format(order=order.get_text(self.session))) + # Notify the admin of the refund + self.bot.send_message(self.chat.id, strings.success_order_refunded.format(order_id=order.order_id)) def __create_transaction(self): """Edit manually the credit of an user."""