From d3d02f173a9a30e83cbb053dc41ed014325d9455 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Dec 2018 21:19:53 +0200 Subject: [PATCH] Add option to use telegram test DC --- example-config.yaml | 11 +++++++++++ mautrix_telegram/abstract_user.py | 4 ++++ mautrix_telegram/config.py | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/example-config.yaml b/example-config.yaml index 034c3c78..76d947b1 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -241,6 +241,17 @@ telegram: api_hash: tjyd5yge35lbodk1xwzw2jstp90k55qz # (Optional) Create your own bot at https://t.me/BotFather bot_token: disabled + # Custom server to connect to. + server: + # Set to true to use these server settings. If false, will automatically + # use production server assigned by Telegram. Set to false in production. + enabled: false + # The DC ID to connect to. + dc: 2 + # The IP to connect to. + ip: 149.154.167.40 + # The port to connect to. 443 may not work, 80 is better and both are equally secure. + port: 80 # Telethon proxy configuration. # You must install PySocks from pip for proxies to work. proxy: diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index aadaf5dc..e70f0ba7 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -100,6 +100,10 @@ class AbstractUser(ABC): device = f"{platform.system()} {platform.release()}" sysversion = MautrixTelegramClient.__version__ self.session = self.session_container.new_session(self.name) + if config["telegram.server.enabled"]: + self.session.set_dc(config["telegram.server.dc"], + config["telegram.server.ip"], + config["telegram.server.port"]) self.client = MautrixTelegramClient(session=self.session, api_id=config["telegram.api_id"], api_hash=config["telegram.api_hash"], diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 0e35219a..0678dc14 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -251,6 +251,10 @@ class Config(DictWithRecursion): copy("telegram.api_id") copy("telegram.api_hash") copy("telegram.bot_token") + copy("telegram.server.enabled") + copy("telegram.server.dc") + copy("telegram.server.ip") + copy("telegram.server.port") copy("telegram.proxy.type") copy("telegram.proxy.address") copy("telegram.proxy.port")