Skip to content

Commit

Permalink
add init params
Browse files Browse the repository at this point in the history
  • Loading branch information
eyMarv committed Feb 22, 2024
1 parent f2a7572 commit f4e3641
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 32 deletions.
39 changes: 23 additions & 16 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
from pyrogram.utils import ainput
from .dispatcher import Dispatcher
from .file_id import FileId, FileType, ThumbnailSource
from .filters import Filter
from .mime_types import mime_types
from .parser import Parser
from .session.internals import MsgId
Expand Down Expand Up @@ -202,6 +201,10 @@ class Client(Methods):
Set the maximum amount of concurrent transmissions (uploads & downloads).
A value that is too high may result in network related issues.
Defaults to 1.
init_params (``raw.types.JsonObject``, *optional*):
Internal parameter.
Defaults to None.
"""

APP_VERSION = f"Pyrogram {__version__}"
Expand Down Expand Up @@ -258,6 +261,7 @@ def __init__(
sleep_threshold: int = Session.SLEEP_THRESHOLD,
hide_password: bool = False,
max_concurrent_transmissions: int = MAX_CONCURRENT_TRANSMISSIONS,
init_params: raw.types.JsonObject = None,
):
super().__init__()

Expand Down Expand Up @@ -289,6 +293,7 @@ def __init__(
self.sleep_threshold = sleep_threshold
self.hide_password = hide_password
self.max_concurrent_transmissions = max_concurrent_transmissions
self.init_params = init_params

self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler")

Expand Down Expand Up @@ -573,9 +578,7 @@ async def fetch_peers(
username = (
peer.username.lower()
if peer.username
else peer.usernames[0].username.lower()
if peer.usernames
else None
else peer.usernames[0].username.lower() if peer.usernames else None
)
if peer.usernames is not None and len(peer.usernames) > 1:
for uname in peer.usernames:
Expand All @@ -592,9 +595,7 @@ async def fetch_peers(
username = (
peer.username.lower()
if peer.username
else peer.usernames[0].username.lower()
if peer.usernames
else None
else peer.usernames[0].username.lower() if peer.usernames else None
)
if peer.usernames is not None and len(peer.usernames) > 1:
for uname in peer.usernames:
Expand Down Expand Up @@ -1031,9 +1032,11 @@ async def get_file(
session = Session(
self,
dc_id,
await Auth(self, dc_id, await self.storage.test_mode()).create()
if dc_id != await self.storage.dc_id()
else await self.storage.auth_key(),
(
await Auth(self, dc_id, await self.storage.test_mode()).create()
if dc_id != await self.storage.dc_id()
else await self.storage.auth_key()
),
await self.storage.test_mode(),
is_media=True,
)
Expand Down Expand Up @@ -1071,9 +1074,11 @@ async def get_file(
if progress:
func = functools.partial(
progress,
min(offset_bytes, file_size)
if file_size != 0
else offset_bytes,
(
min(offset_bytes, file_size)
if file_size != 0
else offset_bytes
),
file_size,
*progress_args,
)
Expand Down Expand Up @@ -1166,9 +1171,11 @@ async def get_file(
if progress:
func = functools.partial(
progress,
min(offset_bytes, file_size)
if file_size != 0
else offset_bytes,
(
min(offset_bytes, file_size)
if file_size != 0
else offset_bytes
),
file_size,
*progress_args,
)
Expand Down
52 changes: 36 additions & 16 deletions pyrogram/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from hashlib import sha1
from io import BytesIO

from pyrogram.raw.all import layer

import pyrogram
from pyrogram import raw
from pyrogram.connection import Connection
Expand All @@ -37,7 +39,6 @@
BadMsgNotification,
SecurityCheckMismatch,
)
from pyrogram.raw.all import layer
from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts
from .internals import MsgId, MsgFactory

Expand Down Expand Up @@ -126,22 +127,41 @@ async def start(self):
)

if not self.is_cdn:
await self.send(
raw.functions.InvokeWithLayer(
layer=layer,
query=raw.functions.InitConnection(
api_id=await self.client.storage.api_id(),
app_version=self.client.app_version,
device_model=self.client.device_model,
system_version=self.client.system_version,
system_lang_code=self.client.lang_code,
lang_code=self.client.lang_code,
lang_pack=self.client.lang_pack,
query=raw.functions.help.GetConfig(),
if self.client.init_params is not None:
await self.send(
raw.functions.InvokeWithLayer(
layer=layer,
query=raw.functions.InitConnection(
api_id=await self.client.storage.api_id(),
app_version=self.client.app_version,
device_model=self.client.device_model,
system_version=self.client.system_version,
system_lang_code=self.client.lang_code,
lang_code=self.client.lang_code,
lang_pack=self.client.lang_pack,
query=raw.functions.help.GetConfig(),
params=self.client.init_params,
),
),
),
timeout=self.START_TIMEOUT,
)
timeout=self.START_TIMEOUT,
)
else:
await self.send(
raw.functions.InvokeWithLayer(
layer=layer,
query=raw.functions.InitConnection(
api_id=await self.client.storage.api_id(),
app_version=self.client.app_version,
device_model=self.client.device_model,
system_version=self.client.system_version,
system_lang_code=self.client.lang_code,
lang_code=self.client.lang_code,
lang_pack=self.client.lang_pack,
query=raw.functions.help.GetConfig(),
),
),
timeout=self.START_TIMEOUT,
)

self.ping_task = self.loop.create_task(self.ping_worker())

Expand Down

0 comments on commit f4e3641

Please sign in to comment.