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

30 lines
886 B
Python
Raw 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.
"""Telethon Connection 模式(与 Telegram Desktop 使用的传输类似可选用 obfuscated"""
from __future__ import annotations
from typing import Type
from telethon.network.connection import (
Connection,
ConnectionTcpAbridged,
ConnectionTcpFull,
ConnectionTcpIntermediate,
ConnectionTcpObfuscated,
)
def resolve_connection_class(mode: str) -> Type[Connection]:
m = (mode or "").strip().lower().replace("-", "_")
if not m or m == "tcp_full":
return ConnectionTcpFull
if m == "tcp_obfuscated":
return ConnectionTcpObfuscated
if m == "tcp_intermediate":
return ConnectionTcpIntermediate
if m == "tcp_abridged":
return ConnectionTcpAbridged
raise ValueError(
f"不支持的 TELEGRAM_CONNECTION={mode!r},可用: "
"tcp_full, tcp_obfuscated, tcp_intermediate, tcp_abridged"
)