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_filters(chat.id) if not chat_filters: msg.reply_text("No warning filters are active here!") return for filt in chat_filters: if filt.chat_id == str(chat.id) and filt.keyword == 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." )
def reply_filter(bot, update): chat_warn_filters = sql.get_chat_warn_filters(update.effective_chat.id) message = update.effective_message to_match = extract_text(message) if not to_match: return for warn_filter in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(warn_filter.keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user_id = update.effective_user.id chat = update.effective_chat warn(user_id, chat, warn_filter.reply, bot, message)
def reply_filter(bot: Bot, update: Update) -> str: chat_warn_filters = sql.get_chat_warn_filters(update.effective_chat.id) message = update.effective_message # type: Optional[Message] to_match = extract_text(message) if not to_match: return "" for warn_filter in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(warn_filter.keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] return warn(user, chat, warn_filter.reply, message) return ""
def list_warn_filters(bot, update): chat = update.effective_chat all_handlers = sql.get_chat_warn_filters(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 handler in all_handlers: entry = " - {}\n".format(escape_markdown(handler.keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.MARKDOWN) 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.MARKDOWN)
def remove_warn_filter(bot, update, args): chat = update.effective_chat if len(args) < 1: return chat_filters = sql.get_chat_warn_filters(chat.id) if not chat_filters: update.effective_message.reply_text("No warning filters are active here!") return for filt in chat_filters: if filt.chat_id == str(chat.id) and filt.keyword == args[0]: sql.remove_warn_filter(chat.id, args[0]) update.effective_message.reply_text("Yep, I'll stop warning people for that.") raise DispatcherHandlerStop update.effective_message.reply_text("That's not a current warning filter - run /warnlist for all \ active warning filters.")
def list_warn_filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] all_handlers = sql.get_chat_warn_filters(chat.id) if not all_handlers: update.effective_message.reply_text( "Burada hiçbir uyarı filtresi aktif değil!") return filter_list = CURRENT_WARNING_FILTER_STRING for handler in all_handlers: entry = " - {}\n".format(escape_markdown(handler.keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.MARKDOWN) 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.MARKDOWN)
def remove_warn_filter(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) < 1: return chat_filters = sql.get_chat_warn_filters(chat.id) if not chat_filters: update.effective_message.reply_text( "Burada hiçbir uyarı filtresi aktif değil!") return for filt in chat_filters: if filt.chat_id == str(chat.id) and filt.keyword == args[0]: sql.remove_warn_filter(chat.id, args[0]) update.effective_message.reply_text( "Evet, bunun için insanları uyarmayı bırakacağım.") raise DispatcherHandlerStop update.effective_message.reply_text( "Bu geçerli bir uyarı filtresi değil - görmek için /warnlist \ komutunu çalıştırın.")