understanding commited on
Commit
45b6c2f
·
verified ·
1 Parent(s): 822206f

Update bot/client.py

Browse files
Files changed (1) hide show
  1. bot/client.py +14 -12
bot/client.py CHANGED
@@ -5,7 +5,7 @@ from bot.config import Telegram
5
 
6
  logger = getLogger("bot")
7
 
8
- def create_clients() -> tuple[Client, Client]:
9
  base_args = dict(
10
  api_id=Telegram.API_ID,
11
  api_hash=Telegram.API_HASH,
@@ -14,23 +14,25 @@ def create_clients() -> tuple[Client, Client]:
14
  max_concurrent_transmissions=10,
15
  )
16
 
17
- # 1. Main Bot
18
- if not Telegram.BOT_TOKEN:
19
- raise RuntimeError("BOT_TOKEN is required.")
20
-
21
- bot = Client("bot_session", bot_token=Telegram.BOT_TOKEN, **base_args)
 
 
 
22
 
23
- # 2. User Client (Downloader)
24
  user = None
25
- if Telegram.USER_SESSION_STRING:
26
- logger.info("✅ Downloader Client Configured")
27
  user = Client(
28
  "downloader_session",
29
  session_string=Telegram.USER_SESSION_STRING,
30
  no_updates=True,
31
- **base_args
32
  )
33
- else:
34
- logger.warning("⚠️ No USER_SESSION_STRING. Restricted links will fail.")
35
 
36
  return bot, user
 
5
 
6
  logger = getLogger("bot")
7
 
8
+ def create_clients() -> tuple[Client, Client | None]:
9
  base_args = dict(
10
  api_id=Telegram.API_ID,
11
  api_hash=Telegram.API_HASH,
 
14
  max_concurrent_transmissions=10,
15
  )
16
 
17
+ if Telegram.BOT_TOKEN:
18
+ logger.info("✅ Using BOT_TOKEN auth")
19
+ bot = Client("bot_session", bot_token=Telegram.BOT_TOKEN, **base_args)
20
+ elif Telegram.SESSION_STRING:
21
+ logger.warning("⚠️ BOT_TOKEN missing; running legacy SESSION_STRING mode (not a bot).")
22
+ bot = Client("user_session", session_string=Telegram.SESSION_STRING, **base_args)
23
+ else:
24
+ raise RuntimeError("Missing BOT_TOKEN (preferred) and SESSION_STRING is empty.")
25
 
 
26
  user = None
27
+ if Telegram.BOT_TOKEN and Telegram.USER_SESSION_STRING:
28
+ logger.info("✅ Worker (Downloader) Client Configured")
29
  user = Client(
30
  "downloader_session",
31
  session_string=Telegram.USER_SESSION_STRING,
32
  no_updates=True,
33
+ **base_args,
34
  )
35
+ elif Telegram.BOT_TOKEN:
36
+ logger.warning("⚠️ No USER_SESSION_STRING. Link-archive disabled.")
37
 
38
  return bot, user