Tag the author of replied message of mirror command

This closes #24

Signed-off-by: lzzy12 <jhashivam2020@gmail.com>

# Conflicts:
#	bot/modules/mirror.py
This commit is contained in:
lzzy12 2020-01-17 10:02:46 -08:00
parent 697017fb86
commit ae9d972add

View File

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