cancel_mirror: Handle some more user made errors
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
7eda6b5f79
commit
706047f102
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue