understanding commited on
Commit
f780c8b
·
verified ·
1 Parent(s): 6b0f0a7

Create bot/__init__.py

Browse files
Files changed (1) hide show
  1. bot/bot/__init__.py +28 -0
bot/bot/__init__.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from logging.config import dictConfig
2
+ from logging import getLogger
3
+ from hydrogram import Client
4
+
5
+ from .config import Telegram, LOGGER_CONFIG_JSON
6
+
7
+ dictConfig(LOGGER_CONFIG_JSON)
8
+ logger = getLogger("bot")
9
+
10
+ # Build client kwargs safely
11
+ _kwargs = dict(
12
+ name="bot",
13
+ api_id=Telegram.API_ID,
14
+ api_hash=Telegram.API_HASH,
15
+ plugins={"root": "bot/plugins"},
16
+ sleep_threshold=-1,
17
+ max_concurrent_transmissions=10,
18
+ )
19
+
20
+ # Prefer SESSION_STRING, else BOT_TOKEN
21
+ if Telegram.SESSION_STRING:
22
+ _kwargs["session_string"] = Telegram.SESSION_STRING
23
+ elif Telegram.BOT_TOKEN:
24
+ _kwargs["bot_token"] = Telegram.BOT_TOKEN
25
+ else:
26
+ raise RuntimeError("Set SESSION_STRING or TELEGRAM_BOT_TOKEN in environment.")
27
+
28
+ TelegramBot = Client(**_kwargs)