From 351866d9e497450906df55a6b38ffc0730a64e43 Mon Sep 17 00:00:00 2001 From: Sergey Blazhko Date: Thu, 18 Jul 2019 12:33:38 +0300 Subject: [PATCH] Added option to connect via MTProxy. Proxy secret should be set in proxy.password config parameter. --- example-config.yaml | 2 +- mautrix_telegram/abstract_user.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 1c80967e..690d081b 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -307,7 +307,7 @@ telegram: # Telethon proxy configuration. # You must install PySocks from pip for proxies to work. proxy: - # Allowed types: disabled, socks4, socks5, http + # Allowed types: disabled, socks4, socks5, http, mtproxy type: disabled # Proxy IP address and port. address: 127.0.0.1 diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index dd9f3d02..dd3112f4 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -96,6 +96,8 @@ class AbstractUser(ABC): proxy_type = 2 elif proxy_type == "http": proxy_type = 3 + elif proxy_type == "mtproxy": + proxy_type = 4 return (proxy_type, config["telegram.proxy.address"], config["telegram.proxy.port"], @@ -119,6 +121,12 @@ class AbstractUser(ABC): device = config["telegram.device_info.device_model"] sysversion = config["telegram.device_info.system_version"] appversion = config["telegram.device_info.app_version"] + import telethon + connection = telethon.network.connection.ConnectionTcpFull + proxy = self._proxy_settings + if proxy is not None and proxy[0] == 4: + connection = telethon.network.connection.ConnectionTcpMTProxyRandomizedIntermediate + proxy = (proxy[1], proxy[2], proxy[5]) self.client = MautrixTelegramClient( session=self.session, @@ -135,8 +143,8 @@ class AbstractUser(ABC): retry_delay=config["telegram.connection.retry_delay"], flood_sleep_threshold=config["telegram.connection.flood_sleep_threshold"], request_retries=config["telegram.connection.request_retries"], - - proxy=self._proxy_settings, + connection=connection, + proxy=proxy, loop=self.loop, base_logger=base_logger