""" main.py — Punto de entrada del UserBot. • Carga todos los plugins automáticamente desde /plugins • Inicia un servidor HTTP mínimo de health-check en PORT (7860) para mantener el Space de Hugging Face vivo • Imprime tabla de comandos al iniciar """ import asyncio import logging import os import sys import time import importlib import pkgutil from pathlib import Path from aiohttp import web from pyrogram import idle from config import Config # ── Logging ─────────────────────────────────────────────────────────────────── logging.basicConfig( level=logging.INFO, format="%(asctime)s │ %(levelname)-8s │ %(name)s │ %(message)s", datefmt="%H:%M:%S", ) log = logging.getLogger("userbot") # Silence noisy libs for lib in ("pyrogram", "asyncio", "aiohttp.access"): logging.getLogger(lib).setLevel(logging.WARNING) # ── Sanity checks ───────────────────────────────────────────────────────────── def _check_env(): missing = [k for k in ("API_ID", "API_HASH", "SESSION_STRING") if not os.environ.get(k)] if missing: log.error("❌ Variables de entorno faltantes: %s", ", ".join(missing)) log.error(" Configúralas en HF Spaces → Settings → Secrets") sys.exit(1) # ── Plugin loader ───────────────────────────────────────────────────────────── def _load_plugins(): plugins_dir = Path(__file__).parent / "plugins" loaded = [] for _, name, _ in pkgutil.iter_modules([str(plugins_dir)]): try: importlib.import_module(f"plugins.{name}") loaded.append(name) log.info(" ✅ Plugin cargado: %s", name) except Exception as e: log.error(" ❌ Error cargando plugin '%s': %s", name, e) return loaded # ── Minimal health-check HTTP server ───────────────────────────────────────── async def _start_web(): async def health(_): return web.Response( text='{"status":"ok","userbot":"running"}', content_type="application/json", ) async def index(_): return web.Response( text="