def add_blacklist(bot: Bot, update: Update): msg = update.effective_message chat = update.effective_chat words = msg.text.split(None, 1) if len(words) > 1: text = words[1] to_blacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: try: re.compile(trigger) except Exception as exce: msg.reply_text(f"Normal ifade eklenemedi, Error: {exce}") return check = infinite_loop_check(trigger) if not check: sql.add_to_blacklist(chat.id, trigger.lower()) else: msg.reply_text("Korkarım şu normal ifadeyi ekleyemiyorum.") return if len(to_blacklist) == 1: msg.reply_text(f"Eklendi <code>{html.escape(to_blacklist[0])}</code> to the blacklist!", parse_mode=ParseMode.HTML) else: msg.reply_text(f"Added <code>{len(to_blacklist)}</code> tetikler blacklist.", parse_mode=ParseMode.HTML) else: msg.reply_text("Bana hangi kelimeleri kaldırmak istediğini söyle blacklist.")
def add_blacklist(update, context): msg = update.effective_message chat = update.effective_chat user = update.effective_user words = msg.text.split(None, 1) conn = connected(context.bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": return else: chat_name = chat.title if len(words) > 1: text = words[1] to_blacklist = list( { trigger.strip() for trigger in text.split("\n") if trigger.strip() }, ) for trigger in to_blacklist: sql.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: send_message( update.effective_message, "Added blacklist <code>{}</code> in chat: <b>{}</b>!".format( html.escape(to_blacklist[0]), html.escape(chat_name), ), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Added blacklist trigger: <code>{}</code> in <b>{}</b>!". format( len(to_blacklist), html.escape(chat_name), ), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Tell me which words you would like to add in blacklist.", )
def add_blacklist(update, context): msg = update.effective_message chat = update.effective_chat user = update.effective_user words = msg.text.split(None, 1) conn = connected(context.bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": return else: chat_name = chat.title if len(words) > 1: text = words[1] to_blacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: sql.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: send_message( update.effective_message, "<code>{}</code> sözü <b>{}</b> qrupunda qara siyahıya əlavə edildi!".format( html.escape(to_blacklist[0]), html.escape(chat_name)), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "<code>{}</code> <b>{}</b> qrupunda qara siyahıya əlavə edildi!".format( len(to_blacklist), html.escape(chat_name)), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Qara siyahıya əlavə edilməli söz verməlisən.", )
def add_blacklist(bot: Bot, update: Update): msg = update.effective_message chat = update.effective_chat words = msg.text.split(None, 1) if len(words) > 1: text = words[1] to_blacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: try: re.compile(trigger) except Exception as exce: msg.reply_text(f"Couldn't add regex, Error: {exce}") return check = infinite_loop_check(trigger) if not check: sql.add_to_blacklist(chat.id, trigger.lower()) else: msg.reply_text("I'm afraid I can't add that regex.") return if len(to_blacklist) == 1: msg.reply_text( f"Added <code>{html.escape(to_blacklist[0])}</code> to the blacklist!", parse_mode=ParseMode.HTML) else: msg.reply_text( f"Added <code>{len(to_blacklist)}</code> triggers to the blacklist.", parse_mode=ParseMode.HTML) else: msg.reply_text( "Tell me which words you would like to remove from the blacklist.")
def __import_data__(chat_id, data): # set chat blacklist blacklist = data.get("blacklist", {}) for trigger in blacklist: sql.add_to_blacklist(chat_id, trigger)