def reply_filter(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + keyword + r"( |$|[^\w])" match = regex_searcher(pattern, to_match) if not match: #Skip to next item continue if match: filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Unsupported url protocol": message.reply_text("You seem to be trying to use an unsupported url protocol. Telegram " "doesn't support buttons for some protocols, such as tg://. Please try " f"again, or ask in {SUPPORT_CHAT} for help.") elif excp.message == "Reply message not found": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text("This note could not be sent, as it is incorrectly formatted. Ask in " f"{SUPPORT_CHAT} if you can't figure out why!") LOGGER.warning("Message %s could not be parsed", str(filt.reply)) LOGGER.exception("Could not parse filter %s in chat %s", str(filt.keyword), str(chat.id)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def reply_filter(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + keyword + r"( |$|[^\w])" match = regex_searcher(pattern, to_match) if not match: #Skip to next item continue if match: filt = sql.get_filter(chat.id, keyword) if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: message.reply_text(filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Desteklenmeyen URL protokolü": message.reply_text("Desteklenmeyen bir URL protokolü kullanmaya çalışıyor gibi görünüyorsunuz. Telegram " "bazı protokoller için düğmeleri desteklemiyor, gibi tg://. Please try " f"tekrar, ya da sor {SUPPORT_CHAT} yardım için.") elif excp.message == "Yanıt mesajı bulunamadı": bot.send_message(chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard) else: message.reply_text("Bu not yanlış biçimlendirildiği için gönderilemedi. Sor" f"{SUPPORT_CHAT} nedenini anlayamıyorsan!") LOGGER.warning("%S iletisi ayrıştırılamadı", str(filt.reply)) LOGGER.exception("%S sohbetindeki %s filtresi ayrıştırılamadı", str(filt.keyword), str(chat.id)) else: # LEGACY - all new filters will have has_markdown set to True. message.reply_text(filt.reply) break
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) msg = update.effective_message if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + trigger + r"( |$|[^\w])" match = regex_searcher(pattern, to_match) if not match: #Skip to next item in blacklist continue if match: 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
def del_blacklist(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) msg = update.effective_message if not to_match: return chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + trigger + r"( |$|[^\w])" match = regex_searcher(pattern, to_match) if not match: #Skip to next item in blacklist continue if match: try: message.delete() except BadRequest as excp: if excp.message == "Silinecek mesaj bulunamadı": pass else: LOGGER.exception("Kara liste mesajı silinirken hata oluştu.") break