From 464a633115fdc7e9b3b4e8492327513ea4f17261 Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Fri, 27 Sep 2019 20:35:41 +0530 Subject: [PATCH] Only maintain single status message in a chat Signed-off-by: lzzy12 --- bot/mirror.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bot/mirror.py b/bot/mirror.py index 2ac19b9..f596017 100644 --- a/bot/mirror.py +++ b/bot/mirror.py @@ -40,7 +40,11 @@ class MirrorListener(listeners.MirrorListeners): def onUploadComplete(self, link: str, progress_status_list: list, index: int): msg = '{}'.format(link, progress_status_list[index].name()) - deleteMessage(self.context, self.reply_message) + try: + deleteMessage(self.context, self.reply_message) + except BadRequest: + # This means that the message has been deleted because of a /status command + pass sendMessage(msg, self.context, self.update) del download_dict[self.update.update_id] fs_utils.clean_download(progress_status_list[index].path()) @@ -57,6 +61,7 @@ def mirror(update, context): message = update.message.text link = message.replace('/mirror', '')[1:] reply_msg = sendMessage('Starting Download', context, update) + status_reply_dict[update.effective_chat] = reply_msg listener = MirrorListener(context, update, reply_msg) aria = download_tools.DownloadHelper(listener) aria.add_download(link) @@ -77,6 +82,7 @@ def mirror_status(update, context): try: deleteMessage(context, status_reply_dict[update.effective_chat]) del status_reply_dict[update.effective_chat] + sendMessage(message, context, update) except KeyError: pass break @@ -87,6 +93,10 @@ def mirror_status(update, context): sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) +@run_async +def cancel_mirror(update, context): + pass + mirror_handler = CommandHandler('mirror', mirror) mirror_status_handler = CommandHandler('status', mirror_status) dispatcher.add_handler(mirror_handler)