understanding commited on
Commit
fcd830a
·
verified ·
1 Parent(s): ae0a927

Update bot/client.py

Browse files
Files changed (1) hide show
  1. bot/client.py +22 -11
bot/client.py CHANGED
@@ -5,21 +5,32 @@ from bot.config import Telegram
5
 
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,
13
  in_memory=True,
14
- sleep_threshold=-1,
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,
12
  in_memory=True,
13
+ sleep_threshold=30,
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