mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Allow user-defined session properties. Related to #86
This commit adds five 5 extra parameters to the Client class: app_version, device_model, system_version, system_lang_code, lang_code
This commit is contained in:
parent
f4c0793a0b
commit
55ef4abb27
@ -129,6 +129,11 @@ class Client(Methods, BaseClient):
|
|||||||
session_name: str,
|
session_name: str,
|
||||||
api_id: int or str = None,
|
api_id: int or str = None,
|
||||||
api_hash: str = None,
|
api_hash: str = None,
|
||||||
|
app_version: str = None,
|
||||||
|
device_model: str = None,
|
||||||
|
system_version: str = None,
|
||||||
|
system_lang_code: str = None,
|
||||||
|
lang_code: str = None,
|
||||||
proxy: dict = None,
|
proxy: dict = None,
|
||||||
test_mode: bool = False,
|
test_mode: bool = False,
|
||||||
phone_number: str = None,
|
phone_number: str = None,
|
||||||
@ -145,6 +150,11 @@ class Client(Methods, BaseClient):
|
|||||||
self.session_name = session_name
|
self.session_name = session_name
|
||||||
self.api_id = int(api_id) if api_id else None
|
self.api_id = int(api_id) if api_id else None
|
||||||
self.api_hash = api_hash
|
self.api_hash = api_hash
|
||||||
|
self.app_version = app_version
|
||||||
|
self.device_model = device_model
|
||||||
|
self.system_version = system_version
|
||||||
|
self.system_lang_code = system_lang_code
|
||||||
|
self.lang_code = lang_code
|
||||||
# TODO: Make code consistent, use underscore for private/protected fields
|
# TODO: Make code consistent, use underscore for private/protected fields
|
||||||
self._proxy = proxy
|
self._proxy = proxy
|
||||||
self.test_mode = test_mode
|
self.test_mode = test_mode
|
||||||
@ -854,6 +864,68 @@ class Client(Methods, BaseClient):
|
|||||||
"More info: https://docs.pyrogram.ml/start/ProjectSetup#configuration"
|
"More info: https://docs.pyrogram.ml/start/ProjectSetup#configuration"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: Woah! Some redundant code down here
|
||||||
|
|
||||||
|
if self.app_version:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.app_version = Client.APP_VERSION
|
||||||
|
|
||||||
|
if parser.has_section("pyrogram"):
|
||||||
|
self.app_version = parser.get(
|
||||||
|
"pyrogram",
|
||||||
|
"app_version",
|
||||||
|
fallback=Client.APP_VERSION
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.device_model:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.device_model = Client.DEVICE_MODEL
|
||||||
|
|
||||||
|
if parser.has_section("pyrogram"):
|
||||||
|
self.device_model = parser.get(
|
||||||
|
"pyrogram",
|
||||||
|
"device_model",
|
||||||
|
fallback=Client.DEVICE_MODEL
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.system_version:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.system_version = Client.SYSTEM_VERSION
|
||||||
|
|
||||||
|
if parser.has_section("pyrogram"):
|
||||||
|
self.system_version = parser.get(
|
||||||
|
"pyrogram",
|
||||||
|
"system_version",
|
||||||
|
fallback=Client.SYSTEM_VERSION
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.system_lang_code:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.system_lang_code = Client.SYSTEM_LANG_CODE
|
||||||
|
|
||||||
|
if parser.has_section("pyrogram"):
|
||||||
|
self.system_lang_code = parser.get(
|
||||||
|
"pyrogram",
|
||||||
|
"system_lang_code",
|
||||||
|
fallback=Client.SYSTEM_LANG_CODE
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.lang_code:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.lang_code = Client.LANG_CODE
|
||||||
|
|
||||||
|
if parser.has_section("pyrogram"):
|
||||||
|
self.lang_code = parser.get(
|
||||||
|
"pyrogram",
|
||||||
|
"lang_code",
|
||||||
|
fallback=Client.LANG_CODE
|
||||||
|
)
|
||||||
|
|
||||||
if self._proxy:
|
if self._proxy:
|
||||||
self._proxy["enabled"] = True
|
self._proxy["enabled"] = True
|
||||||
else:
|
else:
|
||||||
|
@ -142,11 +142,11 @@ class Session:
|
|||||||
layer,
|
layer,
|
||||||
functions.InitConnection(
|
functions.InitConnection(
|
||||||
api_id=self.client.api_id,
|
api_id=self.client.api_id,
|
||||||
device_model=self.client.DEVICE_MODEL,
|
app_version=self.client.app_version,
|
||||||
system_version=self.client.SYSTEM_VERSION,
|
device_model=self.client.device_model,
|
||||||
app_version=self.client.APP_VERSION,
|
system_version=self.client.system_version,
|
||||||
system_lang_code=self.client.SYSTEM_LANG_CODE,
|
system_lang_code=self.client.system_lang_code,
|
||||||
lang_code=self.client.LANG_CODE,
|
lang_code=self.client.lang_code,
|
||||||
lang_pack="",
|
lang_pack="",
|
||||||
query=functions.help.GetConfig(),
|
query=functions.help.GetConfig(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user