05-sep: [feat] salir de sesion (/salir), repo por defecto (/defecto) y limpiar pantalla (/limpiar) en ambos bots
This commit is contained in:
@@ -18,6 +18,7 @@ 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
|
||||
historial_chat = {} # chat_id -> [message_id...] enviados por el bot (para /limpiar)
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
LOG = os.path.join(BASE, "bot.log")
|
||||
@@ -98,6 +99,10 @@ def enviar(texto, chat_id):
|
||||
d = r.json()
|
||||
if d.get("ok"):
|
||||
ultimo_id = d["result"].get("message_id")
|
||||
lista = historial_chat.setdefault(chat_id, [])
|
||||
lista.append(ultimo_id)
|
||||
if len(lista) > 300:
|
||||
historial_chat[chat_id] = lista[-300:]
|
||||
else:
|
||||
log(f"Telegram sendMessage error: {d.get('description', d)}")
|
||||
except Exception as e:
|
||||
@@ -267,6 +272,26 @@ def borrar(chat_id, message_id):
|
||||
print("Error borrando:", e)
|
||||
|
||||
|
||||
def limpiar_pantalla(chat_id):
|
||||
"""Borra los mensajes que el bot ha enviado en este chat (/limpiar)."""
|
||||
lista = historial_chat.pop(chat_id, None) or []
|
||||
borrados = 0
|
||||
for mid in reversed(lista):
|
||||
try:
|
||||
r = requests.post(
|
||||
f"https://api.telegram.org/bot{TOKEN}/deleteMessage",
|
||||
data={"chat_id": chat_id, "message_id": mid},
|
||||
timeout=8,
|
||||
)
|
||||
if r.json().get("ok"):
|
||||
borrados += 1
|
||||
except Exception:
|
||||
pass
|
||||
aviso = enviar(f"🧹 Pantalla limpia ({borrados} mensajes borrados).", chat_id)
|
||||
if aviso:
|
||||
threading.Timer(6.0, borrar, args=(chat_id, aviso)).start()
|
||||
|
||||
|
||||
def mandar_tv(mensaje, simple):
|
||||
try:
|
||||
url = f"{TV_API}?texto={urllib.parse.quote(mensaje)}"
|
||||
@@ -374,15 +399,18 @@ def procesar(texto, chat_id):
|
||||
log(f"panorama: {r.stdout.strip()[-200:]}")
|
||||
except Exception as e:
|
||||
log(f"panorama error: {e}")
|
||||
elif t in ("limpieza", "/limpieza", "limpiar", "/limpiar"):
|
||||
enviar("🧹 Ejecutando limpieza...", chat_id)
|
||||
try:
|
||||
from limpiar import limpiar
|
||||
resultado = limpiar()
|
||||
enviar(f"<pre>{resultado}</pre>", chat_id)
|
||||
except Exception as e:
|
||||
log(f"limpieza error: {e}")
|
||||
enviar(f"❌ Error: {e}", chat_id)
|
||||
elif t in ("limpieza", "/limpieza", "limpiar", "/limpiar", "clear", "/clear"):
|
||||
if t in ("limpieza", "/limpieza"):
|
||||
enviar("🧹 Ejecutando limpieza de procesos...", chat_id)
|
||||
try:
|
||||
from limpiar import limpiar
|
||||
resultado = limpiar()
|
||||
enviar(f"<pre>{resultado}</pre>", chat_id)
|
||||
except Exception as e:
|
||||
log(f"limpieza error: {e}")
|
||||
enviar(f"❌ Error: {e}", chat_id)
|
||||
else:
|
||||
limpiar_pantalla(chat_id)
|
||||
elif t.startswith("youtube ") or t.startswith("/youtube "):
|
||||
url = texto.split(" ", 1)[1].strip()
|
||||
if not url:
|
||||
|
||||
Reference in New Issue
Block a user