03-sep: [fix] reparar comando descargar del videoclub
This commit is contained in:
@@ -81,6 +81,7 @@ def estado():
|
|||||||
|
|
||||||
def enviar(texto, chat_id):
|
def enviar(texto, chat_id):
|
||||||
# Trocea mensajes largos (Telegram limita a ~4096 chars) para no fallar en silencio
|
# Trocea mensajes largos (Telegram limita a ~4096 chars) para no fallar en silencio
|
||||||
|
ultimo_id = None
|
||||||
for i in range(0, len(texto), 4000):
|
for i in range(0, len(texto), 4000):
|
||||||
bloque = texto[i:i + 4000]
|
bloque = texto[i:i + 4000]
|
||||||
try:
|
try:
|
||||||
@@ -91,10 +92,12 @@ def enviar(texto, chat_id):
|
|||||||
)
|
)
|
||||||
d = r.json()
|
d = r.json()
|
||||||
if d.get("ok"):
|
if d.get("ok"):
|
||||||
return d["result"].get("message_id")
|
ultimo_id = d["result"].get("message_id")
|
||||||
|
else:
|
||||||
|
log(f"Telegram sendMessage error: {d.get('description', d)}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error enviando:", e)
|
log(f"Telegram sendMessage exception: {e}")
|
||||||
return None
|
return ultimo_id
|
||||||
|
|
||||||
|
|
||||||
def borrar(chat_id, message_id):
|
def borrar(chat_id, message_id):
|
||||||
@@ -132,6 +135,9 @@ def mandar_youtube(url):
|
|||||||
def procesar(texto, chat_id):
|
def procesar(texto, chat_id):
|
||||||
t = texto.lower().strip()
|
t = texto.lower().strip()
|
||||||
log(f"RECIBIDO chat={chat_id} texto={texto!r}")
|
log(f"RECIBIDO chat={chat_id} texto={texto!r}")
|
||||||
|
partes = t.split(None, 1)
|
||||||
|
comando = partes[0].split("@", 1)[0].lstrip("/") if partes else ""
|
||||||
|
argumento = partes[1].strip() if len(partes) > 1 else ""
|
||||||
# Flujo interactivo por genero (espera numeros en pasos)
|
# Flujo interactivo por genero (espera numeros en pasos)
|
||||||
if flujo_genero.get(chat_id) and t.isdigit():
|
if flujo_genero.get(chat_id) and t.isdigit():
|
||||||
paso = flujo_genero[chat_id]
|
paso = flujo_genero[chat_id]
|
||||||
@@ -207,19 +213,21 @@ def procesar(texto, chat_id):
|
|||||||
else:
|
else:
|
||||||
ok = mandar_youtube(url)
|
ok = mandar_youtube(url)
|
||||||
enviar("🎬 YouTube lanzado en la TV ✅" if ok else "❌ No se pudo lanzar YouTube", chat_id)
|
enviar("🎬 YouTube lanzado en la TV ✅" if ok else "❌ No se pudo lanzar YouTube", chat_id)
|
||||||
elif t in ("descargar", "/descargar"):
|
elif comando == "descargar":
|
||||||
import nas_dl
|
try:
|
||||||
lineas, _act = nas_dl.listar_descargas(hablar_solo_activas=True)
|
|
||||||
enviar("\n".join(lineas), chat_id)
|
|
||||||
elif t.startswith("descargar ") or t.startswith("/descargar "):
|
|
||||||
uri = texto.split(" ", 1)[1].strip()
|
|
||||||
if not uri:
|
|
||||||
enviar("Uso: <b>descargar <enlace|magnet|uri></b> (anade a Download Station del NAS)", chat_id)
|
|
||||||
else:
|
|
||||||
import nas_dl
|
import nas_dl
|
||||||
ok = nas_dl.add_torrent(uri)
|
if argumento:
|
||||||
enviar("📥 Añadido a Download Station del NAS ✅" if ok
|
ok = nas_dl.add_torrent(argumento)
|
||||||
else "❌ No se pudo añadir al NAS", chat_id)
|
enviar("📥 Añadido a Download Station del NAS ✅" if ok
|
||||||
|
else "❌ No se pudo añadir al NAS. Revisa <code>bot.log</code>.", chat_id)
|
||||||
|
else:
|
||||||
|
# Incluye también pendientes, pausadas y terminadas para que
|
||||||
|
# el usuario pueda ver el estado real de cada torrent.
|
||||||
|
lineas, _act = nas_dl.listar_descargas(hablar_solo_activas=False)
|
||||||
|
enviar("\n".join(lineas), chat_id)
|
||||||
|
except Exception as e:
|
||||||
|
log(f"descargar error: {e}")
|
||||||
|
enviar(f"❌ Error en Download Station: {e}", chat_id)
|
||||||
elif t in ("pelis", "/pelis"):
|
elif t in ("pelis", "/pelis"):
|
||||||
procesar_pelis(chat_id)
|
procesar_pelis(chat_id)
|
||||||
elif t in ("series", "/series"):
|
elif t in ("series", "/series"):
|
||||||
|
|||||||
Reference in New Issue
Block a user