def get_blacklisted_urls(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message base_string = tld(chat.id, "url_blacklist_current") blacklisted = sql.get_blacklisted_urls(chat.id) if not blacklisted: message.reply_text(tld(chat.id, "url_blacklist_no_existed")) return for domain in blacklisted: base_string += "- <code>{}</code>\n".format(domain) message.reply_text(base_string, parse_mode=ParseMode.HTML)
def get_blacklisted_urls(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message base_string = "Current <b>blacklisted</b> domains:\n" blacklisted = sql.get_blacklisted_urls(chat.id) if not blacklisted: message.reply_text("There are no blacklisted domains here!") return for domain in blacklisted: base_string += "- <code>{}</code>\n".format(domain) message.reply_text(base_string, parse_mode=ParseMode.HTML)
def del_blacklist_url(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message parsed_entities = message.parse_entities(types=["url"]) extracted_domains = [] for obj, url in parsed_entities.items(): extract_url = tldextract.extract(url) extracted_domains.append(extract_url.domain + "." + extract_url.suffix) for url in sql.get_blacklisted_urls(chat.id): if url in extracted_domains: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break