Spaces:
Runtime error
Runtime error
File size: 1,483 Bytes
a405e76 45b6c2f fcd830a a405e76 fcd830a a405e76 c251b17 45b6c2f c251b17 fcd830a c251b17 fcd830a c251b17 fcd830a 45b6c2f fcd830a c251b17 fcd830a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# PATH: bot/client.py
from logging import getLogger
from hydrogram import Client
from bot.config import Telegram
logger = getLogger("bot")
def create_clients() -> tuple[Client, Client | None]:
base_args = dict(
api_id=Telegram.API_ID,
api_hash=Telegram.API_HASH,
in_memory=True,
sleep_threshold=30,
max_concurrent_transmissions=10,
)
# ✅ Prefer BOT session string (SESSION_STRING) to avoid DC2 auth-key creation on HF
if Telegram.SESSION_STRING:
logger.info("✅ Bot client using SESSION_STRING (pre-generated)")
bot = Client("bot_session", session_string=Telegram.SESSION_STRING, **base_args)
elif Telegram.BOT_TOKEN:
logger.warning("⚠️ Bot client using BOT_TOKEN (may create auth-key on a DC). Prefer SESSION_STRING.")
bot = Client("bot_session", bot_token=Telegram.BOT_TOKEN, **base_args)
else:
raise RuntimeError("Missing SESSION_STRING and BOT_TOKEN.")
# ✅ Worker user client ALWAYS uses USER_SESSION_STRING (phone account)
user = None
if Telegram.USER_SESSION_STRING:
logger.info("✅ Worker (Downloader) client using USER_SESSION_STRING")
user = Client(
"downloader_session",
session_string=Telegram.USER_SESSION_STRING,
no_updates=True,
**base_args,
)
else:
logger.warning("⚠️ No USER_SESSION_STRING. Restricted link download disabled.")
return bot, user |