Spaces:
Runtime error
Runtime error
| import os | |
| from dataclasses import dataclass | |
| class Config: | |
| # Telegram | |
| BOT_TOKEN: str | |
| API_ID: int | |
| API_HASH: str | |
| OWNER_ID: int | |
| # Workers | |
| WORKER1_URL: str | |
| WORKER2_URL: str | |
| BOT_BACKEND_KEY: str | |
| HF_API_KEY: str | |
| # Optional | |
| BOT_USERNAME: str = "" | |
| def _must(name: str) -> str: | |
| v = os.getenv(name, "").strip() | |
| if not v: | |
| raise RuntimeError(f"Missing env: {name}") | |
| return v | |
| def load_config() -> Config: | |
| return Config( | |
| BOT_TOKEN=_must("BOT_TOKEN"), | |
| API_ID=int(_must("API_ID")), | |
| API_HASH=_must("API_HASH"), | |
| OWNER_ID=int(_must("OWNER_ID")), | |
| WORKER1_URL=_must("WORKER1_URL").rstrip("/"), | |
| WORKER2_URL=_must("WORKER2_URL").rstrip("/"), | |
| BOT_BACKEND_KEY=_must("BOT_BACKEND_KEY"), | |
| HF_API_KEY=_must("HF_API_KEY"), | |
| BOT_USERNAME=os.getenv("BOT_USERNAME", "").strip(), | |
| ) |