def addingBot(bot, message, status): botFunctions.kikBotDB(message.chat.id) if botFunctions.addToGroup(message.chat.id, message.chat.title) == 'success': if status: bot.send_message( chat_id=admin, text="<b>Successfully Added me for a Group</b>" + emojiList.exclamationMarkIcon + "\n\n" + botFunctions.structureGroupDetails(bot, message.chat.id) + "\n\nAdded me by " + botFunctions.getName(message.from_user), parse_mode='HTML') try: bot.send_message( chat_id=message.chat.id, text='Thank you ' + botFunctions.getName(message.from_user) + ' for adding me to <b>' + message.chat.title + '</b> ' + message.chat.type + '. All the group details and user details are successfully added to the database. ' + emojiList.successFaceIcon, parse_mode='HTML') except: bot.send_message(chat_id=admin, text='Failed to send welcome message for <b>' + message.chat.title + '</b> ' + message.chat.type + ' and added me by ' + botFunctions.getName(message.from_user) + " " + emojiList.failFaceIcon, parse_mode='HTML') else: bot.send_message(chat_id=admin, text='Failed to Add bot for ' + message.chat.title + ' ' + message.chat.type + '. Try to added me by ' + botFunctions.getName(message.from_user) + " " + emojiList.failFaceIcon) bot.leave_chat(chat_id=message.chat.id) return adminList = [] failedDic = {} for chat in bot.get_chat_administrators(message.chat.id): if not chat.user.is_bot: adminList.append(chat.user.id) if botFunctions.addToAllUser(chat.user) == "success": failedDic[str(chat.user.id)] = botFunctions.getName(chat.user) botFunctions.addToUser(message.chat.id, chat.user.id) if failedDic != {}: for admn in adminList: if str(admn) not in list(failedDic.keys()): for nm in list(failedDic.values()): try: bot.send_message( chat_id=admn, text='<b>Tell</b> ' + nm + ' <b>to START me in privately. This is important, otherwise I cannot send message to</b> ' + nm + " " + emojiList.failFaceIcon, parse_mode='HTML') except: print("Failed to send message to the admin")
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')
def addSuperAdmin(bot, message): if not message.reply_to_message.from_user.is_bot: if botFunctions.addToSuperAdmin(message.reply_to_message.from_user.id): bot.send_message( chat_id=admin, text='Successfully added ' + botFunctions.getName(message.reply_to_message.from_user) + ' as a Super Admin ' + emojiList.successFaceIcon) else: bot.send_message( chat_id=admin, text='Failed to add ' + botFunctions.getName(message.reply_to_message.from_user) + ' as a Super Admin ' + emojiList.failFaceIcon)
def removeSuperAdmin(bot, message): if not message.reply_to_message.from_user.is_bot: if botFunctions.removeFromSuperAdmin( message.reply_to_message.from_user.id): bot.send_message( chat_id=admin, text='Successfully removed ' + botFunctions.getName(message.reply_to_message.from_user) + ' from Super Admin ' + emojiList.successFaceIcon) else: bot.send_message( chat_id=admin, text='Failed to remove ' + botFunctions.getName(message.reply_to_message.from_user) + ' from Super Admin ' + emojiList.failFaceIcon)
def mentionForAllCommands(bot, message, commandName): allID = [] if commandName == "test": allID.append(message.from_user.id) elif commandName == "all": allID = botFunctions.allDB() elif commandName == "allusers": allID = botFunctions.allusersDB() elif commandName == "allgroups": allID = botFunctions.allgroupsDB() elif commandName == "allgroupsadmins": allID = getAllGroupAdmins(bot) elif commandName == "allsuperadmins": allID = botFunctions.getAdmin() for oneByOneID in allID: try: bot.send_message(chat_id=oneByOneID, text="/" + commandName + " by " + botFunctions.getName(message.from_user), parse_mode='HTML') bot.forward_message(chat_id=oneByOneID, from_chat_id=message.chat.id, message_id=message.reply_to_message.message_id) except: print("mentionForAllCommands failed in /" + commandName)
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 checkBotAddingStatus(bot, message): groupIDList = botFunctions.getBanGroups() if str(message.chat.id) in groupIDList: if message.from_user.id == configuration.admin: botFunctions.removeFromBanGroup(message.chat.id) addingBot(bot, message, False) else: adminMessage = "<b>BOT Added to the Banned Group</b>" + emojiList.exclamationMarkIcon + "\n\n" + botFunctions.structureGroupDetails( bot, message.chat.id) adminMessage = adminMessage + "\n\nAdded me by " + botFunctions.getName( message.from_user) bot.send_message(chat_id=configuration.admin, text=adminMessage, parse_mode='HTML') bot.send_message( chat_id=message.chat.id, text="This group is <b>banned</b> by Bot <b>admin</b>. " + emojiList.failFaceIcon + " Please <b>contact</b> the <b>admin if you want</b> me to be added to this group. " + emojiList.successFaceIcon, parse_mode='HTML') bot.leave_chat(chat_id=message.chat.id) else: addingBot(bot, message, True)
def addingUser(bot, message, types): botFunctions.addToUser(message.chat.id, message.new_chat_member.id) if botFunctions.addToAllUser(message.new_chat_member) == 'failed': botFunctions.updateToAllUser(message.new_chat_member) else: try: bot.send_message( chat_id=message.from_user.id, text='<b>Tell</b> ' + botFunctions.getName(message.new_chat_member) + ' <b>to START me in privately. This is important, otherwise I cannot send message to</b> ' + botFunctions.getName(message.new_chat_member) + " " + emojiList.failFaceIcon, parse_mode='HTML') botFunctions.exceptionHandling(message, bot, types, message.new_chat_member) except: print('Cannot send message to admin')
def mentionAllVideo(bot, message): if botFunctions.checkAdmin(bot, message.chat.id, message.from_user.id) and message.chat.type != 'private': mentionedUser = botFunctions.getName(message.from_user) text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : ' + message.caption for userid in botFunctions.getAllUsers(message.chat.id): if botFunctions.memberInTheGroup(bot, message.chat.id, userid): try: bot.send_video(chat_id=userid, data=message.video.file_id, caption=text, parse_mode='HTML') except: print('@all mention failed')
def getOtherAdmins(bot, message): adminMessage = "<b>BOT Added to the Group by an Unauthorized Person</b>" + emojiList.exclamationMarkIcon + "\n\n" + botFunctions.structureGroupDetails( bot, message.chat.id) bot.send_message( chat_id=message.chat.id, text=botFunctions.getName(message.from_user) + ' you have <b>no permission</b> to add me to <b>' + message.chat.title + '</b> ' + message.chat.type + " " + emojiList.failFaceIcon + '. It will be <b>reported to creator</b> of this Bot\n\nThank You ' + emojiList.successFaceIcon, parse_mode='HTML') bot.leave_chat(chat_id=message.chat.id) adminMessage = adminMessage + "\n\nAdded me by " + botFunctions.getName( message.from_user) bot.send_message(chat_id=configuration.admin, text=adminMessage, parse_mode='HTML')
def hhhFunc(bot, message): if message.forward_from is None: if message.text.lower() == 'hi': try: bot.send_message(chat_id=message.chat.id, text='Hi ' + botFunctions.getName(message.from_user)) except: print('>>> exception found in hhhFunc') return if message.text.lower() == 'hello': try: bot.send_message(chat_id=message.chat.id, text='hello ' + botFunctions.getName(message.from_user)) except: print('>>> exception found in hhhFunc') return if message.text.lower() == 'how are you' or message.text.lower() == 'how are you?': try: bot.send_message(chat_id=message.chat.id, text='Im fine. How about you ' + botFunctions.getName(message.from_user)) except: print('>>> exception found in hhhFunc') return
def pinnedPost(bot, message): mentionedUser = botFunctions.getName(message.from_user) text = mentionedUser + ' pinned a post @ <b>' + message.chat.title + '</b> : ' for userid in botFunctions.getAllUsers(message.chat.id): if botFunctions.memberInTheGroup(bot, message.chat.id, userid): try: bot.send_message(chat_id=userid, text=text, parse_mode='HTML') bot.forward_message( chat_id=userid, from_chat_id=message.chat.id, message_id=message.pinned_message.message_id) except: print('@all mention failed')
def allsuperadmins(bot, message): if message.from_user.id == configuration.admin: if message.reply_to_message is not None: botFunctions.mentionForAllCommands(bot, message, "allsuperadmins") return if message.chat.type != 'private': try: bot.send_message( chat_id=message.from_user.id, text="Please use /allsuperadmins command in here") except: print('/allsuperadmins trying failed') else: userID = message.from_user.id subList = re.split(r'/allsuperadmins\W', message.text, 1) if len(subList) == 2: if subList[1] != '': allMessage = subList[ 1] + '\n\n/allsuperadmins by ' + botFunctions.getName( message.from_user) for allID in botFunctions.getAdmin(): try: splitted_text = util.split_string(allMessage, 3000) for text in splitted_text: bot.send_message(chat_id=allID, text=text, parse_mode='HTML') except: print( "All Groups Super Admin message failed in sending" ) else: try: bot.send_message( chat_id=userID, text= 'All Groups Super Admin Message cannot be empty ' + emojiList.failFaceIcon) except: print('All Groups Super Admin Message cannot be empty') elif len(subList) == 1: try: bot.send_message( chat_id=userID, text= 'Please add a Valid All Groups Super Admin Message ' + emojiList.successFaceIcon) except: print('valid All Groups Super Admin message failed')
def privateSticker(bot, message): if message.from_user.id == admin and message.reply_to_message is not None: try: bot.send_sticker(chat_id=message.reply_to_message.forward_from.id, data=message.sticker.file_id) except: print('Cannot send message to pm user') return if message.from_user.id != admin: bot.send_message(chat_id=admin, text='>>> private sticker send by ' + botFunctions.getName(message.from_user)) bot.forward_message(chat_id=admin, from_chat_id=message.chat.id, message_id=message.message_id)
def replyToSticker(bot, message, types): 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 Sticker', parse_mode='HTML') bot.send_sticker(chat_id=message.reply_to_message.from_user.id, data=message.sticker.file_id) except: botFunctions.exceptionHandling(message, bot, types, message.from_user)
def welcomeToUser(bot, message, types): markup = None if configuration.RsLKID == str(message.chat.id): markup = types.InlineKeyboardMarkup() markup.add( types.InlineKeyboardButton(text="Google+", url=configuration.googlePlusURL), types.InlineKeyboardButton(text="Twitter", url=configuration.twitterURL)) markup.add( types.InlineKeyboardButton(text="Facebook", url=configuration.facebookURL), types.InlineKeyboardButton(text="Telegram Channel", url=configuration.telegramChannelURL)) markup.add( types.InlineKeyboardButton( text="To START @" + configuration.botUsername, url="https://telegram.me/" + configuration.botUsername + "?start=XXXX")) welcomeMsg = welcomeMessage.ResistanceLKMessage( botFunctions.getName(message.new_chat_member)) else: welcomeMsg = botFunctions.getWelcomeMessage(message.chat.id) if message.new_chat_member.username is not None: p = re.compile('(#uname)') welcomeMsg = p.sub("@" + message.new_chat_member.username, welcomeMsg) if message.new_chat_member.first_name is not None: p = re.compile('(#fname)') welcomeMsg = p.sub(message.new_chat_member.first_name, welcomeMsg) if message.new_chat_member.last_name is not None: p = re.compile('(#lname)') welcomeMsg = p.sub(message.new_chat_member.last_name, welcomeMsg) p = re.compile('(#title)') welcomeMsg = p.sub(message.chat.title, welcomeMsg) try: bot.send_message(chat_id=message.chat.id, text=welcomeMsg, reply_markup=markup, parse_mode='HTML') except: print("welcome message sending failed")
def replyToLocation(bot, message, types): 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 Location', parse_mode='HTML') bot.send_location(chat_id=message.reply_to_message.from_user.id, longitude=message.location.longitude, latitude=message.location.latitude) except: botFunctions.exceptionHandling(message, bot, types, message.from_user)
def mentionAllText(bot, message): if botFunctions.checkAdmin(bot, message.chat.id, message.from_user.id) and message.chat.type != 'private': mentionedUser = botFunctions.getName(message.from_user) text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : ' + message.text for userid in botFunctions.getAllUsers(message.chat.id): if botFunctions.memberInTheGroup(bot, message.chat.id, userid): try: splitted_text = util.split_string(text, 3000) for text in splitted_text: bot.send_message(chat_id=userid, text=text, parse_mode='HTML') except: print('@all mention failed') if message.reply_to_message is not None: try: bot.forward_message(chat_id=userid, from_chat_id=message.chat.id, message_id=message.reply_to_message.message_id) except: print('@all forward failed')
def mentionAllPhoto(bot, message): if botFunctions.checkAdmin( bot, message.chat.id, message.from_user.id) and message.chat.type != 'private': mentionedUser = botFunctions.getName(message.from_user) text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : mention @all in a photo' for userid in botFunctions.getAllUsers(message.chat.id): if botFunctions.memberInTheGroup(bot, message.chat.id, userid): try: bot.send_message(chat_id=userid, text=text, parse_mode='HTML') bot.send_photo(chat_id=userid, photo=message.photo[-1].file_id, caption=message.caption, parse_mode='HTML') except: print('@all mention failed')
def start(bot, message): if botFunctions.addToAllUser(message.from_user) == 'failed': if botFunctions.updateToAllUser(message.from_user) == 'failed': try: bot.send_message(chat_id=message.from_user.id, text='Cannot update your details ' + botFunctions.getName(message.from_user) + " " + +emojiList.failFaceIcon) except: print('User update failed') bot.send_message(chat_id=admin, text='Cannot update details for ' + botFunctions.getName(message.from_user)) else: try: bot.send_message(chat_id=message.from_user.id, text='You Already STARTed me ' + botFunctions.getName(message.from_user) + ' and updated your personal details ' + emojiList.successFaceIcon) except: print('User update failed') else: try: bot.send_message(chat_id=admin, text='Bot started for ' + botFunctions.getName(message.from_user)) bot.send_message(chat_id=message.from_user.id, text='Thank you for STARTing me ' + botFunctions.getName(message.from_user) + " " + emojiList.successFaceIcon) except: print('User start failed') if message.chat.type == 'private': if botFunctions.memberInTheGroup(bot, configuration.RsLKID, message.from_user.id): try: bot.send_message(chat_id=message.from_user.id, text=welcomeMessage.formDetails( botFunctions.getName(message.from_user)), parse_mode='HTML') except: print('formDetails sending failed') try: bot.send_message(chat_id=message.from_user.id, text=importantNotice.subscribeNotice(), parse_mode='HTML') except: print('subscribeNotice sending failed')
def test(bot, message): if botFunctions.isUserSuperAdmin(message.from_user.id): if message.reply_to_message is not None: botFunctions.mentionForAllCommands(bot, message, "test") return if message.chat.type != 'private': try: bot.send_message(chat_id=message.from_user.id, text="Please use /test command in here") except: print('/test trying failed') else: userID = message.from_user.id subList = re.split(r'/test\W', message.text, 1) if len(subList) == 2: if subList[1] != '': allMessage = subList[ 1] + '\n\n/test by ' + botFunctions.getName( message.from_user) try: splitted_text = util.split_string(allMessage, 3000) for text in splitted_text: bot.send_message(chat_id=userID, text=text, parse_mode='HTML') except: print("Test message failed in sending") else: try: bot.send_message(chat_id=userID, text='Test Message cannot be empty ' + emojiList.failFaceIcon) except: print('Test Message cannot be empty') elif len(subList) == 1: try: bot.send_message(chat_id=userID, text='Please add a Valid Test Message ' + emojiList.successFaceIcon) except: print('valid Test message failed')
def replyToContact(bot, message, types): 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 Contact', parse_mode='HTML') if message.contact.last_name is not None: bot.send_contact(chat_id=message.reply_to_message.from_user.id, phone_number=message.contact.phone_number, first_name=message.contact.first_name, last_name=message.contact.last_name) else: bot.send_contact(chat_id=message.reply_to_message.from_user.id, phone_number=message.contact.phone_number, first_name=message.contact.first_name) except: botFunctions.exceptionHandling(message, bot, types, message.from_user)
def kikBot(bot, message): if botFunctions.kikBotDB(message.chat.id) == 'success': if botID != message.from_user.id: bot.send_message(chat_id=admin, text='Successfully kick me from the <b>' + message.chat.title + '</b> ' + message.chat.type + ' by ' + botFunctions.getName( message.from_user) + " " + emojiList.successFaceIcon, parse_mode='HTML') else: bot.send_message(chat_id=admin, text='Failed to kick me from <b>' + message.chat.title + '</b> ' + message.chat.type + ' by ' + botFunctions.getName( message.from_user) + " " + emojiList.failFaceIcon, parse_mode='HTML')