diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index cb45805..32d03e5 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -18,9 +18,10 @@ from bot.helper.ext_utils.exceptions import DirectDownloadLinkException class MirrorListener(listeners.MirrorListeners): - def __init__(self, bot, update, isTar=False): + def __init__(self, bot, update, isTar=False, tag=None): super().__init__(bot, update) self.isTar = isTar + self.tag = tag def onDownloadStarted(self): pass @@ -100,6 +101,8 @@ class MirrorListener(listeners.MirrorListeners): if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'): share_url += '/' msg += f'\n\n Shareable link: here' + if self.tag is not None: + msg += f'\ncc: @{self.tag}' try: fs_utils.clean_download(download_dict[self.uid].path()) except FileNotFoundError: @@ -136,15 +139,14 @@ def _mirror(bot, update, isTar=False): link = '' LOGGER.info(link) link = link.strip() - - if len(link) == 0: - if update.message.reply_to_message is not None: - document = update.message.reply_to_message.document - if document is not None and document.mime_type == "application/x-bittorrent": - link = document.get_file().file_path - else: - sendMessage('Only torrent files can be mirrored from telegram', bot, update) - return + reply_to = update.message.reply_to_message + if reply_to is not None: + tag = reply_to.from_user.username + if len(link) == 0: + if reply_to.document is not None and reply_to.document.mime_type == "application/x-bittorrent": + link = reply_to.document.get_file().file_path + else: + tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return @@ -153,7 +155,7 @@ def _mirror(bot, update, isTar=False): link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e.error}') - listener = MirrorListener(bot, update, isTar) + listener = MirrorListener(bot, update, isTar, tag) aria = aria2_download.AriaDownloadHelper(listener) aria.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/') sendStatusMessage(update, bot)