def rm_blacklist_url(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message urls = message.text.split(None, 1) if len(urls) > 1: urls = urls[1] to_unblacklist = list( set(uri.strip() for uri in urls.split("\n") if uri.strip())) unblacklisted = 0 for uri in to_unblacklist: extract_url = tldextract.extract(uri) success = sql.rm_url_from_blacklist( chat.id, extract_url.domain + "." + extract_url.suffix) if success: unblacklisted += 1 if len(to_unblacklist) == 1: if unblacklisted: message.reply_text( "Removed <code>{}</code> from the blacklist!".format( html.escape(to_unblacklist[0])), parse_mode=ParseMode.HTML) else: message.reply_text("This isn't a blacklisted domain...!") elif unblacklisted == len(to_unblacklist): message.reply_text( "Removed <code>{}</code> domains from the blacklist.".format( unblacklisted), parse_mode=ParseMode.HTML) elif not unblacklisted: message.reply_text( "None of these domains exist, so they weren't removed.", parse_mode=ParseMode.HTML) else: message.reply_text( "Removed <code>{}</code> domains from the blacklist. {} did not exist, " "so were not removed.".format( unblacklisted, len(to_unblacklist) - unblacklisted), parse_mode=ParseMode.HTML) else: message.reply_text( "Tell me which domains you would like to remove from the blacklist." )
def rm_blacklist_url(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message urls = message.text.split(None, 1) if len(urls) > 1: urls = urls[1] to_unblacklist = list( set(uri.strip() for uri in urls.split("\n") if uri.strip())) unblacklisted = 0 for uri in to_unblacklist: extract_url = tldextract.extract(uri) success = sql.rm_url_from_blacklist( chat.id, extract_url.domain + "." + extract_url.suffix) if success: unblacklisted += 1 if len(to_unblacklist) == 1: if unblacklisted: message.reply_text(tld(chat.id, "url_blacklist_remove_success").format( html.escape(to_unblacklist[0])), parse_mode=ParseMode.HTML) else: message.reply_text(tld(chat.id, "url_blacklist_remove_invalid")) elif unblacklisted == len(to_unblacklist): message.reply_text( tld(chat.id, "url_blacklist_remove_success_2").format(unblacklisted), parse_mode=ParseMode.HTML) elif not unblacklisted: message.reply_text(tld(chat.id, "url_blacklist_remove_invalid_2"), parse_mode=ParseMode.HTML) else: message.reply_text(tld(chat.id, "url_blacklist_remove_success_3").format( unblacklisted, len(to_unblacklist) - unblacklisted), parse_mode=ParseMode.HTML) else: message.reply_text(tld(chat.id, "url_blacklist_remove_invalid_3"))