def help_button(update, context): query = update.callback_query mod_match = re.match(r"help_module\((.+?)\)", query.data) prev_match = re.match(r"help_prev\((.+?)\)", query.data) next_match = re.match(r"help_next\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) # print(query.message.chat.id) try: if mod_match: module = mod_match.group(1) text = ("Aquí está la ayuda para el módulo *{}*:\n".format( HELPABLE[module].__mod_name__) + HELPABLE[module].__help__) query.message.edit_text( text=text, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="Atrás", callback_data="help_back") ]]), ) elif prev_match: curr_page = int(prev_match.group(1)) query.message.edit_text( text=HELP_STRINGS, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, HELPABLE, "help")), ) elif next_match: next_page = int(next_match.group(1)) query.message.edit_text( text=HELP_STRINGS, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, HELPABLE, "help")), ) elif back_match: query.message.edit_text( text=HELP_STRINGS, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, HELPABLE, "help")), ) # ensure no spinny white circle context.bot.answer_callback_query(query.id) # query.message.delete() except BadRequest: pass
def send_help(chat_id, text, keyboard=None): if not keyboard: keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help")) dispatcher.bot.send_message( chat_id=chat_id, text=text, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=keyboard, )
def send_settings(chat_id, user_id, user=False): if user: if USER_SETTINGS: settings = "\n\n".join( "*{}*:\n{}".format(mod.__mod_name__, mod.__user_settings__(user_id)) for mod in USER_SETTINGS.values() ) dispatcher.bot.send_message( user_id, "Estas son tus configuraciones actuales:" + "\n\n" + settings, parse_mode=ParseMode.MARKDOWN, ) else: dispatcher.bot.send_message( user_id, "Parece que no hay ninguna configuración disponible :'(", parse_mode=ParseMode.MARKDOWN, ) else: if CHAT_SETTINGS: chat_name = dispatcher.bot.getChat(chat_id).title dispatcher.bot.send_message( user_id, text="Para qué módulo le gustaría cambiar la configuración de {}?".format( chat_name ), reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id) ), ) else: dispatcher.bot.send_message( user_id, "Parece que no hay ninguna configuración de grupo disponible :'(\nEnvía esto " "en un grupo en el que sea administrador para encontrar su configuración actual.", parse_mode=ParseMode.MARKDOWN, )
def settings_button(update: Update, context: CallbackContext): query = update.callback_query user = update.effective_user bot = context.bot mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = ( "*{}* tiene la siguiente configuración para el módulo *{}*:\n\n" .format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id)) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Atrás", callback_data="stngs_back({})".format(chat_id), ) ]]), ) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Hola! Hay algunas configuraciones para {}. Continúa y elije " "lo que quieras.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id)), ) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "¡Hola! Hay algunas configuraciones para {}. Continúa y elije " "lo que te guste.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id)), ) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text= "¡Hola! Hay algunas configuraciones para {}. Continúa y elije " "lo que te guste.".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id)), ) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))