Spaces:
Runtime error
Runtime error
Update bot/client.py
Browse files- bot/client.py +12 -10
bot/client.py
CHANGED
|
@@ -14,25 +14,27 @@ def create_clients() -> tuple[Client, Client | None]:
|
|
| 14 |
max_concurrent_transmissions=10,
|
| 15 |
)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 25 |
|
|
|
|
| 26 |
user = None
|
| 27 |
-
if Telegram.
|
| 28 |
-
logger.info("✅ Worker (Downloader)
|
| 29 |
user = Client(
|
| 30 |
"downloader_session",
|
| 31 |
session_string=Telegram.USER_SESSION_STRING,
|
| 32 |
no_updates=True,
|
| 33 |
**base_args,
|
| 34 |
)
|
| 35 |
-
|
| 36 |
-
logger.warning("⚠️ No USER_SESSION_STRING.
|
| 37 |
|
| 38 |
return bot, user
|
|
|
|
| 14 |
max_concurrent_transmissions=10,
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# ✅ Prefer BOT session string (SESSION_STRING) to avoid DC2 auth-key creation on HF
|
| 18 |
+
if Telegram.SESSION_STRING:
|
| 19 |
+
logger.info("✅ Bot client using SESSION_STRING (pre-generated)")
|
| 20 |
+
bot = Client("bot_session", session_string=Telegram.SESSION_STRING, **base_args)
|
| 21 |
+
elif Telegram.BOT_TOKEN:
|
| 22 |
+
logger.warning("⚠️ Bot client using BOT_TOKEN (may create auth-key on a DC). Prefer SESSION_STRING.")
|
| 23 |
bot = Client("bot_session", bot_token=Telegram.BOT_TOKEN, **base_args)
|
|
|
|
|
|
|
|
|
|
| 24 |
else:
|
| 25 |
+
raise RuntimeError("Missing SESSION_STRING and BOT_TOKEN.")
|
| 26 |
|
| 27 |
+
# ✅ Worker user client ALWAYS uses USER_SESSION_STRING (phone account)
|
| 28 |
user = None
|
| 29 |
+
if Telegram.USER_SESSION_STRING:
|
| 30 |
+
logger.info("✅ Worker (Downloader) client using USER_SESSION_STRING")
|
| 31 |
user = Client(
|
| 32 |
"downloader_session",
|
| 33 |
session_string=Telegram.USER_SESSION_STRING,
|
| 34 |
no_updates=True,
|
| 35 |
**base_args,
|
| 36 |
)
|
| 37 |
+
else:
|
| 38 |
+
logger.warning("⚠️ No USER_SESSION_STRING. Restricted link download disabled.")
|
| 39 |
|
| 40 |
return bot, user
|