def add_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) >= 2: # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() content = extracted[1] else: return # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(WARN_HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, WARN_HANDLER_GROUP) sql.add_warn_filter(chat.id, keyword, content) update.effective_message.reply_text( "Warn handler added for '{}'!".format(keyword)) raise DispatcherHandlerStop
def add_warn_filter(bot, update): chat = update.effective_chat msg = update.effective_message args = msg.text.split(None, 2) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) >= 3: keyword = args[1] content = args[2] else: return # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(WARN_HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, WARN_HANDLER_GROUP) sql.add_warn_filter(chat.id, keyword, content) update.effective_message.reply_text("Warn handler added for {}!".format(keyword)) raise DispatcherHandlerStop