From 706047f102e8c145772f0fd9f02ec9b2d79f9f6b Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Sun, 29 Sep 2019 21:55:19 +0530 Subject: [PATCH] cancel_mirror: Handle some more user made errors Signed-off-by: lzzy12 --- bot/cancel_mirror.py | 12 ++++++++---- bot/helper/download_tools.py | 2 +- bot/mirror.py | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bot/cancel_mirror.py b/bot/cancel_mirror.py index 26508ce..f4d1c71 100644 --- a/bot/cancel_mirror.py +++ b/bot/cancel_mirror.py @@ -5,11 +5,15 @@ from bot import download_dict, aria2, dispatcher @run_async def cancel_mirror(update: Update, context): - if update.message.reply_to_message is None: - sendMessage("Please reply to the /mirror message which was used to start the download to cancel it", - context, update) + mirror_message = update.message.reply_to_message + if mirror_message is None or mirror_message.message_id not in download_dict.keys(): + if '/mirror' in mirror_message.text: + msg = 'Message has already been cancelled' + else: + msg = 'Please reply to the /mirror message which was used to start the download to cancel it!' + sendMessage(msg, context, update) return - download = download_dict[update.message.reply_to_message.message_id].download() + download = download_dict[mirror_message.message_id].download() aria2.pause([download]) sendMessage("Download canceled", context, update) diff --git a/bot/helper/download_tools.py b/bot/helper/download_tools.py index 138f319..f377a4d 100644 --- a/bot/helper/download_tools.py +++ b/bot/helper/download_tools.py @@ -63,7 +63,7 @@ class DownloadHelper: self.__listener.onDownloadError(download.error_message, status_list, index) return if download.is_paused: - self.__listener.onDownloadError("Download cancelled", status_list, index) + self.__listener.onDownloadError("Download cancelled manually by user", status_list, index) return sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) if should_update: diff --git a/bot/mirror.py b/bot/mirror.py index d325eff..26e9cc6 100644 --- a/bot/mirror.py +++ b/bot/mirror.py @@ -33,12 +33,13 @@ class MirrorListener(listeners.MirrorListeners): def onDownloadError(self, error, progress_status_list: list, index: int): LOGGER.error(error) - deleteMessage(self.context, status_reply_dict[self.update.effective_chat.id]) + if len(status_reply_dict) == 1: + deleteMessage(self.context, status_reply_dict[self.update.effective_chat.id]) del status_reply_dict[self.update.effective_chat.id] if index is not None: fs_utils.clean_download(progress_status_list[index].path()) del download_dict[self.message.message_id] - msg = f"@{self.message.from_user.username} your download has been cancelled due to: {error}" + msg = f"@{self.message.from_user.username} your download has been stopped due to: {error}" sendMessage(msg, self.context, self.update) def onUploadStarted(self, progress_status_list: list, index: int):