# 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