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
|
@run_async
|
||||||
def cancel_mirror(update: Update, context):
|
def cancel_mirror(update: Update, context):
|
||||||
if update.message.reply_to_message is None:
|
mirror_message = update.message.reply_to_message
|
||||||
sendMessage("Please reply to the /mirror message which was used to start the download to cancel it",
|
if mirror_message is None or mirror_message.message_id not in download_dict.keys():
|
||||||
context, update)
|
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
|
return
|
||||||
download = download_dict[update.message.reply_to_message.message_id].download()
|
download = download_dict[mirror_message.message_id].download()
|
||||||
aria2.pause([download])
|
aria2.pause([download])
|
||||||
sendMessage("Download canceled", context, update)
|
sendMessage("Download canceled", context, update)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class DownloadHelper:
|
||||||
self.__listener.onDownloadError(download.error_message, status_list, index)
|
self.__listener.onDownloadError(download.error_message, status_list, index)
|
||||||
return
|
return
|
||||||
if download.is_paused:
|
if download.is_paused:
|
||||||
self.__listener.onDownloadError("Download cancelled", status_list, index)
|
self.__listener.onDownloadError("Download cancelled manually by user", status_list, index)
|
||||||
return
|
return
|
||||||
sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL)
|
sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL)
|
||||||
if should_update:
|
if should_update:
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,13 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
|
|
||||||
def onDownloadError(self, error, progress_status_list: list, index: int):
|
def onDownloadError(self, error, progress_status_list: list, index: int):
|
||||||
LOGGER.error(error)
|
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]
|
del status_reply_dict[self.update.effective_chat.id]
|
||||||
if index is not None:
|
if index is not None:
|
||||||
fs_utils.clean_download(progress_status_list[index].path())
|
fs_utils.clean_download(progress_status_list[index].path())
|
||||||
del download_dict[self.message.message_id]
|
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)
|
sendMessage(msg, self.context, self.update)
|
||||||
|
|
||||||
def onUploadStarted(self, progress_status_list: list, index: int):
|
def onUploadStarted(self, progress_status_list: list, index: int):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue