def reply_filter(bot: Bot, update: Update) -> str: chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] chat_warn_filters = sql.get_chat_warn_triggers(chat.id) to_match = extract_text(message) if not to_match: return "" for keyword in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user = update.effective_user # type: Optional[User] warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""
def reply_filter(bot: Bot, update: Update) -> str: chat = update.effective_chat message = update.effective_message user = update.effective_user if not user: #Ignore channel return if user.id == 777000: return chat_warn_filters = sql.get_chat_warn_triggers(chat.id) to_match = extract_text(message) if not to_match: return "" for keyword in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user = update.effective_user warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""