patch 219dba6a312f4a8d40668f28f81baa8a8a535bfe
Author: E. Bosch <presidev@AT@gmail.com>
Date: Tue Feb 22 02:37:33 CET 2022
* telegram: Support to connect to test environment
Add options to configure this
hunk ./irgramd 80
- tornado.options.define('port', default=None, metavar='PORT', help='Port to listen on. (default 6667, default with TLS 6697)')
+ tornado.options.define('port', default=None, metavar='PORT', help='Port to listen on for IRC. (default 6667, default with TLS 6697)')
+ tornado.options.define('test', default=False, help='Connect to Telegram test environment')
+ tornado.options.define('test_datacenter', default=2, metavar='DATACENTER_NUMBER', help='Datacenter to connect to Telegram test environment')
+ tornado.options.define('test_host', default=None, metavar='HOST_IP', help='Host to connect to Telegram test environment (default: use a internal table depending on datacenter)')
+ tornado.options.define('test_port', default=443, metavar='PORT', help='Port to connect to Telegram test environment')
hunk ./telegram.py 24
+# Test IP table
+
+TEST_IPS = { 1: '149.154.175.10',
+ 2: '149.154.167.40',
+ 3: '149.154.175.117'
+ }
+
hunk ./telegram.py 41
+ self.test = settings['test']
+ self.test_dc = settings['test_datacenter']
+ self.test_ip = settings['test_host'] if settings['test_host'] else TEST_IPS[self.test_dc]
+ self.test_port = settings['test_port']
hunk ./telegram.py 66
- telegram_session = os.path.join(self.telegram_session_dir, 'telegram')
- self.telegram_client = telethon.TelegramClient(telegram_session, self.api_id, self.api_hash)
+ if self.test:
+ self.telegram_client = telethon.TelegramClient(None, self.api_id, self.api_hash)
+ self.telegram_client.session.set_dc(self.test_dc, self.test_ip, self.test_port)
+ else:
+ telegram_session = os.path.join(self.telegram_session_dir, 'telegram')
+ self.telegram_client = telethon.TelegramClient(telegram_session, self.api_id, self.api_hash)
hunk ./telegram.py 86
- await self.telegram_client.connect()
+ if self.test:
+ await self.telegram_client.start(self.phone, code_callback=lambda: str(self.test_dc) * 5)
+ else:
+ await self.telegram_client.connect()