def mentionOneText(bot, message): if message.chat.type != 'private': listUsers = botFunctions.mentionedList(message.chat.id, message.text) if message.reply_to_message is not None and not message.reply_to_message.from_user.is_bot and botFunctions.memberInTheGroup(bot, message.chat.id, message.reply_to_message.from_user.id): listUsers.append(str(message.reply_to_message.from_user.id)) listUsers = list(set(listUsers)) listSUB = re.split('\W+', message.text) listSUB = list(set(listSUB)) if len(listUsers) > 0: mentionedUser = botFunctions.getName(message.from_user) for uname in listUsers: if botFunctions.memberInTheGroup(bot, message.chat.id, uname) and str(message.from_user.id) != uname: content = message.text for subName in botFunctions.getSubscribeName(uname): for sname in listSUB: if sname.lower() == subName.lower(): for i in range(content.count(sname)): botFunctions.updateSubscribeNameCount(sname, uname) p = re.compile(r"\b{0}\b".format(sname)) content = p.sub("<b>" + sname + "</b>", content) text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : ' + content try: splitted_text = util.split_string(text, 3000) for text in splitted_text: bot.send_message(chat_id=uname, text=text, parse_mode='HTML') except: print('single mention/subscribe failed') if message.reply_to_message is not None and str(message.reply_to_message.from_user.id) != uname: try: bot.forward_message(chat_id=uname, from_chat_id=message.chat.id, message_id=message.reply_to_message.message_id) except: print('single mention/subscribe forward failed')
def mentionOneVideo(bot, message): if message.chat.type != 'private': listUser = [] repliedUser = '' if message.caption is not None: listUser = botFunctions.mentionedList(message.chat.id, message.caption) if message.reply_to_message is not None: mentionedUser = botFunctions.getName(message.reply_to_message.from_user) if not message.reply_to_message.from_user.is_bot: if botFunctions.memberInTheGroup(bot, message.chat.id, message.reply_to_message.from_user.id): if botFunctions.memberInTheGroup(bot, message.chat.id, message.reply_to_message.from_user.id) and str(message.from_user.id) != str(message.reply_to_message.from_user.id): try: bot.send_message(chat_id=message.reply_to_message.from_user.id, text=botFunctions.getName( message.from_user) + ' @ <b>' + message.chat.title + '</b> : reply as a Video', parse_mode='HTML') except: print('reply to video failed') listUser.append(str(message.reply_to_message.from_user.id)) listUser = list(set(listUser)) else: if str(message.reply_to_message.from_user.id) in listUser: listUser.remove(str(message.reply_to_message.from_user.id)) else: mentionedUser = botFunctions.getName(message.from_user) if len(listUser) > 0: for uname in listUser: if botFunctions.memberInTheGroup(bot, message.chat.id, uname) and str(message.from_user.id) != uname: text = None if message.caption is not None: text = message.caption listSUB = re.split('\W+', message.caption) listSUB = list(set(listSUB)) for subName in botFunctions.getSubscribeName(uname): for sname in listSUB: if sname.lower() == subName.lower(): for i in range(text.count(sname)): botFunctions.updateSubscribeNameCount(sname, uname) p = re.compile(r"\b{0}\b".format(sname)) text = p.sub("<b>" + sname + "</b>", text) if str(repliedUser) != uname: try: bot.send_message(chat_id=uname, text=mentionedUser + ' @ <b>' + message.chat.title + '</b> : mention you in a video', parse_mode='HTML') except: print("single mention/subscribe failed in video") try: bot.send_video(chat_id=uname, data=message.video.file_id, caption=text, parse_mode='HTML') except: print('single mention/subscribe failed in video')