Files
tg_python/tg_bridge/client_factory.py
2026-04-23 22:06:19 +08:00

24 lines
769 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from telethon import TelegramClient
from tg_bridge.config import Settings
from tg_bridge.connection_mode import resolve_connection_class
from tg_bridge.proxy import telethon_proxy_from_settings
def create_telegram_client(s: Settings) -> TelegramClient:
"""创建带代理与连接超时的 TelegramClientTelethon 默认 timeout=10 经代理易超时)。"""
proxy = telethon_proxy_from_settings(s)
conn = resolve_connection_class(s.connection_mode)
return TelegramClient(
str(s.session_path),
s.api_id,
s.api_hash,
proxy=proxy,
connection=conn,
timeout=s.connect_timeout,
connection_retries=s.connection_retries,
retry_delay=s.retry_delay,
)