Allow specifying custom version/lang code/etc on client.connect

This commit is contained in:
Lonami Exo 2017-06-03 13:24:27 +02:00
parent 06db6c3823
commit b472421b8a

View File

@ -106,10 +106,20 @@ class TelegramClient:
# region Connecting # region Connecting
def connect(self, reconnect=False): def connect(self, reconnect=False,
"""Connects to the Telegram servers, executing authentication if required. device_model=None, system_version=None,
Note that authenticating to the Telegram servers is not the same as authenticating app_version=None, lang_code=None):
the app, which requires to send a code first.""" """Connects to the Telegram servers, executing authentication if
required. Note that authenticating to the Telegram servers is
not the same as authenticating the desired user itself, which
may require a call (or several) to 'sign_in' for the first time.
Default values for the optional parameters if left as None are:
device_model = platform.node()
system_version = platform.system()
app_version = TelegramClient.__version__
lang_code = 'en'
"""
if self.transport is None: if self.transport is None:
self.transport = TcpTransport(self.session.server_address, self.transport = TcpTransport(self.session.server_address,
self.session.port, proxy=self.proxy) self.session.port, proxy=self.proxy)
@ -124,14 +134,24 @@ class TelegramClient:
self.sender = MtProtoSender(self.transport, self.session) self.sender = MtProtoSender(self.transport, self.session)
self.sender.connect() self.sender.connect()
# Set the default parameters if left unspecified
if not device_model:
device_model = platform.node()
if not system_version:
system_version = platform.system()
if not app_version:
app_version = self.__version__
if not lang_code:
lang_code = 'en'
# Now it's time to send an InitConnectionRequest # Now it's time to send an InitConnectionRequest
# This must always be invoked with the layer we'll be using # This must always be invoked with the layer we'll be using
query = InitConnectionRequest( query = InitConnectionRequest(
api_id=self.api_id, api_id=self.api_id,
device_model=platform.node(), device_model=device_model,
system_version=platform.system(), system_version=system_version,
app_version=self.__version__, app_version=app_version,
lang_code='en', lang_code=lang_code,
query=GetConfigRequest()) query=GetConfigRequest())
result = self.invoke( result = self.invoke(