understanding commited on
Commit
cc8851e
·
verified ·
1 Parent(s): 3f5799a

Update bot/client.py

Browse files
Files changed (1) hide show
  1. bot/client.py +7 -14
bot/client.py CHANGED
@@ -6,12 +6,7 @@ from bot.config import Telegram
6
  logger = getLogger("bot")
7
 
8
  def create_client() -> Client:
9
- """
10
- Creates Hydrogram client in a safe way:
11
- - If SESSION_STRING is present -> user/bot session (no bot token needed)
12
- - Else BOT_TOKEN must be present
13
- """
14
- kwargs = dict(
15
  name="app",
16
  api_id=Telegram.API_ID,
17
  api_hash=Telegram.API_HASH,
@@ -20,13 +15,11 @@ def create_client() -> Client:
20
  max_concurrent_transmissions=10,
21
  )
22
 
23
- if Telegram.SESSION_STRING.strip():
24
- kwargs["session_string"] = Telegram.SESSION_STRING.strip()
25
  logger.info("Using SESSION_STRING auth")
26
- else:
27
- if not Telegram.BOT_TOKEN.strip():
28
- raise RuntimeError("Missing BOT_TOKEN (and SESSION_STRING is empty).")
29
- kwargs["bot_token"] = Telegram.BOT_TOKEN.strip()
30
- logger.info("Using BOT_TOKEN auth")
31
 
32
- return Client(**kwargs)
 
 
 
 
6
  logger = getLogger("bot")
7
 
8
  def create_client() -> Client:
9
+ base = dict(
 
 
 
 
 
10
  name="app",
11
  api_id=Telegram.API_ID,
12
  api_hash=Telegram.API_HASH,
 
15
  max_concurrent_transmissions=10,
16
  )
17
 
18
+ if Telegram.SESSION_STRING:
 
19
  logger.info("Using SESSION_STRING auth")
20
+ return Client(session_string=Telegram.SESSION_STRING, **base)
 
 
 
 
21
 
22
+ if not Telegram.BOT_TOKEN:
23
+ raise RuntimeError("Missing BOT_TOKEN and SESSION_STRING is empty.")
24
+ logger.info("Using BOT_TOKEN auth")
25
+ return Client(bot_token=Telegram.BOT_TOKEN, **base)