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(update: Update, context: CallbackContext) -> str: bot = context.bot 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).replace( r"\*", "(.*)").replace(r"\\(.*)", "*") + 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(update, context) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f'approve_list_{chat_id}')) target_user = mention_html(user.id, user.first_name) if target_user in approve_list: 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 # type: Optional[User] warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""
def reply_filter(update: Update, context: CallbackContext) -> str: chat: Optional[Chat] = update.effective_chat message: Optional[Message] = update.effective_message user: Optional[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: Optional[User] = update.effective_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: delete_expired(bot, update) 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 "" threshold = 7 for keyword in chat_warn_filters: if (keyword == "only_roman"): count = 0 if not only_roman_chars(to_match): for i in to_match: retval = only_roman_chars(i) if not retval: count += 1 if count >= threshold: break if (count == threshold): user = update.effective_user # type: Optional[User] reason = "Nicht romanische Zeichen" return warn(user, chat, reason, message) else: if ((count != 0) and ((len(to_match) / 2) <= int(count))): user = update.effective_user # type: Optional[User] reason = "Nicht romanische Zeichen" return warn(user, chat, reason, message) else: 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 ""