05-sep: [feat] menu wizard en bot OpenCode (/menu), menu IDD cierra al elegir + updates en hilos, borrar tarea NAS (0%) desde panel

This commit is contained in:
juanjo
2026-09-05 22:47:22 +02:00
parent 1c6bd113fd
commit 23fe44aecd
4 changed files with 342 additions and 25 deletions

View File

@@ -210,6 +210,64 @@ def listar_descargas(hablar_solo_activas=True, session=None):
return lineas, activas
def listar_tareas(session=None):
"""Devuelve todas las tareas de Download Station con id y estado,
para poder borrar una concreta desde Telegram."""
if not session:
session = login()
if not session:
return []
try:
r = _api("/webapi/DownloadStation/task.cgi", {
"api": "SYNO.DownloadStation.Task",
"version": "3",
"method": "list",
"additional": "detail,transfer",
}, session=session)
if not r.get("success"):
return []
except Exception as e:
print(f"[NAS] Error listar_tareas: {e}")
return []
salida = []
for t in (r.get("data", {}).get("tasks", []) or []):
detail = (t.get("additional") or {}).get("detail") or {}
transfer = (t.get("additional") or {}).get("transfer") or {}
total = detail.get("total_pieces") or 0
done = transfer.get("downloaded_pieces") or 0
pct = (done * 100.0 / total) if total else 0.0
salida.append({
"id": t.get("id"),
"title": t.get("title") or "",
"status": t.get("status") or "?",
"pct": pct,
"size": transfer.get("size_downloaded") or 0,
})
return salida
def borrar_tarea(tid, session=None):
"""Borra una tarea de Download Station por su id.
Devuelve (ok, detalle)."""
if not session:
session = login()
if not session:
return False, "No se pudo autenticar con Download Station."
try:
import json as _json
r = _api("/webapi/DownloadStation/task.cgi", {
"api": "SYNO.DownloadStation.Task",
"version": "3",
"method": "delete",
"id": _json.dumps([tid]),
}, session=session)
except Exception as e:
return False, str(e)
if r.get("success"):
return True, "ok"
return False, str(r.get("error"))
if __name__ == "__main__":
import sys
if len(sys.argv) < 2: