diff --git a/bot/helper/mirror_utils/listeners.py b/bot/helper/mirror_utils/listeners.py index 5840ed0..749aa2a 100644 --- a/bot/helper/mirror_utils/listeners.py +++ b/bot/helper/mirror_utils/listeners.py @@ -1,10 +1,9 @@ class MirrorListeners: - def __init__(self, context, update, reply_message): + def __init__(self, context, update): self.context = context self.update = update self.message = update.message self.uid = self.message.message_id - self.reply_message = reply_message def onDownloadStarted(self, link: str): raise NotImplementedError diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index 8587cf1..bbe6d5a 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -14,12 +14,15 @@ import threading class MirrorListener(listeners.MirrorListeners): - def __init__(self, context, update, reply_message, isTar=False): - super().__init__(context, update, reply_message) + def __init__(self, context, update, isTar=False): + super().__init__(context, update) self.isTar = isTar def onDownloadStarted(self, link): - LOGGER.info("Adding link: " + link) + LOGGER.info(f"Adding link: {link}") + self.reply_message = sendMessage(bot_utils.get_readable_message(), self.context, self.update) + with status_reply_dict_lock: + status_reply_dict[self.update.effective_chat.id] = self.reply_message def onDownloadProgress(self, progress_status_list: list, index: int): msg = get_readable_message(progress_status_list) @@ -149,7 +152,6 @@ def _mirror(update, context, isTar=False): if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', context, update) return - reply_msg = sendMessage('Starting Download', context, update) index = update.effective_chat.id with status_reply_dict_lock: if index in status_reply_dict.keys(): @@ -157,8 +159,7 @@ def _mirror(update, context, isTar=False): deleteMessage(context, status_reply_dict[index]) except BadRequest: pass - status_reply_dict[index] = reply_msg - listener = MirrorListener(context, update, reply_msg, isTar) + listener = MirrorListener(context, update, isTar) aria = download_tools.DownloadHelper(listener) t = threading.Thread(target=aria.add_download, args=(link,)) t.start() diff --git a/bot/modules/mirror_status.py b/bot/modules/mirror_status.py index 3f75a07..4876836 100644 --- a/bot/modules/mirror_status.py +++ b/bot/modules/mirror_status.py @@ -6,13 +6,15 @@ from bot.helper.ext_utils.bot_utils import get_readable_message from telegram.error import BadRequest from bot.helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper.bot_commands import BotCommands +import threading @run_async def mirror_status(update: Update, context): message = get_readable_message() if len(message) == 0: message = "No active downloads" - sendMessage(message, context, update) + reply_message = sendMessage(message, context, update) + threading.Thread(target=auto_delete_message, args=(context, update.message, reply_message)).start() return index = update.effective_chat.id with status_reply_dict_lock: @@ -27,6 +29,7 @@ def mirror_status(update: Update, context): if len(message) == 0: message = "No active downloads" editMessage(message, context, status_reply_dict[index]) + threading.Thread(target=auto_delete_message, args=(context, update.message,status_reply_dict[index])).start() break try: editMessage(message, context, status_reply_dict[index])