初始化
This commit is contained in:
29
tg_bridge/connection_mode.py
Normal file
29
tg_bridge/connection_mode.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""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"
|
||||
)
|
||||
Reference in New Issue
Block a user