understanding commited on
Commit
5337d47
·
verified ·
1 Parent(s): dc987fd

Create bot/config.py

Browse files
Files changed (1) hide show
  1. bot/config.py +48 -0
bot/config.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ def _get_int(name: str, default: int) -> int:
4
+ try:
5
+ return int(os.environ.get(name, str(default)))
6
+ except Exception:
7
+ return default
8
+
9
+ class Telegram:
10
+ # User account session (phone) recommended
11
+ API_ID = _get_int("TELEGRAM_API_ID", 0)
12
+ API_HASH = os.environ.get("TELEGRAM_API_HASH", "")
13
+
14
+ # Use ONLY one of these:
15
+ SESSION_STRING = os.environ.get("SESSION_STRING", "") # ✅ user session string (phone)
16
+ BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN", "") # optional (bot token) if you ever use bot auth
17
+
18
+ OWNER_ID = _get_int("OWNER_ID", 0)
19
+
20
+ # optional: allowlist via env (space separated ids)
21
+ ALLOWED_USER_IDS = [x for x in os.environ.get("ALLOWED_USER_IDS", "").split() if x.strip()]
22
+
23
+ class Server:
24
+ BIND_ADDRESS = os.environ.get("BIND_ADDRESS", "0.0.0.0")
25
+ PORT = _get_int("PORT", 7860)
26
+
27
+ # Simple logging config for uvicorn + hydrogram
28
+ LOGGER_CONFIG_JSON = {
29
+ "version": 1,
30
+ "formatters": {
31
+ "default": {
32
+ "format": "[%(asctime)s][%(name)s][%(levelname)s] -> %(message)s",
33
+ "datefmt": "%d/%m/%Y %H:%M:%S",
34
+ }
35
+ },
36
+ "handlers": {
37
+ "stream_handler": {
38
+ "class": "logging.StreamHandler",
39
+ "formatter": "default",
40
+ }
41
+ },
42
+ "loggers": {
43
+ "uvicorn": {"level": "INFO", "handlers": ["stream_handler"]},
44
+ "uvicorn.error": {"level": "INFO", "handlers": ["stream_handler"]},
45
+ "hydrogram": {"level": "INFO", "handlers": ["stream_handler"]},
46
+ "bot": {"level": "INFO", "handlers": ["stream_handler"]},
47
+ },
48
+ }