# PATH: bot/config.py import os def _get_int(name: str, default: int) -> int: try: return int(os.environ.get(name, str(default))) except Exception: return default def _get_str(name: str, default: str = "") -> str: return str(os.environ.get(name, default)).strip() def _get_int_list(name: str) -> list[int]: raw = _get_str(name, "") if not raw: return [] parts = [p.strip() for p in raw.replace(";", ",").replace("|", ",").split(",")] out: list[int] = [] for p in parts: if not p: continue try: out.append(int(p)) except Exception: continue return out def _as_https_base(v: str) -> str: v = (v or "").strip().rstrip("/") if not v: return "" if v.startswith("http://") or v.startswith("https://"): return v.rstrip("/") return "https://" + v class Telegram: API_ID: int = _get_int("API_ID", 0) API_HASH: str = _get_str("API_HASH", "") BOT_TOKEN: str = _get_str("BOT_TOKEN", "") # ✅ BOT session (generated using API_ID + API_HASH + BOT_TOKEN) # In HF you already have this as SESSION_STRING SESSION_STRING: str = _get_str("SESSION_STRING", "") # ✅ USER session (generated using API_ID + API_HASH + phone login) USER_SESSION_STRING: str = _get_str("USER_SESSION_STRING", "") OWNER_ID: int = _get_int("OWNER_ID", 0) BOT_USERNAME: str = _get_str("TELEGRAM_BOT_USERNAME", "BotFather") ADMIN_IDS: list[int] = _get_int_list("ADMIN_IDS") # ✅ Added: compatibility shim for handlers.py (Auth.OWNERS/Auth.ADMINS) class Auth: # Optional multi-owner: OWNER_IDS="123,456" (comma/;/| supported) OWNERS: list[int] = _get_int_list("OWNER_IDS") or ( [Telegram.OWNER_ID] if Telegram.OWNER_ID else [] ) ADMINS: list[int] = Telegram.ADMIN_IDS or [] class Workers: WORKER1_URL: str = _as_https_base(_get_str("WORKER1_URL", "")) WORKER2_URL: str = _as_https_base(_get_str("WORKER2_URL", "")) BOT_BACKEND_KEY: str = _get_str("BOT_BACKEND_KEY", "") HF_API_KEY: str = _get_str("HF_API_KEY", "") class Server: BIND_ADDRESS: str = _get_str("BIND_ADDRESS", "0.0.0.0") PORT: int = _get_int("PORT", 7860) BASE_URL: str = _get_str("BASE_URL", "http://127.0.0.1:7860") LOGGER_CONFIG_JSON = { "version": 1, "disable_existing_loggers": False, "formatters": { "default": { "format": "[%(asctime)s][%(name)s][%(levelname)s] -> %(message)s", "datefmt": "%d/%m/%Y %H:%M:%S", } }, "handlers": {"stream": {"class": "logging.StreamHandler", "formatter": "default"}}, "loggers": { "uvicorn": {"level": "INFO", "handlers": ["stream"]}, "uvicorn.error": {"level": "INFO", "handlers": ["stream"]}, "bot": {"level": "INFO", "handlers": ["stream"]}, "hydrogram": {"level": "INFO", "handlers": ["stream"]}, "httpx": {"level": "WARNING", "handlers": ["stream"]}, }, }