24 lines
769 B
Python
24 lines
769 B
Python
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:
|
||
"""创建带代理与连接超时的 TelegramClient(Telethon 默认 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,
|
||
)
|