def unblacklist(bot: Bot, update: Update): msg = update.effective_message chat = update.effective_chat user = update.effective_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({ 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, "blacklist_err_not_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 conn: 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 those trigger existed, so nothing was removed from blacklist.").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."))
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({ 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, "blacklist_err_not_trigger")) elif successful == len(to_unblacklist): msg.reply_text(tld(chat.id, "blacklist_multi_del").format( successful, chat_name), parse_mode=ParseMode.HTML)
def unblacklist(update, context): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[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_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: send_message( update.effective_message, tl( update.effective_message, "<code>{}</code> dihapus dari daftar hitam di <b>{}</b>!" ).format(html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, "Ini bukan pemicu daftar hitam...!") elif successful == len(to_unblacklist): send_message( update.effective_message, tl( update.effective_message, "<code>{}</code> Pemicu dihapus dari daftar hitam di <b>{}</b>!" ).format(successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: send_message( update.effective_message, tl( update.effective_message, "Tidak satu pun pemicu ini ada, sehingga tidak dapat dihapus." ).format(successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: send_message( update.effective_message, tl( update.effective_message, "Pemicu <code>{}</code> dihapus dari daftar hitam. {} Tidak ada, " "jadi tidak dihapus.").format( successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: send_message( update.effective_message, tl( update.effective_message, "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam." ))