From 34b51b6481de6166d43aa4c3f37bbe50ef8e6c40 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 16 Mar 2019 16:50:40 +0100 Subject: [PATCH] Force keyword arguments for all TL types --- compiler/api/compiler.py | 12 ++-- pyrogram/client/client.py | 34 ++++++----- pyrogram/client/ext/utils.py | 6 +- .../methods/chats/export_chat_invite_link.py | 2 +- pyrogram/client/methods/chats/get_chat.py | 6 +- .../client/methods/chats/get_chat_members.py | 2 +- .../client/methods/contacts/get_contacts.py | 2 +- .../methods/messages/edit_message_media.py | 16 ++++-- .../client/methods/messages/get_messages.py | 2 +- .../client/methods/messages/send_animation.py | 2 +- .../client/methods/messages/send_audio.py | 2 +- .../client/methods/messages/send_document.py | 2 +- .../client/methods/messages/send_location.py | 6 +- .../methods/messages/send_media_group.py | 2 +- .../client/methods/messages/send_sticker.py | 2 +- .../client/methods/messages/send_video.py | 2 +- pyrogram/client/methods/password/utils.py | 2 +- pyrogram/client/methods/users/get_me.py | 2 +- .../methods/users/set_user_profile_photo.py | 2 +- pyrogram/client/style/html.py | 14 ++--- pyrogram/client/style/markdown.py | 14 ++--- .../types/bots/inline_keyboard_button.py | 14 +++-- .../types/bots/inline_keyboard_markup.py | 4 +- pyrogram/client/types/bots/keyboard_button.py | 6 +- .../types/bots/reply_keyboard_markup.py | 8 ++- .../types/messages_and_media/sticker.py | 5 +- pyrogram/session/auth.py | 56 +++++++++---------- pyrogram/session/session.py | 14 ++--- 28 files changed, 133 insertions(+), 108 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index c9ea5f34..fe204a98 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -287,9 +287,11 @@ def start(): sorted_args = sort_args(c.args) - arguments = ", " + ", ".join( - [get_argument_type(i) for i in sorted_args if i != ("flags", "#")] - ) if c.args else "" + arguments = ( + ", " + + ("*, " if c.args else "") + + (", ".join([get_argument_type(i) for i in sorted_args if i != ("flags", "#")]) if c.args else "") + ) fields = "\n ".join( ["self.{0} = {0} # {1}".format(i[0], i[1]) for i in c.args if i != ("flags", "#")] @@ -456,7 +458,9 @@ def start(): fields=fields, read_types=read_types, write_types=write_types, - return_arguments=", ".join([i[0] for i in sorted_args if i != ("flags", "#")]), + return_arguments=", ".join( + ["{0}={0}".format(i[0]) for i in sorted_args if i != ("flags", "#")] + ), slots=", ".join(['"{}"'.format(i[0]) for i in sorted_args if i != ("flags", "#")]), qualname="{}{}".format("{}.".format(c.namespace) if c.namespace else "", c.name) ) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index df1ff1c5..253cc754 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -627,9 +627,9 @@ class Client(Methods, BaseClient): try: r = self.send( functions.auth.SignIn( - self.phone_number, - phone_code_hash, - self.phone_code + phone_number=self.phone_number, + phone_code_hash=phone_code_hash, + phone_code=self.phone_code ) ) except PhoneNumberUnoccupied: @@ -640,11 +640,11 @@ class Client(Methods, BaseClient): try: r = self.send( functions.auth.SignUp( - self.phone_number, - phone_code_hash, - self.phone_code, - self.first_name, - self.last_name + phone_number=self.phone_number, + phone_code_hash=phone_code_hash, + phone_code=self.phone_code, + first_name=self.first_name, + last_name=self.last_name ) ) except PhoneNumberOccupied: @@ -738,7 +738,11 @@ class Client(Methods, BaseClient): break if terms_of_service: - assert self.send(functions.help.AcceptTermsOfService(terms_of_service.id)) + assert self.send( + functions.help.AcceptTermsOfService( + id=terms_of_service.id + ) + ) self.password = None self.user_id = r.user.id @@ -1036,10 +1040,10 @@ class Client(Methods, BaseClient): raise ConnectionError("Client has not been started") if self.no_updates: - data = functions.InvokeWithoutUpdates(data) + data = functions.InvokeWithoutUpdates(query=data) if self.takeout_id: - data = functions.InvokeWithTakeout(self.takeout_id, data) + data = functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=data) r = self.session.send(data, retries, timeout) @@ -1353,7 +1357,7 @@ class Client(Methods, BaseClient): self.fetch_peers( self.send( functions.users.GetUsers( - id=[types.InputUser(peer_id, 0)] + id=[types.InputUser(user_id=peer_id, access_hash=0)] ) ) ) @@ -1361,7 +1365,7 @@ class Client(Methods, BaseClient): if str(peer_id).startswith("-100"): self.send( functions.channels.GetChannels( - id=[types.InputChannel(int(str(peer_id)[4:]), 0)] + id=[types.InputChannel(channel_id=int(str(peer_id)[4:]), access_hash=0)] ) ) else: @@ -1668,8 +1672,8 @@ class Client(Methods, BaseClient): hashes = session.send( functions.upload.GetCdnFileHashes( - r.file_token, - offset + file_token=r.file_token, + offset=offset ) ) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 087773f4..981752fa 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -67,10 +67,10 @@ def get_peer_id(input_peer) -> int: def get_input_peer(peer_id: int, access_hash: int): return ( - types.InputPeerUser(peer_id, access_hash) if peer_id > 0 - else types.InputPeerChannel(int(str(peer_id)[4:]), access_hash) + types.InputPeerUser(user_id=peer_id, access_hash=access_hash) if peer_id > 0 + else types.InputPeerChannel(channel_id=int(str(peer_id)[4:]), access_hash=access_hash) if (str(peer_id).startswith("-100") and access_hash) - else types.InputPeerChat(-peer_id) + else types.InputPeerChat(chat_id=-peer_id) ) diff --git a/pyrogram/client/methods/chats/export_chat_invite_link.py b/pyrogram/client/methods/chats/export_chat_invite_link.py index 9ff8c9c0..39f1a2fe 100644 --- a/pyrogram/client/methods/chats/export_chat_invite_link.py +++ b/pyrogram/client/methods/chats/export_chat_invite_link.py @@ -45,7 +45,7 @@ class ExportChatInviteLink(BaseClient): if isinstance(peer, types.InputPeerChat): return self.send( functions.messages.ExportChatInvite( - chat_id=peer.chat_id + peer=peer.chat_id ) ).link elif isinstance(peer, types.InputPeerChannel): diff --git a/pyrogram/client/methods/chats/get_chat.py b/pyrogram/client/methods/chats/get_chat.py index d30fd9bb..9db34669 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.py @@ -67,10 +67,10 @@ class GetChat(BaseClient): peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): - r = self.send(functions.channels.GetFullChannel(peer)) + r = self.send(functions.channels.GetFullChannel(channel=peer)) elif isinstance(peer, (types.InputPeerUser, types.InputPeerSelf)): - r = self.send(functions.users.GetFullUser(peer)) + r = self.send(functions.users.GetFullUser(id=peer)) else: - r = self.send(functions.messages.GetFullChat(peer.chat_id)) + r = self.send(functions.messages.GetFullChat(chat_id=peer.chat_id)) return pyrogram.Chat._parse_full(self, r) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 382d7f0f..6c56b532 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -92,7 +92,7 @@ class GetChatMembers(BaseClient): self, self.send( functions.messages.GetFullChat( - peer.chat_id + chat_id=peer.chat_id ) ) ) diff --git a/pyrogram/client/methods/contacts/get_contacts.py b/pyrogram/client/methods/contacts/get_contacts.py index 29b7e176..30310913 100644 --- a/pyrogram/client/methods/contacts/get_contacts.py +++ b/pyrogram/client/methods/contacts/get_contacts.py @@ -39,7 +39,7 @@ class GetContacts(BaseClient): """ while True: try: - contacts = self.send(functions.contacts.GetContacts(0)) + contacts = self.send(functions.contacts.GetContacts(hash=0)) except FloodWait as e: log.warning("get_contacts flood: waiting {} seconds".format(e.x)) time.sleep(e.x) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 9ad2f199..2f82e2ea 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -131,7 +131,9 @@ class EditMessageMedia(BaseClient): w=media.width, h=media.height ), - types.DocumentAttributeFilename(os.path.basename(media.media)) + types.DocumentAttributeFilename( + file_name=os.path.basename(media.media) + ) ] ) ) @@ -187,7 +189,9 @@ class EditMessageMedia(BaseClient): performer=media.performer, title=media.title ), - types.DocumentAttributeFilename(os.path.basename(media.media)) + types.DocumentAttributeFilename( + file_name=os.path.basename(media.media) + ) ] ) ) @@ -244,7 +248,9 @@ class EditMessageMedia(BaseClient): w=media.width, h=media.height ), - types.DocumentAttributeFilename(os.path.basename(media.media)), + types.DocumentAttributeFilename( + file_name=os.path.basename(media.media) + ), types.DocumentAttributeAnimated() ] ) @@ -296,7 +302,9 @@ class EditMessageMedia(BaseClient): thumb=None if media.thumb is None else self.save_file(media.thumb), file=self.save_file(media.media), attributes=[ - types.DocumentAttributeFilename(os.path.basename(media.media)) + types.DocumentAttributeFilename( + file_name=os.path.basename(media.media) + ) ] ) ) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index b1c90d10..40b1b0ee 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -76,7 +76,7 @@ class GetMessages(BaseClient): is_iterable = not isinstance(ids, int) ids = list(ids) if is_iterable else [ids] - ids = [ids_type(i) for i in ids] + ids = [ids_type(id=i) for i in ids] if isinstance(peer, types.InputPeerChannel): rpc = functions.channels.GetMessages(channel=peer, id=ids) diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 8fc31e08..5ac902ed 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -141,7 +141,7 @@ class SendAnimation(BaseClient): w=width, h=height ), - types.DocumentAttributeFilename(os.path.basename(animation)), + types.DocumentAttributeFilename(file_name=os.path.basename(animation)), types.DocumentAttributeAnimated() ] ) diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index a956ba85..a4f5512b 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -142,7 +142,7 @@ class SendAudio(BaseClient): performer=performer, title=title ), - types.DocumentAttributeFilename(os.path.basename(audio)) + types.DocumentAttributeFilename(file_name=os.path.basename(audio)) ] ) elif audio.startswith("http"): diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 35fe8c0e..6dc496e4 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -123,7 +123,7 @@ class SendDocument(BaseClient): file=file, thumb=thumb, attributes=[ - types.DocumentAttributeFilename(os.path.basename(document)) + types.DocumentAttributeFilename(file_name=os.path.basename(document)) ] ) elif document.startswith("http"): diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index b899a938..5fe57904 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -69,9 +69,9 @@ class SendLocation(BaseClient): functions.messages.SendMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaGeoPoint( - types.InputGeoPoint( - latitude, - longitude + geo_point=types.InputGeoPoint( + lat=latitude, + long=longitude ) ), message="", diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index 0df273bc..42e4ddde 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -137,7 +137,7 @@ class SendMediaGroup(BaseClient): w=i.width, h=i.height ), - types.DocumentAttributeFilename(os.path.basename(i.media)) + types.DocumentAttributeFilename(file_name=os.path.basename(i.media)) ] ) ) diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index e41c074e..ba16a2e7 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -103,7 +103,7 @@ class SendSticker(BaseClient): mime_type="image/webp", file=file, attributes=[ - types.DocumentAttributeFilename(os.path.basename(sticker)) + types.DocumentAttributeFilename(file_name=os.path.basename(sticker)) ] ) elif sticker.startswith("http"): diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index b69b2185..0224eaf6 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -145,7 +145,7 @@ class SendVideo(BaseClient): w=width, h=height ), - types.DocumentAttributeFilename(os.path.basename(video)) + types.DocumentAttributeFilename(file_name=os.path.basename(video)) ] ) elif video.startswith("http"): diff --git a/pyrogram/client/methods/password/utils.py b/pyrogram/client/methods/password/utils.py index 24c4dd28..3a29976a 100644 --- a/pyrogram/client/methods/password/utils.py +++ b/pyrogram/client/methods/password/utils.py @@ -101,4 +101,4 @@ def compute_check(r: types.account.Password, password: str) -> types.InputCheckP + K_bytes ) - return types.InputCheckPasswordSRP(srp_id, A_bytes, M1_bytes) + return types.InputCheckPasswordSRP(srp_id=srp_id, A=A_bytes, M1=M1_bytes) diff --git a/pyrogram/client/methods/users/get_me.py b/pyrogram/client/methods/users/get_me.py index beea1243..fdceeaba 100644 --- a/pyrogram/client/methods/users/get_me.py +++ b/pyrogram/client/methods/users/get_me.py @@ -35,7 +35,7 @@ class GetMe(BaseClient): self, self.send( functions.users.GetFullUser( - types.InputPeerSelf() + id=types.InputPeerSelf() ) ).user ) diff --git a/pyrogram/client/methods/users/set_user_profile_photo.py b/pyrogram/client/methods/users/set_user_profile_photo.py index 0863c695..359a0cd0 100644 --- a/pyrogram/client/methods/users/set_user_profile_photo.py +++ b/pyrogram/client/methods/users/set_user_profile_photo.py @@ -43,7 +43,7 @@ class SetUserProfilePhoto(BaseClient): return bool( self.send( functions.photos.UploadProfilePhoto( - self.save_file(photo) + file=self.save_file(photo) ) ) ) diff --git a/pyrogram/client/style/html.py b/pyrogram/client/style/html.py index 9a72a565..040e770b 100644 --- a/pyrogram/client/style/html.py +++ b/pyrogram/client/style/html.py @@ -55,20 +55,20 @@ class HTML: input_user = self.peers_by_id.get(user_id, None) entity = ( - Mention(start, len(body), input_user) - if input_user else MentionInvalid(start, len(body), user_id) + Mention(offset=start, length=len(body), user_id=input_user) + if input_user else MentionInvalid(offset=start, length=len(body), user_id=user_id) ) else: - entity = Url(start, len(body), url) + entity = Url(offset=start, length=len(body), url=url) else: if style == "b" or style == "strong": - entity = Bold(start, len(body)) + entity = Bold(offset=start, length=len(body)) elif style == "i" or style == "em": - entity = Italic(start, len(body)) + entity = Italic(offset=start, length=len(body)) elif style == "code": - entity = Code(start, len(body)) + entity = Code(offset=start, length=len(body)) elif style == "pre": - entity = Pre(start, len(body), "") + entity = Pre(offset=start, length=len(body), language="") else: continue diff --git a/pyrogram/client/style/markdown.py b/pyrogram/client/style/markdown.py index 05a11a25..04ce95c8 100644 --- a/pyrogram/client/style/markdown.py +++ b/pyrogram/client/style/markdown.py @@ -72,24 +72,24 @@ class Markdown: input_user = self.peers_by_id.get(user_id, None) entity = ( - Mention(start, len(text), input_user) + Mention(offset=start, length=len(text), user_id=input_user) if input_user - else MentionInvalid(start, len(text), user_id) + else MentionInvalid(offset=start, length=len(text), user_id=user_id) ) else: - entity = Url(start, len(text), url) + entity = Url(offset=start, length=len(text), url=url) body = text offset += len(url) + 4 else: if style == self.BOLD_DELIMITER: - entity = Bold(start, len(body)) + entity = Bold(offset=start, length=len(body)) elif style == self.ITALIC_DELIMITER: - entity = Italic(start, len(body)) + entity = Italic(offset=start, length=len(body)) elif style == self.CODE_DELIMITER: - entity = Code(start, len(body)) + entity = Code(offset=start, length=len(body)) elif style == self.PRE_DELIMITER: - entity = Pre(start, len(body), "") + entity = Pre(offset=start, length=len(body), language="") else: continue diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index 505b7c87..cca42b33 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -111,16 +111,20 @@ class InlineKeyboardButton(PyrogramType): def write(self): if self.callback_data: - return KeyboardButtonCallback(self.text, self.callback_data) + return KeyboardButtonCallback(text=self.text, data=self.callback_data) if self.url: - return KeyboardButtonUrl(self.text, self.url) + return KeyboardButtonUrl(text=self.text, url=self.url) if self.switch_inline_query: - return KeyboardButtonSwitchInline(self.text, self.switch_inline_query) + return KeyboardButtonSwitchInline(text=self.text, query=self.switch_inline_query) if self.switch_inline_query_current_chat: - return KeyboardButtonSwitchInline(self.text, self.switch_inline_query_current_chat, same_peer=True) + return KeyboardButtonSwitchInline( + text=self.text, + query=self.switch_inline_query_current_chat, + same_peer=True + ) if self.callback_game: - return KeyboardButtonGame(self.text) + return KeyboardButtonGame(text=self.text) diff --git a/pyrogram/client/types/bots/inline_keyboard_markup.py b/pyrogram/client/types/bots/inline_keyboard_markup.py index cb5327b1..77e9cfeb 100644 --- a/pyrogram/client/types/bots/inline_keyboard_markup.py +++ b/pyrogram/client/types/bots/inline_keyboard_markup.py @@ -59,7 +59,7 @@ class InlineKeyboardMarkup(PyrogramType): def write(self): return ReplyInlineMarkup( - [KeyboardButtonRow( - [j.write() for j in i] + rows=[KeyboardButtonRow( + buttons=[j.write() for j in i] ) for i in self.inline_keyboard] ) diff --git a/pyrogram/client/types/bots/keyboard_button.py b/pyrogram/client/types/bots/keyboard_button.py index dc4ed1e7..b8786cee 100644 --- a/pyrogram/client/types/bots/keyboard_button.py +++ b/pyrogram/client/types/bots/keyboard_button.py @@ -75,8 +75,8 @@ class KeyboardButton(PyrogramType): # TODO: Enforce optional args mutual exclusiveness if self.request_contact: - return KeyboardButtonRequestPhone(self.text) + return KeyboardButtonRequestPhone(text=self.text) elif self.request_location: - return KeyboardButtonRequestGeoLocation(self.text) + return KeyboardButtonRequestGeoLocation(text=self.text) else: - return RawKeyboardButton(self.text) + return RawKeyboardButton(text=self.text) diff --git a/pyrogram/client/types/bots/reply_keyboard_markup.py b/pyrogram/client/types/bots/reply_keyboard_markup.py index 229899d0..431a55eb 100644 --- a/pyrogram/client/types/bots/reply_keyboard_markup.py +++ b/pyrogram/client/types/bots/reply_keyboard_markup.py @@ -87,9 +87,11 @@ class ReplyKeyboardMarkup(PyrogramType): def write(self): return RawReplyKeyboardMarkup( rows=[KeyboardButtonRow( - [KeyboardButton(j).write() - if isinstance(j, str) else j.write() - for j in i] + buttons=[ + KeyboardButton(j).write() + if isinstance(j, str) else j.write() + for j in i + ] ) for i in self.keyboard], resize=self.resize_keyboard or None, single_use=self.one_time_keyboard or None, diff --git a/pyrogram/client/types/messages_and_media/sticker.py b/pyrogram/client/types/messages_and_media/sticker.py index 70322577..ce390b1d 100644 --- a/pyrogram/client/types/messages_and_media/sticker.py +++ b/pyrogram/client/types/messages_and_media/sticker.py @@ -103,7 +103,10 @@ class Sticker(PyrogramType): try: return send( functions.messages.GetStickerSet( - types.InputStickerSetID(*input_sticker_set_id) + stickerset=types.InputStickerSetID( + id=input_sticker_set_id[0], + access_hash=input_sticker_set_id[1] + ) ) ).set.short_name except StickersetInvalid: diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 05b20eec..9d8e4b16 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -45,10 +45,10 @@ class Auth: @staticmethod def pack(data: Object) -> bytes: return ( - bytes(8) - + Long(MsgId()) - + Int(len(data.write())) - + data.write() + bytes(8) + + Long(MsgId()) + + Int(len(data.write())) + + data.write() ) @staticmethod @@ -83,7 +83,7 @@ class Auth: # Step 1; Step 2 nonce = int.from_bytes(urandom(16), "little", signed=True) log.debug("Send req_pq: {}".format(nonce)) - res_pq = self.send(functions.ReqPqMulti(nonce)) + res_pq = self.send(functions.ReqPqMulti(nonce=nonce)) log.debug("Got ResPq: {}".format(res_pq.server_nonce)) log.debug("Server public key fingerprints: {}".format(res_pq.server_public_key_fingerprints)) @@ -110,12 +110,12 @@ class Auth: new_nonce = int.from_bytes(urandom(32), "little", signed=True) data = types.PQInnerData( - res_pq.pq, - p.to_bytes(4, "big"), - q.to_bytes(4, "big"), - nonce, - server_nonce, - new_nonce, + pq=res_pq.pq, + p=p.to_bytes(4, "big"), + q=q.to_bytes(4, "big"), + nonce=nonce, + server_nonce=server_nonce, + new_nonce=new_nonce, ).write() sha = sha1(data).digest() @@ -129,12 +129,12 @@ class Auth: log.debug("Send req_DH_params") server_dh_params = self.send( functions.ReqDHParams( - nonce, - server_nonce, - p.to_bytes(4, "big"), - q.to_bytes(4, "big"), - public_key_fingerprint, - encrypted_data + nonce=nonce, + server_nonce=server_nonce, + p=p.to_bytes(4, "big"), + q=q.to_bytes(4, "big"), + public_key_fingerprint=public_key_fingerprint, + encrypted_data=encrypted_data ) ) @@ -144,13 +144,13 @@ class Auth: new_nonce = new_nonce.to_bytes(32, "little", signed=True) tmp_aes_key = ( - sha1(new_nonce + server_nonce).digest() - + sha1(server_nonce + new_nonce).digest()[:12] + sha1(new_nonce + server_nonce).digest() + + sha1(server_nonce + new_nonce).digest()[:12] ) tmp_aes_iv = ( - sha1(server_nonce + new_nonce).digest()[12:] - + sha1(new_nonce + new_nonce).digest() + new_nonce[:4] + sha1(server_nonce + new_nonce).digest()[12:] + + sha1(new_nonce + new_nonce).digest() + new_nonce[:4] ) server_nonce = int.from_bytes(server_nonce, "little", signed=True) @@ -175,10 +175,10 @@ class Auth: retry_id = 0 data = types.ClientDHInnerData( - nonce, - server_nonce, - retry_id, - g_b + nonce=nonce, + server_nonce=server_nonce, + retry_id=retry_id, + g_b=g_b ).write() sha = sha1(data).digest() @@ -189,9 +189,9 @@ class Auth: log.debug("Send set_client_DH_params") set_client_dh_params_answer = self.send( functions.SetClientDHParams( - nonce, - server_nonce, - encrypted_data + nonce=nonce, + server_nonce=server_nonce, + encrypted_data=encrypted_data ) ) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 5392728f..4ebdf4fc 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -134,11 +134,11 @@ class Session: self.current_salt = FutureSalt( 0, 0, self._send( - functions.Ping(0), + functions.Ping(ping_id=0), timeout=self.START_TIMEOUT ).new_server_salt ) - self.current_salt = self._send(functions.GetFutureSalts(1), timeout=self.START_TIMEOUT).salts[0] + self.current_salt = self._send(functions.GetFutureSalts(num=1), timeout=self.START_TIMEOUT).salts[0] self.next_salt_thread = Thread(target=self.next_salt, name="NextSaltThread") self.next_salt_thread.start() @@ -146,8 +146,8 @@ class Session: if not self.is_cdn: self._send( functions.InvokeWithLayer( - layer, - functions.InitConnection( + layer=layer, + query=functions.InitConnection( api_id=self.client.api_id, app_version=self.client.app_version, device_model=self.client.device_model, @@ -314,7 +314,7 @@ class Session: log.info("Send {} acks".format(len(self.pending_acks))) try: - self._send(types.MsgsAck(list(self.pending_acks)), False) + self._send(types.MsgsAck(msg_ids=list(self.pending_acks)), False) except (OSError, TimeoutError): pass else: @@ -335,7 +335,7 @@ class Session: try: self._send(functions.PingDelayDisconnect( - 0, self.WAIT_TIMEOUT + 10 + ping_id=0, disconnect_delay=self.WAIT_TIMEOUT + 10 ), False) except (OSError, TimeoutError, Error): pass @@ -365,7 +365,7 @@ class Session: break try: - self.current_salt = self._send(functions.GetFutureSalts(1)).salts[0] + self.current_salt = self._send(functions.GetFutureSalts(num=1)).salts[0] except (OSError, TimeoutError, Error): self.connection.close() break