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: if keyword.startswith('/') and keyword.endswith('/'): pattern = keyword[1:-1] 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 ""
def list_warn_filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: update.effective_message.reply_text("No warning filters are active here!") return filter_list = CURRENT_WARNING_FILTER_STRING for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == CURRENT_WARNING_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def list_warn_filters(update: Update, context: CallbackContext): chat: Optional[Chat] = update.effective_chat all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: update.effective_message.reply_text("No warning filters are active here!") return filter_list = CURRENT_WARNING_FILTER_STRING for keyword in all_handlers: entry = f" - {html.escape(keyword)}\n" if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if filter_list != CURRENT_WARNING_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def list_warn_filters(bot: Bot, update: Update): chat = update.effective_chat all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: update.effective_message.reply_text( tld(chat.id, 'warns_filters_list_empty')) return filter_list = tld(chat.id, 'warns_filters_list') for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == tld(chat.id, 'warns_filters_list'): update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def list_warn_filters(bot: Bot, update: Update): chat: Optional[Chat] = update.effective_chat all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: update.effective_message.reply_text( "Tidak ada filter peringatan yang aktif di sini!") return filter_list = CURRENT_WARNING_FILTER_STRING for keyword in all_handlers: entry = f" - {html.escape(keyword)}\n" if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == CURRENT_WARNING_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
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 ""
def remove_warn_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return to_remove = extracted[0] chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: msg.reply_text( "р┤Чр╡Нр┤░р╡Вр┤кр╡Нр┤кр┤┐р╡╜ р┤Зр┤кр╡Нр┤кр╡Лр╡╛ warning filters р┤Тр┤ир╡Нр┤ир╡Бр┤В р┤Зр┤▓р╡Нр┤▓!" ) return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( "р┤╢р┤░р┤┐, р┤Ер┤др┤┐р┤ир╡Н р┤Зр┤ир┤┐ warn р┤Ър╡Жр┤пр╡Нр┤пр┤┐р┤▓р╡Нр┤▓!" ) raise DispatcherHandlerStop msg.reply_text( "That's not a current warning filter - run /warnlist for all active warning filters." )
def remove_warn_filter(update: Update, context: CallbackContext): if not check_perms(update, 1): return bot = context.bot chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return to_remove = extracted[0] chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: msg.reply_text("No warning filters are active here!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Yep, I'll stop warning people for that.") raise DispatcherHandlerStop msg.reply_text( "That's not a current warning filter - run /warnlist for all active warning filters." )