Spaces:
Runtime error
Runtime error
File size: 2,993 Bytes
8419c9c 3288146 bf573ad 8419c9c 3f5799a 8419c9c bf573ad fa2ac4f 8419c9c 3f5799a 8419c9c bf573ad 341445e bf573ad 3288146 bf573ad 8419c9c fa2ac4f 3f5799a bf573ad 3f5799a 8419c9c fa2ac4f 8419c9c bf573ad 6965c1f fa2ac4f 6965c1f bf573ad 6965c1f bf573ad 6965c1f bf573ad 6965c1f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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"]},
},
} |