def remove_warn_filter(update: Update, context: CallbackContext): chat: Optional[Chat] = update.effective_chat msg: Optional[Message] = update.effective_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 hay filtros de advertencia activos aquÃ!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text( "Está bien, dejaré de advertir a la gente por eso.") raise DispatcherHandlerStop msg.reply_text( "Ese no es un filtro de advertencia actual: Usa /warnlist para ver todos los filtros de advertencia activos." )
def add_warn_filter(update: Update, context: CallbackContext): chat: Optional[Chat] = update.effective_chat msg: Optional[Message] = update.effective_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( f"Controlador de advertencia agregado para '{keyword}'!") raise DispatcherHandlerStop
def filters(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(context.bot, update, chat, user.id) if not conn is False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local filters" else: chat_name = chat.title if not msg.reply_to_message and len(args) < 2: send_message( update.effective_message, "Proporcione la palabra clave para que este trigger responda!", ) return if msg.reply_to_message: if len(args) < 2: send_message( update.effective_message, "Proporcione la palabra clave para que este trigger responda!", ) return else: keyword = args[1] else: extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat_id): dispatcher.remove_handler(handler, HANDLER_GROUP) text, file_type, file_id = get_filter_type(msg) if not msg.reply_to_message and len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename text, buttons = button_markdown_parser(extracted[1], entities=msg.parse_entities(), offset=offset) text = text.strip() if not text: send_message( update.effective_message, "No hay mensaje de nota: No puede SÓLO tener botones, necesita un mensaje para acompañarlo!", ) return elif msg.reply_to_message and len(args) >= 2: if msg.reply_to_message.text: text_to_parsing = msg.reply_to_message.text elif msg.reply_to_message.caption: text_to_parsing = msg.reply_to_message.caption else: text_to_parsing = "" offset = len(text_to_parsing ) # set correct offset relative to command + notename text, buttons = button_markdown_parser(text_to_parsing, entities=msg.parse_entities(), offset=offset) text = text.strip() elif not text and not file_type: send_message( update.effective_message, "Proporcione la palabra clave para que este trigger responda!", ) return elif msg.reply_to_message: if msg.reply_to_message.text: text_to_parsing = msg.reply_to_message.text elif msg.reply_to_message.caption: text_to_parsing = msg.reply_to_message.caption else: text_to_parsing = "" offset = len(text_to_parsing ) # set correct offset relative to command + notename text, buttons = button_markdown_parser(text_to_parsing, entities=msg.parse_entities(), offset=offset) text = text.strip() if (msg.reply_to_message.text or msg.reply_to_message.caption) and not text: send_message( update.effective_message, "No hay mensaje de nota: No puede SÓLO tener botones, necesita un mensaje para acompañarlo!", ) return else: send_message(update.effective_message, "Trigger no válido!") return add = addnew_filter(update, chat_id, keyword, text, file_type, file_id, buttons) # This is an old method # sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) if add is True: send_message( update.effective_message, "Trigger '{}' guardado en *{}*!".format(keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) raise DispatcherHandlerStop