05-sep: [proyecto1] menu de botones inline para el bot IDD (/menu) sin tocar la logica

This commit is contained in:
juanjo
2026-09-05 19:59:01 +02:00
parent 1c56bbb753
commit 6c4b0b2252
2 changed files with 565 additions and 1 deletions

View File

@@ -16,6 +16,8 @@ flujo_genero = {} # chat_id -> 'esperando_tipo' | 'esperando_genero' | No
flujo_genero_tipo = {} # chat_id -> 'movie' | 'series' (tipo ya elegido)
panel_descargas = {} # chat_id -> estado del panel editable
temporizadores_parental = {} # alias normalizado -> Timer de desbloqueo
menu_pendiente = {} # chat_id -> accion de texto libre esperada (menu botones)
menu_pausa_nombre = {} # chat_id -> nombre elegido en flujo de pausa
BASE = os.path.dirname(os.path.abspath(__file__))
LOG = os.path.join(BASE, "bot.log")
@@ -226,8 +228,17 @@ def procesar_callback(callback):
callback_id = callback.get("id")
mensaje = callback.get("message") or {}
chat_id = (mensaje.get("chat") or {}).get("id")
accion = (callback.get("data") or "").split(":", 1)[-1]
data = callback.get("data") or ""
responder_callback(callback_id)
# Menu de botones (menu_idd)
if data.startswith("m:"):
try:
from menu_idd import procesar_callback as menu_cb
menu_cb(data[2:], chat_id, mensaje.get("message_id"))
except Exception as e:
log(f"menu callback error: {e}")
return
accion = data.split(":", 1)[-1]
estado_panel = panel_descargas.get(chat_id)
if not estado_panel:
return
@@ -283,6 +294,27 @@ def procesar(texto, chat_id):
partes = t.split(None, 1)
comando = partes[0].split("@", 1)[0].lstrip("/") if partes else ""
argumento = partes[1].strip() if len(partes) > 1 else ""
# Texto libre pendiente pedido desde el menu de botones
try:
import menu_idd
except Exception:
menu_idd = None
if menu_idd is not None:
if t.startswith("/") or t in ("cancelar", "cancel", "salir"):
if menu_idd.pendiente_activo(chat_id):
menu_idd.cancelar_pendiente(chat_id)
if t in ("cancelar", "cancel", "salir"):
return
elif menu_idd.pendiente_activo(chat_id):
if menu_idd.resolver_pausa_minutos(chat_id, texto):
return
cmd = menu_idd.construir_comando(chat_id, texto)
menu_idd.cancelar_pendiente(chat_id)
if cmd == "INVALIDO":
enviar("⏱️ Escribe un número de minutos entre 1 y 1440.", chat_id)
return
if cmd:
return procesar(cmd, chat_id)
# Flujo interactivo por genero (espera numeros en pasos)
if flujo_genero.get(chat_id) and t.isdigit():
paso = flujo_genero[chat_id]
@@ -627,9 +659,17 @@ def procesar(texto, chat_id):
elif t.startswith("bajar ") or t.startswith("/bajar "):
n = _int_arg(texto)
procesar_bajar(n, chat_id)
elif comando in ("menu", "menú", "inicio", "start") and not argumento:
try:
from menu_idd import enviar_menu
enviar_menu(chat_id)
except Exception as e:
log(f"menu error: {e}")
enviar(f"❌ Error abriendo el menú: {e}", chat_id)
elif t in ("ayuda", "/ayuda", "help", "/help"):
enviar(
"📚 <b>ÍNDICE DE COMANDOS</b>\n"
"🧭 Escribe <b>/menu</b> para navegar con botones.\n"
"Escribe <b>/ayuda</b> cuando lo necesites.\n\n"
"━━━ 🎬 VIDEOCLUB ━━━\n"
"<b>1.</b> <code>busca &lt;nombre&gt;</code> — buscar en TODO internet\n"