Spaces:
Runtime error
Runtime error
Update bot/config.py
Browse files- bot/config.py +17 -26
bot/config.py
CHANGED
|
@@ -3,47 +3,38 @@ import os
|
|
| 3 |
|
| 4 |
def _get_int(name: str, default: int) -> int:
|
| 5 |
try:
|
| 6 |
-
return int(
|
| 7 |
except Exception:
|
| 8 |
return default
|
| 9 |
|
| 10 |
def _get_str(name: str, default: str = "") -> str:
|
| 11 |
return str(os.environ.get(name, default)).strip()
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class Telegram:
|
| 14 |
API_ID: int = _get_int("API_ID", 0)
|
| 15 |
API_HASH: str = _get_str("API_HASH", "")
|
| 16 |
-
OWNER_ID: int = _get_int("OWNER_ID", 0)
|
| 17 |
-
|
| 18 |
-
# HF: SESSION_STRING preferred (works even if BOT_TOKEN blocked)
|
| 19 |
-
SESSION_STRING: str = _get_str("SESSION_STRING", "")
|
| 20 |
BOT_TOKEN: str = _get_str("BOT_TOKEN", "")
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
class Workers:
|
| 23 |
-
WORKER1_URL: str = _get_str("WORKER1_URL", "")
|
| 24 |
-
WORKER2_URL: str = _get_str("WORKER2_URL", "")
|
| 25 |
BOT_BACKEND_KEY: str = _get_str("BOT_BACKEND_KEY", "")
|
| 26 |
HF_API_KEY: str = _get_str("HF_API_KEY", "")
|
| 27 |
|
| 28 |
class Server:
|
| 29 |
BIND_ADDRESS: str = _get_str("BIND_ADDRESS", "0.0.0.0")
|
| 30 |
PORT: int = _get_int("PORT", 7860)
|
| 31 |
-
|
| 32 |
-
LOGGER_CONFIG_JSON = {
|
| 33 |
-
"version": 1,
|
| 34 |
-
"disable_existing_loggers": False,
|
| 35 |
-
"formatters": {
|
| 36 |
-
"default": {
|
| 37 |
-
"format": "[%(asctime)s][%(name)s][%(levelname)s] -> %(message)s",
|
| 38 |
-
"datefmt": "%d/%m/%Y %H:%M:%S",
|
| 39 |
-
}
|
| 40 |
-
},
|
| 41 |
-
"handlers": {"stream": {"class": "logging.StreamHandler", "formatter": "default"}},
|
| 42 |
-
"loggers": {
|
| 43 |
-
"uvicorn": {"level": "INFO", "handlers": ["stream"]},
|
| 44 |
-
"uvicorn.error": {"level": "INFO", "handlers": ["stream"]},
|
| 45 |
-
"bot": {"level": "INFO", "handlers": ["stream"]},
|
| 46 |
-
"hydrogram": {"level": "INFO", "handlers": ["stream"]},
|
| 47 |
-
"httpx": {"level": "WARNING", "handlers": ["stream"]},
|
| 48 |
-
},
|
| 49 |
-
}
|
|
|
|
| 3 |
|
| 4 |
def _get_int(name: str, default: int) -> int:
|
| 5 |
try:
|
| 6 |
+
return int(os.environ.get(name, str(default)))
|
| 7 |
except Exception:
|
| 8 |
return default
|
| 9 |
|
| 10 |
def _get_str(name: str, default: str = "") -> str:
|
| 11 |
return str(os.environ.get(name, default)).strip()
|
| 12 |
|
| 13 |
+
def _as_https_base(v: str) -> str:
|
| 14 |
+
v = (v or "").strip().rstrip("/")
|
| 15 |
+
if not v:
|
| 16 |
+
return ""
|
| 17 |
+
# if user already gave http/https, keep it
|
| 18 |
+
if v.startswith("http://") or v.startswith("https://"):
|
| 19 |
+
return v.rstrip("/")
|
| 20 |
+
# else assume domain-only
|
| 21 |
+
return "https://" + v
|
| 22 |
+
|
| 23 |
class Telegram:
|
| 24 |
API_ID: int = _get_int("API_ID", 0)
|
| 25 |
API_HASH: str = _get_str("API_HASH", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
BOT_TOKEN: str = _get_str("BOT_TOKEN", "")
|
| 27 |
+
SESSION_STRING: str = _get_str("SESSION_STRING", "")
|
| 28 |
+
OWNER_ID: int = _get_int("OWNER_ID", 0)
|
| 29 |
+
BOT_USERNAME: str = _get_str("TELEGRAM_BOT_USERNAME", "BotFather")
|
| 30 |
|
| 31 |
class Workers:
|
| 32 |
+
WORKER1_URL: str = _as_https_base(_get_str("WORKER1_URL", ""))
|
| 33 |
+
WORKER2_URL: str = _as_https_base(_get_str("WORKER2_URL", ""))
|
| 34 |
BOT_BACKEND_KEY: str = _get_str("BOT_BACKEND_KEY", "")
|
| 35 |
HF_API_KEY: str = _get_str("HF_API_KEY", "")
|
| 36 |
|
| 37 |
class Server:
|
| 38 |
BIND_ADDRESS: str = _get_str("BIND_ADDRESS", "0.0.0.0")
|
| 39 |
PORT: int = _get_int("PORT", 7860)
|
| 40 |
+
BASE_URL: str = _get_str("BASE_URL", "http://127.0.0.1:7860")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|