def unblacklist(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] words = msg.text.split(None, 1) conn = connected(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_unblacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) successful = 0 for trigger in to_unblacklist: success = sql.rm_from_blacklist(chat_id, trigger.lower()) if success: successful += 1 if len(to_unblacklist) == 1: if successful: msg.reply_text(tld(chat.id, "blacklist_del").format( html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: msg.reply_text( tld(chat.id, "This isn't a blacklisted trigger!")) elif successful == len(to_unblacklist): msg.reply_text(tld(chat.id, "blacklist_multi_del").format( successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: msg.reply_text(tld(chat.id, "blacklist_err_multidel_no_trigger").format( successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text(tld( chat.id, "blacklist_err_multidel_some_no_trigger").format( successful, chat_name, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text(tld(chat.id, "blacklist_err_del_no_args"))
def unblacklist(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] words = msg.text.split(None, 1) conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": exit(1) else: chat_name = chat.title if len(words) > 1: text = words[1] to_unblacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) successful = 0 for trigger in to_unblacklist: success = sql.rm_from_blacklist(chat_id, trigger.lower()) if success: successful += 1 if len(to_unblacklist) == 1: if successful: msg.reply_text(tld(chat.id, "Removed <code>{}</code> from the blacklist in <b>{}</b>!").format(html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: msg.reply_text(tld(chat.id, "This isn't a blacklisted trigger...!")) elif successful == len(to_unblacklist): msg.reply_text(tld(chat.id, "Removed <code>{}</code> triggers from the blacklist in <b>{}</b>!").format( successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: msg.reply_text(tld(chat.id, "None of these triggers were exist, so they weren't removed.").format( successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text(tld(chat.id, "Removed <code>{}</code> triggers from the blacklist in <b>{}</b>! {} did not exist, " "so were not removed.").format(successful, chat_name, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text(tld(chat.id, "Tell me what words you would like to remove from the blacklist."))