Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
- different Force bot pm message for leech and mirror
- handled exceptions for deleting messages
- leech index messages will only send in leech log when force bot pm is true
- force bot pm will applicable when using bot in PM
- removed user's profile hyperlink from mirror status message
  • Loading branch information
arshsisodiya committed Aug 29, 2022
1 parent 4850b86 commit 5f6e236
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_readable_message():
else:
msg += f"\n<b>Size: </b>{download.size()}"
if download.message.chat.type != 'private':
uname = download.message.from_user.mention_html(download.message.from_user.first_name)
uname =download.message.from_user.first_name
msg += f"\n<b><a href='{download.message.link}'>Source</a>:</b> {uname} | <b>Id :</b> <code>{download.message.from_user.id}</code>"
else:
msg += ''
Expand Down
4 changes: 2 additions & 2 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _clone(message, bot):
result, button = gd.clone(link)
deleteMessage(bot, msg)
if BOT_PM and FORCE_BOT_PM:
botpm = f"\n\n<b>Hey {tag}!, I have sent your links in PM.</b>\n"
botpm = f"\n\n<b>Hey {tag}!, I have sent your cloned links in PM.</b>\n"
buttons = ButtonMaker()
b_uname = bot.get_me().username
botstart = f"http://t.me/{b_uname}"
Expand Down Expand Up @@ -133,7 +133,7 @@ def _clone(message, bot):
del Interval[0]
delete_all_messages()
if BOT_PM and FORCE_BOT_PM:
botpm = f"\n\n<b>Hey {tag}!, I have sent your links in PM.</b>\n"
botpm = f"\n\n<b>Hey {tag}!, I have sent your cloned links in PM.</b>\n"
buttons = ButtonMaker()
b_uname = bot.get_me().username
botstart = f"http://t.me/{b_uname}"
Expand Down
29 changes: 19 additions & 10 deletions bot/modules/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,22 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name):
mesg = self.message.text.split('\n')
message_args = mesg[0].split(' ', maxsplit=1)
reply_to = self.message.reply_to_message
if self.message.chat.type != 'private' and AUTO_DELETE_UPLOAD_MESSAGE_DURATION != -1:
if reply_to is not None:
if self.message.chat.type != 'private' and AUTO_DELETE_UPLOAD_MESSAGE_DURATION != -1 and reply_to is not None:
try:
reply_to.delete()
except exception as err:
pass
if self.isLeech:
uptype = "files"
else:
uptype = "links"
msg = f"<b>Name: </b><code>{escape(name)}</code>\n\n<b>Size: </b>{size}"
if BOT_PM and FORCE_BOT_PM:
botpm = f"<b>\n\nHey {self.tag}!, I have sent your links in PM.</b>\n"
if BOT_PM and FORCE_BOT_PM and not self.isPrivate:
botpm = f"<b>\n\nHey {self.tag}!, I have sent your {uptype} in PM.</b>\n"
buttons = ButtonMaker()
b_uname = bot.get_me().username
botstart = f"http://t.me/{b_uname}"
buttons.buildbutton("View links in PM", f"{botstart}")
buttons.buildbutton(f"View {uptype} in PM", f"{botstart}")
sendMarkup(msg + botpm, self.bot, self.message, buttons.build_menu(2))
self.message.delete()
reply_to = self.message.reply_to_message
Expand Down Expand Up @@ -291,7 +297,7 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name):
if FORCE_BOT_PM is False:
upldmsg = sendMarkup(msg + fmsg, self.bot, self.message, buttons.build_menu(1))
Thread(target=auto_delete_upload_message, args=(self.bot, self.message, upldmsg)).start()
if LEECH_LOG:
if LEECH_LOG and FORCE_BOT_PM:
try:
for chatid in LEECH_LOG:
bot.sendMessage(chat_id=chatid, text=msg + fmsg,
Expand Down Expand Up @@ -359,7 +365,7 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name):
except Exception as e:
LOGGER.warning(e)
pass
if FORCE_BOT_PM is False:
if FORCE_BOT_PM is False or self.message.chat.type == 'private' :
upldmsg = sendMarkup(msg, self.bot, self.message, buttons.build_menu(2))
Thread(target=auto_delete_upload_message, args=(self.bot, self.message, upldmsg)).start()
if MIRROR_LOGS:
Expand Down Expand Up @@ -398,9 +404,12 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name):

def onDownloadError(self, error):
reply_to = self.message.reply_to_message
if reply_to is not None:
reply_to.delete()
else:
try:
if AUTO_DELETE_UPLOAD_MESSAGE_DURATION != -1 and reply_to is not None:
reply_to.delete()
else:
pass
except:
pass
error = error.replace('<', ' ').replace('>', ' ')
clean_download(self.dir)
Expand Down

0 comments on commit 5f6e236

Please sign in to comment.