def message_text(bot, update): if bot.get_chat_member( update.message.chat_id, update.message.from_user.id).status not in [ "creator", "administrator" ] or update.message.from_user.id not in config.admin_id: if update.message is not None: if update.message.text is None: if update.message.forward_from_chat: update.message.text = update.message.caption if update.message.text is not None: if any(s in str(update.message.text).lower() for s in config.spam_words): if update.message.chat.username is not None: chat_name = update.message.chat.username else: chat_name = update.message.chat.title chat_id = update.message.chat_id util.bot_log( strings.REPORT_MESSAGE_TEXT % (str(update.message.text), str(update.message.from_user.name), str(chat_name) + " " + str(update.message.chat.username), util.get_hash(int(chat_id))), bot) bot.delete_message(chat_id, update.message.message_id) util.log_blocked_content('!spam_word', update.message.chat_id, update.message.from_user.id, update.message.text)
def sign(bot, update): if update.message.from_user.id in config.admin_id or bot.get_chat_member( update.message.chat_id, update.message.from_user.id).status in [ "creator", "administrator" ]: if update.message.from_user.name is not None: user_name = update.message.from_user.name else: user_name = str(update.message.from_user.first_name) + " " + str( update.message.from_user.last_name) db = MySQLdb.connect(config.database['server'], config.database['user'], config.database['password'], config.database['name']) db.autocommit(True) cur = db.cursor() cur.execute( "INSERT IGNORE INTO Permissions (User_ID, Group_ID) VALUES (" + str(update.message.from_user.id) + ", (SELECT ID FROM Groups WHERE Chat_ID = '" + str(update.message.chat_id) + "'))") bot.delete_message(update.message.chat_id, update.message.message_id) cur.close() db.close() util.bot_log( strings.DASH_USER_SIGN % (str(user_name), str(update.message.from_user.id), str(update.message.chat.title), str(update.message.chat_id), util.get_hash(int(update.message.chat_id))), bot)
def message_links(bot, update): if bot.get_chat_member( update.message.chat_id, update.message.from_user.id).status not in [ "creator", "administrator" ] or update.message.from_user.id not in config.admin_id: if update.message is not None: delete = False chat_id = update.message.chat_id if update.message.text is None: if update.message.forward_from_chat: update.message.text = update.message.caption else: return False if update.message.chat.username is not None: chat_name = update.message.chat.username config.safe_urls.append("https://t.me/" + chat_name) config.safe_urls.append("https://t.me/@" + chat_name) else: chat_name = update.message.chat.title urls = re.findall(config.regex_web_url, update.message.text) for url in urls: if url not in config.safe_urls: if is_spam(url, True, chat_id): util.bot_log( strings.REPORT_MESSAGE_URL % (str(update.message.text), str(update.message.from_user.name), str(chat_name), str(url), util.get_hash(int(chat_id))), bot) delete = True if any(tgUrl in update.message.text for tgUrl in config.telegram_domains): delete = True if delete == True: bot.delete_message(chat_id, update.message.message_id) util.log_blocked_content('!spam_domain', update.message.chat_id, update.message.from_user.id, update.message.text)
def message_entities(bot, update): if bot.get_chat_member( update.message.chat_id, update.message.from_user.id).status not in [ "creator", "administrator" ] or update.message.from_user.id not in config.admin_id: if update.message is not None and update.message.entities is not None: if update.message.forward_from_chat: update.message.text = update.message.caption if update.message.chat.username is not None: if update.message.chat.username not in config.safe_names: config.safe_names.append('@' + update.message.chat.username) for entitie in update.message.entities: if entitie.type == "mention": if update.message.text is not None: if update.message.chat.username is not None: chat_name = update.message.chat.username else: chat_name = update.message.chat.title e = update.message.text[entitie.offset:entitie.offset + entitie.length] if is_spam(e, False, update.message.chat_id): chat_id = update.message.chat_id util.bot_log( strings.REPORT_MESSAGE_TEXT % (html.escape(str(update.message.text)), str(update.message.from_user.name), str(chat_name) + " " + str(update.message.chat.username), util.get_hash(int(chat_id))), bot) bot.delete_message(chat_id, update.message.message_id) util.log_blocked_content( '!spam_telegram', update.message.chat_id, update.message.from_user.id, update.message.text)
def new_user_name(bot, update): if update.message is not None and update.message.new_chat_members is not None: for new in update.message.new_chat_members: first = str(new.first_name) last = str(new.last_name) if update.message.chat.username is not None: chat_name = update.message.chat.username else: chat_name = update.message.chat.title if str(last) == "None": last = "" if any(s in str(first + " " + last).lower() for s in mix_spam_list): chat_id = update.message.chat_id util.bot_log( strings.REPORT_USER_NAME % (str(first + last), str(chat_name), util.get_hash(int(chat_id))), bot) bot.kick_chat_member(chat_id, new.id) bot.delete_message(chat_id, update.message.message_id) util.log_blocked_content('!spam_in_username', update.message.chat_id, update.message.from_user.id, str(first + last))
def check(bot, update): blacklist=False try: for new in update.message.new_chat_members: if check_in_blacklist(new.id): user=new blacklist=True except AttributeError: pass if check_in_blacklist(update.message.from_user.id): user=update.message.from_user blacklist=True if blacklist: if user.name is not None: user_name=user.name else: user_name=str(user.first_name)+" "+str(user.last_name) chat_id=update.message.chat_id util.bot_log(strings.BAN_REPORT % (str(user_name), str(user.id), str(update.message.chat.title), util.get_hash(int(chat_id))), bot) bot.kick_chat_member(update.message.chat_id, user.id) bot.delete_message(update.message.chat_id, update.message.message_id)