From 78efb04b404047cdd6a196f891324d5c779a383c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH] Rename Client.send to Client.invoke --- pyrogram/client.py | 18 +++++------ pyrogram/methods/advanced/__init__.py | 6 ++-- .../methods/advanced/{send.py => invoke.py} | 18 +++++------ pyrogram/methods/advanced/resolve_peer.py | 8 ++--- pyrogram/methods/advanced/save_file.py | 2 +- .../methods/auth/accept_terms_of_service.py | 2 +- pyrogram/methods/auth/check_password.py | 4 +-- pyrogram/methods/auth/get_password_hint.py | 2 +- pyrogram/methods/auth/log_out.py | 2 +- pyrogram/methods/auth/recover_password.py | 2 +- pyrogram/methods/auth/resend_code.py | 2 +- pyrogram/methods/auth/send_code.py | 2 +- pyrogram/methods/auth/send_recovery_code.py | 2 +- pyrogram/methods/auth/sign_in.py | 2 +- pyrogram/methods/auth/sign_in_bot.py | 2 +- pyrogram/methods/auth/sign_up.py | 2 +- pyrogram/methods/auth/terminate.py | 2 +- .../methods/bots/answer_callback_query.py | 2 +- pyrogram/methods/bots/answer_inline_query.py | 2 +- pyrogram/methods/bots/get_game_high_scores.py | 2 +- .../methods/bots/get_inline_bot_results.py | 2 +- .../methods/bots/request_callback_answer.py | 2 +- pyrogram/methods/bots/send_game.py | 2 +- .../methods/bots/send_inline_bot_result.py | 2 +- pyrogram/methods/bots/set_bot_commands.py | 2 +- pyrogram/methods/bots/set_game_score.py | 2 +- pyrogram/methods/chats/add_chat_members.py | 4 +-- pyrogram/methods/chats/archive_chats.py | 2 +- pyrogram/methods/chats/ban_chat_member.py | 4 +-- pyrogram/methods/chats/create_channel.py | 2 +- pyrogram/methods/chats/create_group.py | 2 +- pyrogram/methods/chats/create_supergroup.py | 2 +- pyrogram/methods/chats/delete_channel.py | 2 +- pyrogram/methods/chats/delete_chat_photo.py | 4 +-- pyrogram/methods/chats/delete_supergroup.py | 2 +- pyrogram/methods/chats/delete_user_history.py | 2 +- pyrogram/methods/chats/get_chat.py | 8 ++--- pyrogram/methods/chats/get_chat_event_log.py | 2 +- pyrogram/methods/chats/get_chat_member.py | 4 +-- pyrogram/methods/chats/get_chat_members.py | 4 +-- .../methods/chats/get_chat_members_count.py | 4 +-- .../methods/chats/get_chat_online_count.py | 2 +- pyrogram/methods/chats/get_dialogs.py | 4 +-- pyrogram/methods/chats/get_dialogs_count.py | 4 +-- pyrogram/methods/chats/get_nearby_chats.py | 2 +- pyrogram/methods/chats/get_send_as_chats.py | 2 +- pyrogram/methods/chats/iter_dialogs.py | 2 +- pyrogram/methods/chats/join_chat.py | 4 +-- pyrogram/methods/chats/leave_chat.py | 6 ++-- pyrogram/methods/chats/mark_chat_unread.py | 6 ++-- pyrogram/methods/chats/pin_chat_message.py | 2 +- pyrogram/methods/chats/promote_chat_member.py | 4 +-- .../methods/chats/restrict_chat_member.py | 2 +- .../methods/chats/set_administrator_title.py | 4 +-- .../methods/chats/set_chat_description.py | 2 +- .../methods/chats/set_chat_permissions.py | 2 +- pyrogram/methods/chats/set_chat_photo.py | 4 +-- .../chats/set_chat_protected_content.py | 6 ++-- pyrogram/methods/chats/set_chat_title.py | 4 +-- pyrogram/methods/chats/set_chat_username.py | 2 +- pyrogram/methods/chats/set_send_as_chat.py | 2 +- pyrogram/methods/chats/set_slow_mode.py | 2 +- pyrogram/methods/chats/unarchive_chats.py | 2 +- pyrogram/methods/chats/unban_chat_member.py | 2 +- .../methods/chats/unpin_all_chat_messages.py | 2 +- pyrogram/methods/chats/unpin_chat_message.py | 2 +- pyrogram/methods/contacts/add_contact.py | 2 +- pyrogram/methods/contacts/delete_contacts.py | 2 +- pyrogram/methods/contacts/get_contacts.py | 2 +- .../methods/contacts/get_contacts_count.py | 2 +- pyrogram/methods/contacts/import_contacts.py | 2 +- .../invite_links/approve_chat_join_request.py | 2 +- .../invite_links/create_chat_invite_link.py | 2 +- .../invite_links/decline_chat_join_request.py | 2 +- .../delete_chat_admin_invite_links.py | 2 +- .../invite_links/delete_chat_invite_link.py | 2 +- .../invite_links/edit_chat_invite_link.py | 2 +- .../invite_links/export_chat_invite_link.py | 2 +- .../get_chat_admin_invite_links.py | 2 +- .../get_chat_admin_invite_links_count.py | 2 +- .../get_chat_admins_with_invite_links.py | 2 +- .../invite_links/get_chat_invite_link.py | 2 +- .../get_chat_invite_link_members.py | 2 +- .../get_chat_invite_link_members_count.py | 2 +- .../invite_links/revoke_chat_invite_link.py | 2 +- pyrogram/methods/messages/copy_media_group.py | 2 +- pyrogram/methods/messages/delete_messages.py | 4 +-- .../methods/messages/edit_inline_media.py | 2 +- .../messages/edit_inline_reply_markup.py | 2 +- pyrogram/methods/messages/edit_inline_text.py | 2 +- .../methods/messages/edit_message_media.py | 12 +++---- .../messages/edit_message_reply_markup.py | 2 +- .../methods/messages/edit_message_text.py | 2 +- pyrogram/methods/messages/forward_messages.py | 2 +- .../messages/get_discussion_message.py | 2 +- pyrogram/methods/messages/get_history.py | 2 +- .../methods/messages/get_history_count.py | 2 +- pyrogram/methods/messages/get_messages.py | 2 +- pyrogram/methods/messages/inline_session.py | 4 +-- pyrogram/methods/messages/read_history.py | 2 +- pyrogram/methods/messages/retract_vote.py | 2 +- pyrogram/methods/messages/search_global.py | 2 +- .../methods/messages/search_global_count.py | 2 +- pyrogram/methods/messages/search_messages.py | 2 +- .../methods/messages/search_messages_count.py | 2 +- pyrogram/methods/messages/send_animation.py | 4 +-- pyrogram/methods/messages/send_audio.py | 2 +- .../methods/messages/send_cached_media.py | 2 +- pyrogram/methods/messages/send_chat_action.py | 2 +- pyrogram/methods/messages/send_contact.py | 2 +- pyrogram/methods/messages/send_dice.py | 2 +- pyrogram/methods/messages/send_document.py | 2 +- pyrogram/methods/messages/send_location.py | 2 +- pyrogram/methods/messages/send_media_group.py | 26 +++++++-------- pyrogram/methods/messages/send_message.py | 2 +- pyrogram/methods/messages/send_photo.py | 2 +- pyrogram/methods/messages/send_poll.py | 2 +- pyrogram/methods/messages/send_reaction.py | 2 +- pyrogram/methods/messages/send_sticker.py | 2 +- pyrogram/methods/messages/send_venue.py | 2 +- pyrogram/methods/messages/send_video.py | 2 +- pyrogram/methods/messages/send_video_note.py | 2 +- pyrogram/methods/messages/send_voice.py | 2 +- pyrogram/methods/messages/stop_poll.py | 2 +- pyrogram/methods/messages/vote_poll.py | 2 +- .../methods/password/change_cloud_password.py | 4 +-- .../methods/password/enable_cloud_password.py | 4 +-- .../methods/password/remove_cloud_password.py | 4 +-- pyrogram/methods/users/block_user.py | 2 +- .../methods/users/delete_profile_photos.py | 2 +- pyrogram/methods/users/get_common_chats.py | 2 +- pyrogram/methods/users/get_me.py | 2 +- pyrogram/methods/users/get_profile_photos.py | 6 ++-- .../methods/users/get_profile_photos_count.py | 4 +-- pyrogram/methods/users/get_users.py | 2 +- pyrogram/methods/users/set_profile_photo.py | 2 +- pyrogram/methods/users/set_username.py | 2 +- pyrogram/methods/users/unblock_user.py | 2 +- pyrogram/methods/users/update_profile.py | 2 +- pyrogram/methods/utilities/start.py | 4 +-- pyrogram/session/auth.py | 8 ++--- pyrogram/session/session.py | 32 +++++++++---------- pyrogram/types/messages_and_media/message.py | 2 +- pyrogram/types/messages_and_media/sticker.py | 6 ++-- 144 files changed, 234 insertions(+), 236 deletions(-) rename pyrogram/methods/advanced/{send.py => invoke.py} (87%) diff --git a/pyrogram/client.py b/pyrogram/client.py index cfef3a8d..920b7233 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -567,7 +567,7 @@ class Client(Methods): if not isinstance(message, raw.types.MessageEmpty): try: - diff = await self.send( + diff = await self.invoke( raw.functions.updates.GetChannelDifference( channel=await self.resolve_peer(utils.get_channel_id(channel_id)), filter=raw.types.ChannelMessagesFilter( @@ -589,7 +589,7 @@ class Client(Methods): self.dispatcher.updates_queue.put_nowait((update, users, chats)) elif isinstance(updates, (raw.types.UpdateShortMessage, raw.types.UpdateShortChatMessage)): - diff = await self.send( + diff = await self.invoke( raw.functions.updates.GetDifference( pts=updates.pts - updates.pts_count, date=updates.date, @@ -847,14 +847,14 @@ class Client(Methods): await session.start() for _ in range(3): - exported_auth = await self.send( + exported_auth = await self.invoke( raw.functions.auth.ExportAuthorization( dc_id=dc_id ) ) try: - await session.send( + await session.invoke( raw.functions.auth.ImportAuthorization( id=exported_auth.id, bytes=exported_auth.bytes @@ -920,7 +920,7 @@ class Client(Methods): file_name = "" try: - r = await session.send( + r = await session.invoke( raw.functions.upload.GetFile( location=location, offset=offset, @@ -958,7 +958,7 @@ class Client(Methods): if len(chunk) < limit: break - r = await session.send( + r = await session.invoke( raw.functions.upload.GetFile( location=location, offset=offset, @@ -986,7 +986,7 @@ class Client(Methods): file_name = f.name while True: - r2 = await cdn_session.send( + r2 = await cdn_session.invoke( raw.functions.upload.GetCdnFile( file_token=r.file_token, offset=offset, @@ -996,7 +996,7 @@ class Client(Methods): if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded): try: - await session.send( + await session.invoke( raw.functions.upload.ReuploadCdnFile( file_token=r.file_token, request_token=r2.request_token @@ -1019,7 +1019,7 @@ class Client(Methods): ) ) - hashes = await session.send( + hashes = await session.invoke( raw.functions.upload.GetCdnFileHashes( file_token=r.file_token, offset=offset diff --git a/pyrogram/methods/advanced/__init__.py b/pyrogram/methods/advanced/__init__.py index a3cf461a..bf19658a 100644 --- a/pyrogram/methods/advanced/__init__.py +++ b/pyrogram/methods/advanced/__init__.py @@ -16,14 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .invoke import Invoke from .resolve_peer import ResolvePeer from .save_file import SaveFile -from .send import Send class Advanced( + Invoke, ResolvePeer, - SaveFile, - Send + SaveFile ): pass diff --git a/pyrogram/methods/advanced/send.py b/pyrogram/methods/advanced/invoke.py similarity index 87% rename from pyrogram/methods/advanced/send.py rename to pyrogram/methods/advanced/invoke.py index 6e5551cd..9ae25d00 100644 --- a/pyrogram/methods/advanced/send.py +++ b/pyrogram/methods/advanced/invoke.py @@ -26,15 +26,15 @@ from pyrogram.session import Session log = logging.getLogger(__name__) -class Send: - async def send( +class Invoke: + async def invoke( self: "pyrogram.Client", - data: TLObject, + query: TLObject, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT, sleep_threshold: float = None ): - """Send raw Telegram queries. + """Invoke raw Telegram functions. This method makes it possible to manually call every single Telegram API method in a low-level manner. Available functions are listed in the :obj:`functions ` package and may accept compound @@ -47,7 +47,7 @@ class Send: available yet in the Client class as an easy-to-use method). Parameters: - data (``RawFunction``): + query (``RawFunction``): The API Schema function filled with proper arguments. retries (``int``): @@ -69,13 +69,13 @@ class Send: raise ConnectionError("Client has not been started yet") if self.no_updates: - data = raw.functions.InvokeWithoutUpdates(query=data) + query = raw.functions.InvokeWithoutUpdates(query=query) if self.takeout_id: - data = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=data) + query = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=query) - r = await self.session.send( - data, retries, timeout, + r = await self.session.invoke( + query, retries, timeout, (sleep_threshold if sleep_threshold is not None else self.sleep_threshold) diff --git a/pyrogram/methods/advanced/resolve_peer.py b/pyrogram/methods/advanced/resolve_peer.py index db4def9a..80fe7975 100644 --- a/pyrogram/methods/advanced/resolve_peer.py +++ b/pyrogram/methods/advanced/resolve_peer.py @@ -71,7 +71,7 @@ class ResolvePeer: try: return await self.storage.get_peer_by_username(peer_id) except KeyError: - await self.send( + await self.invoke( raw.functions.contacts.ResolveUsername( username=peer_id ) @@ -88,7 +88,7 @@ class ResolvePeer: if peer_type == "user": await self.fetch_peers( - await self.send( + await self.invoke( raw.functions.users.GetUsers( id=[ raw.types.InputUser( @@ -100,13 +100,13 @@ class ResolvePeer: ) ) elif peer_type == "chat": - await self.send( + await self.invoke( raw.functions.messages.GetChats( id=[-peer_id] ) ) else: - await self.send( + await self.invoke( raw.functions.channels.GetChannels( id=[ raw.types.InputChannel( diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index 9c92651d..706f28e0 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -103,7 +103,7 @@ class SaveFile: return try: - await session.send(data) + await session.invoke(data) except Exception as e: log.error(e) diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py index ea041d6c..3bc5fbad 100644 --- a/pyrogram/methods/auth/accept_terms_of_service.py +++ b/pyrogram/methods/auth/accept_terms_of_service.py @@ -31,7 +31,7 @@ class AcceptTermsOfService: terms_of_service_id (``str``): The terms of service identifier. """ - r = await self.send( + r = await self.invoke( raw.functions.help.AcceptTermsOfService( id=raw.types.DataJSON( data=terms_of_service_id diff --git a/pyrogram/methods/auth/check_password.py b/pyrogram/methods/auth/check_password.py index 1f1d142c..9d8b08ab 100644 --- a/pyrogram/methods/auth/check_password.py +++ b/pyrogram/methods/auth/check_password.py @@ -43,10 +43,10 @@ class CheckPassword: Raises: BadRequest: In case the password is invalid. """ - r = await self.send( + r = await self.invoke( raw.functions.auth.CheckPassword( password=compute_password_check( - await self.send(raw.functions.account.GetPassword()), + await self.invoke(raw.functions.account.GetPassword()), password ) ) diff --git a/pyrogram/methods/auth/get_password_hint.py b/pyrogram/methods/auth/get_password_hint.py index d9002106..af655758 100644 --- a/pyrogram/methods/auth/get_password_hint.py +++ b/pyrogram/methods/auth/get_password_hint.py @@ -33,4 +33,4 @@ class GetPasswordHint: Returns: ``str``: On success, the password hint as string is returned. """ - return (await self.send(raw.functions.account.GetPassword())).hint + return (await self.invoke(raw.functions.account.GetPassword())).hint diff --git a/pyrogram/methods/auth/log_out.py b/pyrogram/methods/auth/log_out.py index 2f8ad019..b4a29f82 100644 --- a/pyrogram/methods/auth/log_out.py +++ b/pyrogram/methods/auth/log_out.py @@ -42,7 +42,7 @@ class LogOut: # Log out. app.log_out() """ - await self.send(raw.functions.auth.LogOut()) + await self.invoke(raw.functions.auth.LogOut()) await self.stop() await self.storage.delete() diff --git a/pyrogram/methods/auth/recover_password.py b/pyrogram/methods/auth/recover_password.py index 600ac86a..9f75a93f 100644 --- a/pyrogram/methods/auth/recover_password.py +++ b/pyrogram/methods/auth/recover_password.py @@ -43,7 +43,7 @@ class RecoverPassword: Raises: BadRequest: In case the recovery code is invalid. """ - r = await self.send( + r = await self.invoke( raw.functions.auth.RecoverPassword( code=recovery_code ) diff --git a/pyrogram/methods/auth/resend_code.py b/pyrogram/methods/auth/resend_code.py index d17cc395..4210e04d 100644 --- a/pyrogram/methods/auth/resend_code.py +++ b/pyrogram/methods/auth/resend_code.py @@ -52,7 +52,7 @@ class ResendCode: """ phone_number = phone_number.strip(" +") - r = await self.send( + r = await self.invoke( raw.functions.auth.ResendCode( phone_number=phone_number, phone_code_hash=phone_code_hash diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py index 3d42fa6b..5a4f87ea 100644 --- a/pyrogram/methods/auth/send_code.py +++ b/pyrogram/methods/auth/send_code.py @@ -49,7 +49,7 @@ class SendCode: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.auth.SendCode( phone_number=phone_number, api_id=self.api_id, diff --git a/pyrogram/methods/auth/send_recovery_code.py b/pyrogram/methods/auth/send_recovery_code.py index 40d2b7dd..d1f23bf9 100644 --- a/pyrogram/methods/auth/send_recovery_code.py +++ b/pyrogram/methods/auth/send_recovery_code.py @@ -36,6 +36,6 @@ class SendRecoveryCode: Raises: BadRequest: In case no recovery email was set up. """ - return (await self.send( + return (await self.invoke( raw.functions.auth.RequestPasswordRecovery() )).email_pattern diff --git a/pyrogram/methods/auth/sign_in.py b/pyrogram/methods/auth/sign_in.py index d8079c95..c328c958 100644 --- a/pyrogram/methods/auth/sign_in.py +++ b/pyrogram/methods/auth/sign_in.py @@ -58,7 +58,7 @@ class SignIn: """ phone_number = phone_number.strip(" +") - r = await self.send( + r = await self.invoke( raw.functions.auth.SignIn( phone_number=phone_number, phone_code_hash=phone_code_hash, diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py index db4515a4..5f2e68b5 100644 --- a/pyrogram/methods/auth/sign_in_bot.py +++ b/pyrogram/methods/auth/sign_in_bot.py @@ -46,7 +46,7 @@ class SignInBot: """ while True: try: - r = await self.send( + r = await self.invoke( raw.functions.auth.ImportBotAuthorization( flags=0, api_id=self.api_id, diff --git a/pyrogram/methods/auth/sign_up.py b/pyrogram/methods/auth/sign_up.py index 4e769ab1..6700fee4 100644 --- a/pyrogram/methods/auth/sign_up.py +++ b/pyrogram/methods/auth/sign_up.py @@ -56,7 +56,7 @@ class SignUp: """ phone_number = phone_number.strip(" +") - r = await self.send( + r = await self.invoke( raw.functions.auth.SignUp( phone_number=phone_number, first_name=first_name, diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index d8cca6ba..548d030c 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -41,7 +41,7 @@ class Terminate: raise ConnectionError("Client is already terminated") if self.takeout_id: - await self.send(raw.functions.account.FinishTakeoutSession()) + await self.invoke(raw.functions.account.FinishTakeoutSession()) log.warning(f"Takeout session {self.takeout_id} finished") await Syncer.remove(self) diff --git a/pyrogram/methods/bots/answer_callback_query.py b/pyrogram/methods/bots/answer_callback_query.py index 73d5ce55..af2c8f72 100644 --- a/pyrogram/methods/bots/answer_callback_query.py +++ b/pyrogram/methods/bots/answer_callback_query.py @@ -68,7 +68,7 @@ class AnswerCallbackQuery: # Answer with alert app.answer_callback_query(query_id, text=text, show_alert=True) """ - return await self.send( + return await self.invoke( raw.functions.messages.SetBotCallbackAnswer( query_id=int(callback_query_id), cache_time=cache_time, diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py index 1751171d..ebdfab23 100644 --- a/pyrogram/methods/bots/answer_inline_query.py +++ b/pyrogram/methods/bots/answer_inline_query.py @@ -94,7 +94,7 @@ class AnswerInlineQuery: InputTextMessageContent("Message content"))]) """ - return await self.send( + return await self.invoke( raw.functions.messages.SetInlineBotResults( query_id=int(inline_query_id), results=[await r.write(self) for r in results], diff --git a/pyrogram/methods/bots/get_game_high_scores.py b/pyrogram/methods/bots/get_game_high_scores.py index e4a2ed15..312cc632 100644 --- a/pyrogram/methods/bots/get_game_high_scores.py +++ b/pyrogram/methods/bots/get_game_high_scores.py @@ -59,7 +59,7 @@ class GetGameHighScores: """ # TODO: inline_message_id - r = await self.send( + r = await self.invoke( raw.functions.messages.GetGameHighScores( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py index 2c41fec7..a71fbad8 100644 --- a/pyrogram/methods/bots/get_inline_bot_results.py +++ b/pyrogram/methods/bots/get_inline_bot_results.py @@ -70,7 +70,7 @@ class GetInlineBotResults: # TODO: Don't return the raw type try: - return await self.send( + return await self.invoke( raw.functions.messages.GetInlineBotResults( bot=await self.resolve_peer(bot), peer=raw.types.InputPeerSelf(), diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py index ff6ae0d3..908c8eca 100644 --- a/pyrogram/methods/bots/request_callback_answer.py +++ b/pyrogram/methods/bots/request_callback_answer.py @@ -64,7 +64,7 @@ class RequestCallbackAnswer: # Telegram only wants bytes, but we are allowed to pass strings too. data = bytes(callback_data, "utf-8") if isinstance(callback_data, str) else callback_data - return await self.send( + return await self.invoke( raw.functions.messages.GetBotCallbackAnswer( peer=await self.resolve_peer(chat_id), msg_id=message_id, diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py index 7f9e856b..c8eee66e 100644 --- a/pyrogram/methods/bots/send_game.py +++ b/pyrogram/methods/bots/send_game.py @@ -71,7 +71,7 @@ class SendGame: app.send_game(chat_id, "gamename") """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaGame( diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py index 299aaaf6..00b42043 100644 --- a/pyrogram/methods/bots/send_inline_bot_result.py +++ b/pyrogram/methods/bots/send_inline_bot_result.py @@ -61,7 +61,7 @@ class SendInlineBotResult: app.send_inline_bot_result(chat_id, query_id, result_id) """ - return await self.send( + return await self.invoke( raw.functions.messages.SendInlineBotResult( peer=await self.resolve_peer(chat_id), query_id=query_id, diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py index 8c9baa2e..6df1a2e4 100644 --- a/pyrogram/methods/bots/set_bot_commands.py +++ b/pyrogram/methods/bots/set_bot_commands.py @@ -62,7 +62,7 @@ class SetBotCommands: BotCommand("settings", "Bot settings")]) """ - return await self.send( + return await self.invoke( raw.functions.bots.SetBotCommands( commands=[c.write() for c in commands], scope=await scope.write(self), diff --git a/pyrogram/methods/bots/set_game_score.py b/pyrogram/methods/bots/set_game_score.py index ef644b60..855e4a2e 100644 --- a/pyrogram/methods/bots/set_game_score.py +++ b/pyrogram/methods/bots/set_game_score.py @@ -75,7 +75,7 @@ class SetGameScore: # Force set new score app.set_game_score(user_id, 25, force=True) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SetGameScore( peer=await self.resolve_peer(chat_id), score=score, diff --git a/pyrogram/methods/chats/add_chat_members.py b/pyrogram/methods/chats/add_chat_members.py index cda789aa..2d053c4e 100644 --- a/pyrogram/methods/chats/add_chat_members.py +++ b/pyrogram/methods/chats/add_chat_members.py @@ -67,7 +67,7 @@ class AddChatMembers: if isinstance(peer, raw.types.InputPeerChat): for user_id in user_ids: - await self.send( + await self.invoke( raw.functions.messages.AddChatUser( chat_id=peer.chat_id, user_id=await self.resolve_peer(user_id), @@ -75,7 +75,7 @@ class AddChatMembers: ) ) else: - await self.send( + await self.invoke( raw.functions.channels.InviteToChannel( channel=peer, users=[ diff --git a/pyrogram/methods/chats/archive_chats.py b/pyrogram/methods/chats/archive_chats.py index aa5b50d5..cba27371 100644 --- a/pyrogram/methods/chats/archive_chats.py +++ b/pyrogram/methods/chats/archive_chats.py @@ -60,7 +60,7 @@ class ArchiveChats: ) ) - await self.send( + await self.invoke( raw.functions.folders.EditPeerFolders( folder_peers=folder_peers ) diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py index c01b7046..d8a207ab 100644 --- a/pyrogram/methods/chats/ban_chat_member.py +++ b/pyrogram/methods/chats/ban_chat_member.py @@ -73,7 +73,7 @@ class BanChatMember: user_peer = await self.resolve_peer(user_id) if isinstance(chat_peer, raw.types.InputPeerChannel): - r = await self.send( + r = await self.invoke( raw.functions.channels.EditBanned( channel=chat_peer, participant=user_peer, @@ -91,7 +91,7 @@ class BanChatMember: ) ) else: - r = await self.send( + r = await self.invoke( raw.functions.messages.DeleteChatUser( chat_id=abs(chat_id), user_id=user_peer diff --git a/pyrogram/methods/chats/create_channel.py b/pyrogram/methods/chats/create_channel.py index 5920d5ff..1b054b6e 100644 --- a/pyrogram/methods/chats/create_channel.py +++ b/pyrogram/methods/chats/create_channel.py @@ -43,7 +43,7 @@ class CreateChannel: app.create_channel("Channel Title", "Channel Description") """ - r = await self.send( + r = await self.invoke( raw.functions.channels.CreateChannel( title=title, about=description, diff --git a/pyrogram/methods/chats/create_group.py b/pyrogram/methods/chats/create_group.py index d01a2e68..78240f9f 100644 --- a/pyrogram/methods/chats/create_group.py +++ b/pyrogram/methods/chats/create_group.py @@ -55,7 +55,7 @@ class CreateGroup: if not isinstance(users, list): users = [users] - r = await self.send( + r = await self.invoke( raw.functions.messages.CreateChat( title=title, users=[await self.resolve_peer(u) for u in users] diff --git a/pyrogram/methods/chats/create_supergroup.py b/pyrogram/methods/chats/create_supergroup.py index 348fc726..eb922c32 100644 --- a/pyrogram/methods/chats/create_supergroup.py +++ b/pyrogram/methods/chats/create_supergroup.py @@ -47,7 +47,7 @@ class CreateSupergroup: app.create_supergroup("Supergroup Title", "Supergroup Description") """ - r = await self.send( + r = await self.invoke( raw.functions.channels.CreateChannel( title=title, about=description, diff --git a/pyrogram/methods/chats/delete_channel.py b/pyrogram/methods/chats/delete_channel.py index 246c930a..210c81f1 100644 --- a/pyrogram/methods/chats/delete_channel.py +++ b/pyrogram/methods/chats/delete_channel.py @@ -41,7 +41,7 @@ class DeleteChannel: app.delete_channel(channel_id) """ - await self.send( + await self.invoke( raw.functions.channels.DeleteChannel( channel=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/chats/delete_chat_photo.py b/pyrogram/methods/chats/delete_chat_photo.py index 0b4d6488..ac485603 100644 --- a/pyrogram/methods/chats/delete_chat_photo.py +++ b/pyrogram/methods/chats/delete_chat_photo.py @@ -49,14 +49,14 @@ class DeleteChatPhoto: peer = await self.resolve_peer(chat_id) if isinstance(peer, raw.types.InputPeerChat): - await self.send( + await self.invoke( raw.functions.messages.EditChatPhoto( chat_id=peer.chat_id, photo=raw.types.InputChatPhotoEmpty() ) ) elif isinstance(peer, raw.types.InputPeerChannel): - await self.send( + await self.invoke( raw.functions.channels.EditPhoto( channel=peer, photo=raw.types.InputChatPhotoEmpty() diff --git a/pyrogram/methods/chats/delete_supergroup.py b/pyrogram/methods/chats/delete_supergroup.py index 5f6e8168..8fb069ff 100644 --- a/pyrogram/methods/chats/delete_supergroup.py +++ b/pyrogram/methods/chats/delete_supergroup.py @@ -41,7 +41,7 @@ class DeleteSupergroup: app.delete_supergroup(supergroup_id) """ - await self.send( + await self.invoke( raw.functions.channels.DeleteChannel( channel=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/chats/delete_user_history.py b/pyrogram/methods/chats/delete_user_history.py index 867100bb..4411ddbd 100644 --- a/pyrogram/methods/chats/delete_user_history.py +++ b/pyrogram/methods/chats/delete_user_history.py @@ -41,7 +41,7 @@ class DeleteUserHistory: ``bool``: True on success, False otherwise. """ - r = await self.send( + r = await self.invoke( raw.functions.channels.DeleteParticipantHistory( channel=await self.resolve_peer(chat_id), participant=await self.resolve_peer(user_id) diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py index 99e57566..fc198019 100644 --- a/pyrogram/methods/chats/get_chat.py +++ b/pyrogram/methods/chats/get_chat.py @@ -56,7 +56,7 @@ class GetChat: match = self.INVITE_LINK_RE.match(str(chat_id)) if match: - r = await self.send( + r = await self.invoke( raw.functions.messages.CheckChatInvite( hash=match.group(1) ) @@ -76,10 +76,10 @@ class GetChat: peer = await self.resolve_peer(chat_id) if isinstance(peer, raw.types.InputPeerChannel): - r = await self.send(raw.functions.channels.GetFullChannel(channel=peer)) + r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer)) elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)): - r = await self.send(raw.functions.users.GetFullUser(id=peer)) + r = await self.invoke(raw.functions.users.GetFullUser(id=peer)) else: - r = await self.send(raw.functions.messages.GetFullChat(chat_id=peer.chat_id)) + r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id)) return await types.Chat._parse_full(self, r) diff --git a/pyrogram/methods/chats/get_chat_event_log.py b/pyrogram/methods/chats/get_chat_event_log.py index db277090..2325bad9 100644 --- a/pyrogram/methods/chats/get_chat_event_log.py +++ b/pyrogram/methods/chats/get_chat_event_log.py @@ -70,7 +70,7 @@ class GetChatEventLog: limit = min(100, total) while True: - r: raw.base.channels.AdminLogResults = await self.send( + r: raw.base.channels.AdminLogResults = await self.invoke( raw.functions.channels.GetAdminLog( channel=await self.resolve_peer(chat_id), q=query, diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py index 9717d019..1b24d213 100644 --- a/pyrogram/methods/chats/get_chat_member.py +++ b/pyrogram/methods/chats/get_chat_member.py @@ -54,7 +54,7 @@ class GetChatMember: user = await self.resolve_peer(user_id) if isinstance(chat, raw.types.InputPeerChat): - r = await self.send( + r = await self.invoke( raw.functions.messages.GetFullChat( chat_id=chat.chat_id ) @@ -75,7 +75,7 @@ class GetChatMember: else: raise UserNotParticipant elif isinstance(chat, raw.types.InputPeerChannel): - r = await self.send( + r = await self.invoke( raw.functions.channels.GetParticipant( channel=chat, participant=user diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py index 7e6b8898..a192c3e3 100644 --- a/pyrogram/methods/chats/get_chat_members.py +++ b/pyrogram/methods/chats/get_chat_members.py @@ -92,7 +92,7 @@ class GetChatMembers: peer = await self.resolve_peer(chat_id) if isinstance(peer, raw.types.InputPeerChat): - r = await self.send( + r = await self.invoke( raw.functions.messages.GetFullChat( chat_id=peer.chat_id ) @@ -120,7 +120,7 @@ class GetChatMembers: else: raise ValueError(f'Invalid filter "{filter}"') - r = await self.send( + r = await self.invoke( raw.functions.channels.GetParticipants( channel=peer, filter=filter, diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py index a7dae4be..9c57a11e 100644 --- a/pyrogram/methods/chats/get_chat_members_count.py +++ b/pyrogram/methods/chats/get_chat_members_count.py @@ -48,7 +48,7 @@ class GetChatMembersCount: peer = await self.resolve_peer(chat_id) if isinstance(peer, raw.types.InputPeerChat): - r = await self.send( + r = await self.invoke( raw.functions.messages.GetChats( id=[peer.chat_id] ) @@ -56,7 +56,7 @@ class GetChatMembersCount: return r.chats[0].participants_count elif isinstance(peer, raw.types.InputPeerChannel): - r = await self.send( + r = await self.invoke( raw.functions.channels.GetFullChannel( channel=peer ) diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py index 3f8e5d6a..19924542 100644 --- a/pyrogram/methods/chats/get_chat_online_count.py +++ b/pyrogram/methods/chats/get_chat_online_count.py @@ -42,7 +42,7 @@ class GetChatOnlineCount: online = app.get_chat_online_count(chat_id) print(online) """ - return (await self.send( + return (await self.invoke( raw.functions.messages.GetOnlines( peer=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py index 7276c80b..4aaa95ff 100644 --- a/pyrogram/methods/chats/get_dialogs.py +++ b/pyrogram/methods/chats/get_dialogs.py @@ -67,12 +67,12 @@ class GetDialogs: """ if pinned_only: - r = await self.send( + r = await self.invoke( raw.functions.messages.GetPinnedDialogs(folder_id=0), sleep_threshold=60 ) else: - r = await self.send( + r = await self.invoke( raw.functions.messages.GetDialogs( offset_date=utils.datetime_to_timestamp(offset_date), offset_id=0, diff --git a/pyrogram/methods/chats/get_dialogs_count.py b/pyrogram/methods/chats/get_dialogs_count.py index 3f869909..8ca237cf 100644 --- a/pyrogram/methods/chats/get_dialogs_count.py +++ b/pyrogram/methods/chats/get_dialogs_count.py @@ -42,9 +42,9 @@ class GetDialogsCount: """ if pinned_only: - return len((await self.send(raw.functions.messages.GetPinnedDialogs(folder_id=0))).dialogs) + return len((await self.invoke(raw.functions.messages.GetPinnedDialogs(folder_id=0))).dialogs) else: - r = await self.send( + r = await self.invoke( raw.functions.messages.GetDialogs( offset_date=0, offset_id=0, diff --git a/pyrogram/methods/chats/get_nearby_chats.py b/pyrogram/methods/chats/get_nearby_chats.py index 0dff05aa..c7c36cc6 100644 --- a/pyrogram/methods/chats/get_nearby_chats.py +++ b/pyrogram/methods/chats/get_nearby_chats.py @@ -49,7 +49,7 @@ class GetNearbyChats: print(chats) """ - r = await self.send( + r = await self.invoke( raw.functions.contacts.GetLocated( geo_point=raw.types.InputGeoPoint( lat=latitude, diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py index 147da217..2db4d5f0 100644 --- a/pyrogram/methods/chats/get_send_as_chats.py +++ b/pyrogram/methods/chats/get_send_as_chats.py @@ -43,7 +43,7 @@ class GetSendAsChats: chats = app.get_send_as_chats(chat_id) print(chats) """ - r = await self.send( + r = await self.invoke( raw.functions.channels.GetSendAs( peer=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py index 009bdfa8..72a396f7 100644 --- a/pyrogram/methods/chats/iter_dialogs.py +++ b/pyrogram/methods/chats/iter_dialogs.py @@ -57,7 +57,7 @@ class IterDialogs: offset_peer = raw.types.InputPeerEmpty() while True: - r = (await self.send( + r = (await self.invoke( raw.functions.messages.GetDialogs( offset_date=offset_date, offset_id=offset_id, diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py index c1a850af..2534442a 100644 --- a/pyrogram/methods/chats/join_chat.py +++ b/pyrogram/methods/chats/join_chat.py @@ -53,7 +53,7 @@ class JoinChat: match = self.INVITE_LINK_RE.match(str(chat_id)) if match: - chat = await self.send( + chat = await self.invoke( raw.functions.messages.ImportChatInvite( hash=match.group(1) ) @@ -63,7 +63,7 @@ class JoinChat: elif isinstance(chat.chats[0], raw.types.Channel): return types.Chat._parse_channel_chat(self, chat.chats[0]) else: - chat = await self.send( + chat = await self.invoke( raw.functions.channels.JoinChannel( channel=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/chats/leave_chat.py b/pyrogram/methods/chats/leave_chat.py index 56369e1c..7a6eb85d 100644 --- a/pyrogram/methods/chats/leave_chat.py +++ b/pyrogram/methods/chats/leave_chat.py @@ -51,13 +51,13 @@ class LeaveChat: peer = await self.resolve_peer(chat_id) if isinstance(peer, raw.types.InputPeerChannel): - return await self.send( + return await self.invoke( raw.functions.channels.LeaveChannel( channel=await self.resolve_peer(chat_id) ) ) elif isinstance(peer, raw.types.InputPeerChat): - r = await self.send( + r = await self.invoke( raw.functions.messages.DeleteChatUser( chat_id=peer.chat_id, user_id=raw.types.InputUserSelf() @@ -65,7 +65,7 @@ class LeaveChat: ) if delete: - await self.send( + await self.invoke( raw.functions.messages.DeleteHistory( peer=peer, max_id=0 diff --git a/pyrogram/methods/chats/mark_chat_unread.py b/pyrogram/methods/chats/mark_chat_unread.py index 32251e2a..62cb8bee 100644 --- a/pyrogram/methods/chats/mark_chat_unread.py +++ b/pyrogram/methods/chats/mark_chat_unread.py @@ -19,7 +19,7 @@ from typing import Union import pyrogram -from pyrogram.raw import functions +from pyrogram import raw class MarkChatUnread: @@ -37,8 +37,8 @@ class MarkChatUnread: ``bool``: On success, True is returned. """ - return await self.send( - functions.messages.MarkDialogUnread( + return await self.invoke( + raw.functions.messages.MarkDialogUnread( peer=await self.resolve_peer(chat_id), unread=True ) diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py index 9e34e1aa..1f5ac912 100644 --- a/pyrogram/methods/chats/pin_chat_message.py +++ b/pyrogram/methods/chats/pin_chat_message.py @@ -61,7 +61,7 @@ class PinChatMessage: # Pin without notification app.pin_chat_message(chat_id, message_id, disable_notification=True) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.UpdatePinnedMessage( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py index 63a844bb..b64a1799 100644 --- a/pyrogram/methods/chats/promote_chat_member.py +++ b/pyrogram/methods/chats/promote_chat_member.py @@ -57,7 +57,7 @@ class PromoteChatMember: chat_id = await self.resolve_peer(chat_id) user_id = await self.resolve_peer(user_id) - raw_chat_member = (await self.send( + raw_chat_member = (await self.invoke( raw.functions.channels.GetParticipant( channel=chat_id, participant=user_id @@ -68,7 +68,7 @@ class PromoteChatMember: if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin): rank = raw_chat_member.rank - await self.send( + await self.invoke( raw.functions.channels.EditAdmin( channel=chat_id, user_id=user_id, diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py index a8ab2173..52b264e8 100644 --- a/pyrogram/methods/chats/restrict_chat_member.py +++ b/pyrogram/methods/chats/restrict_chat_member.py @@ -72,7 +72,7 @@ class RestrictChatMember: # Chat member can only send text messages app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True)) """ - r = await self.send( + r = await self.invoke( raw.functions.channels.EditBanned( channel=await self.resolve_peer(chat_id), participant=await self.resolve_peer(user_id), diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py index ed59b342..2ea0dccf 100644 --- a/pyrogram/methods/chats/set_administrator_title.py +++ b/pyrogram/methods/chats/set_administrator_title.py @@ -57,7 +57,7 @@ class SetAdministratorTitle: chat_id = await self.resolve_peer(chat_id) user_id = await self.resolve_peer(user_id) - r = (await self.send( + r = (await self.invoke( raw.functions.channels.GetParticipant( channel=chat_id, participant=user_id @@ -71,7 +71,7 @@ class SetAdministratorTitle: else: raise ValueError("Custom titles can only be applied to owners or administrators of supergroups") - await self.send( + await self.invoke( raw.functions.channels.EditAdmin( channel=chat_id, user_id=user_id, diff --git a/pyrogram/methods/chats/set_chat_description.py b/pyrogram/methods/chats/set_chat_description.py index 440b4050..4a93530b 100644 --- a/pyrogram/methods/chats/set_chat_description.py +++ b/pyrogram/methods/chats/set_chat_description.py @@ -52,7 +52,7 @@ class SetChatDescription: peer = await self.resolve_peer(chat_id) if isinstance(peer, (raw.types.InputPeerChannel, raw.types.InputPeerChat)): - await self.send( + await self.invoke( raw.functions.messages.EditChatAbout( peer=peer, about=description diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py index dfbd5d91..51d74fee 100644 --- a/pyrogram/methods/chats/set_chat_permissions.py +++ b/pyrogram/methods/chats/set_chat_permissions.py @@ -62,7 +62,7 @@ class SetChatPermissions: ) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.EditChatDefaultBannedRights( peer=await self.resolve_peer(chat_id), banned_rights=raw.types.ChatBannedRights( diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py index 1097b237..6da4330b 100644 --- a/pyrogram/methods/chats/set_chat_photo.py +++ b/pyrogram/methods/chats/set_chat_photo.py @@ -100,14 +100,14 @@ class SetChatPhoto: ) if isinstance(peer, raw.types.InputPeerChat): - await self.send( + await self.invoke( raw.functions.messages.EditChatPhoto( chat_id=peer.chat_id, photo=photo, ) ) elif isinstance(peer, raw.types.InputPeerChannel): - await self.send( + await self.invoke( raw.functions.channels.EditPhoto( channel=peer, photo=photo diff --git a/pyrogram/methods/chats/set_chat_protected_content.py b/pyrogram/methods/chats/set_chat_protected_content.py index 1372481c..ee72d722 100644 --- a/pyrogram/methods/chats/set_chat_protected_content.py +++ b/pyrogram/methods/chats/set_chat_protected_content.py @@ -19,7 +19,7 @@ from typing import Union import pyrogram -from pyrogram.raw import functions +from pyrogram import raw class SetChatProtectedContent: @@ -41,8 +41,8 @@ class SetChatProtectedContent: ``bool``: On success, True is returned. """ - await self.send( - functions.messages.ToggleNoForwards( + await self.invoke( + raw.functions.messages.ToggleNoForwards( peer=await self.resolve_peer(chat_id), enabled=enabled ) diff --git a/pyrogram/methods/chats/set_chat_title.py b/pyrogram/methods/chats/set_chat_title.py index ac30b078..edebf176 100644 --- a/pyrogram/methods/chats/set_chat_title.py +++ b/pyrogram/methods/chats/set_chat_title.py @@ -57,14 +57,14 @@ class SetChatTitle: peer = await self.resolve_peer(chat_id) if isinstance(peer, raw.types.InputPeerChat): - await self.send( + await self.invoke( raw.functions.messages.EditChatTitle( chat_id=peer.chat_id, title=title ) ) elif isinstance(peer, raw.types.InputPeerChannel): - await self.send( + await self.invoke( raw.functions.channels.EditTitle( channel=peer, title=title diff --git a/pyrogram/methods/chats/set_chat_username.py b/pyrogram/methods/chats/set_chat_username.py index c63207aa..c1f6d17d 100644 --- a/pyrogram/methods/chats/set_chat_username.py +++ b/pyrogram/methods/chats/set_chat_username.py @@ -55,7 +55,7 @@ class SetChatUsername: if isinstance(peer, raw.types.InputPeerChannel): return bool( - await self.send( + await self.invoke( raw.functions.channels.UpdateUsername( channel=peer, username=username or "" diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py index dabb4066..bbe210a4 100644 --- a/pyrogram/methods/chats/set_send_as_chat.py +++ b/pyrogram/methods/chats/set_send_as_chat.py @@ -47,7 +47,7 @@ class SetSendAsChat: app.set_send_as_chat(chat_id, send_as_chat_id) """ - return await self.send( + return await self.invoke( raw.functions.messages.SaveDefaultSendAs( peer=await self.resolve_peer(chat_id), send_as=await self.resolve_peer(send_as_chat_id) diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py index 3bc00cb2..e3237ad3 100644 --- a/pyrogram/methods/chats/set_slow_mode.py +++ b/pyrogram/methods/chats/set_slow_mode.py @@ -51,7 +51,7 @@ class SetSlowMode: app.set_slow_mode(chat_id, None) """ - await self.send( + await self.invoke( raw.functions.channels.ToggleSlowMode( channel=await self.resolve_peer(chat_id), seconds=seconds or 0 diff --git a/pyrogram/methods/chats/unarchive_chats.py b/pyrogram/methods/chats/unarchive_chats.py index a6b77d18..726eb4a0 100644 --- a/pyrogram/methods/chats/unarchive_chats.py +++ b/pyrogram/methods/chats/unarchive_chats.py @@ -60,7 +60,7 @@ class UnarchiveChats: ) ) - await self.send( + await self.invoke( raw.functions.folders.EditPeerFolders( folder_peers=folder_peers ) diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py index 9176fe33..c331e823 100644 --- a/pyrogram/methods/chats/unban_chat_member.py +++ b/pyrogram/methods/chats/unban_chat_member.py @@ -49,7 +49,7 @@ class UnbanChatMember: # Unban chat member right now app.unban_chat_member(chat_id, user_id) """ - await self.send( + await self.invoke( raw.functions.channels.EditBanned( channel=await self.resolve_peer(chat_id), participant=await self.resolve_peer(user_id), diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py index bd75c40d..93b6eaec 100644 --- a/pyrogram/methods/chats/unpin_all_chat_messages.py +++ b/pyrogram/methods/chats/unpin_all_chat_messages.py @@ -44,7 +44,7 @@ class UnpinAllChatMessages: # Unpin all chat messages app.unpin_all_chat_messages(chat_id) """ - await self.send( + await self.invoke( raw.functions.messages.UnpinAllMessages( peer=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py index cf3f9e9d..6723f5a2 100644 --- a/pyrogram/methods/chats/unpin_chat_message.py +++ b/pyrogram/methods/chats/unpin_chat_message.py @@ -48,7 +48,7 @@ class UnpinChatMessage: app.unpin_chat_message(chat_id, message_id) """ - await self.send( + await self.invoke( raw.functions.messages.UpdatePinnedMessage( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py index 72bdd88a..433c4c90 100644 --- a/pyrogram/methods/contacts/add_contact.py +++ b/pyrogram/methods/contacts/add_contact.py @@ -60,7 +60,7 @@ class AddContact: app.add_contact(12345678, "Foo") app.add_contact("username", "Bar") """ - r = await self.send( + r = await self.invoke( raw.functions.contacts.AddContact( id=await self.resolve_peer(user_id), first_name=first_name, diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py index e6ef3258..03238beb 100644 --- a/pyrogram/methods/contacts/delete_contacts.py +++ b/pyrogram/methods/contacts/delete_contacts.py @@ -50,7 +50,7 @@ class DeleteContacts: if not is_user_ids_list: user_ids = [user_ids] - r = await self.send( + r = await self.invoke( raw.functions.contacts.DeleteContacts( id=[await self.resolve_peer(i) for i in user_ids] ) diff --git a/pyrogram/methods/contacts/get_contacts.py b/pyrogram/methods/contacts/get_contacts.py index 0b41c3d6..ca888876 100644 --- a/pyrogram/methods/contacts/get_contacts.py +++ b/pyrogram/methods/contacts/get_contacts.py @@ -41,5 +41,5 @@ class GetContacts: contacts = app.get_contacts() print(contacts) """ - contacts = await self.send(raw.functions.contacts.GetContacts(hash=0)) + contacts = await self.invoke(raw.functions.contacts.GetContacts(hash=0)) return types.List(types.User._parse(self, user) for user in contacts.users) diff --git a/pyrogram/methods/contacts/get_contacts_count.py b/pyrogram/methods/contacts/get_contacts_count.py index b7e5d371..d32ae050 100644 --- a/pyrogram/methods/contacts/get_contacts_count.py +++ b/pyrogram/methods/contacts/get_contacts_count.py @@ -36,4 +36,4 @@ class GetContactsCount: print(count) """ - return len((await self.send(raw.functions.contacts.GetContacts(hash=0))).contacts) + return len((await self.invoke(raw.functions.contacts.GetContacts(hash=0))).contacts) diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py index 7a6e3142..de802cff 100644 --- a/pyrogram/methods/contacts/import_contacts.py +++ b/pyrogram/methods/contacts/import_contacts.py @@ -47,7 +47,7 @@ class ImportContacts: InputPhoneContact("+1-456-789-0123", "Bar"), InputPhoneContact("+1-789-012-3456", "Baz")]) """ - imported_contacts = await self.send( + imported_contacts = await self.invoke( raw.functions.contacts.ImportContacts( contacts=contacts ) diff --git a/pyrogram/methods/invite_links/approve_chat_join_request.py b/pyrogram/methods/invite_links/approve_chat_join_request.py index a18a1c14..3cd22489 100644 --- a/pyrogram/methods/invite_links/approve_chat_join_request.py +++ b/pyrogram/methods/invite_links/approve_chat_join_request.py @@ -44,7 +44,7 @@ class ApproveChatJoinRequest: Returns: ``bool``: True on success. """ - await self.send( + await self.invoke( raw.functions.messages.HideChatJoinRequest( peer=await self.resolve_peer(chat_id), user_id=await self.resolve_peer(user_id), diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py index 15ca0341..0e3e63a7 100644 --- a/pyrogram/methods/invite_links/create_chat_invite_link.py +++ b/pyrogram/methods/invite_links/create_chat_invite_link.py @@ -72,7 +72,7 @@ class CreateChatInviteLink: # Create a new link for up to 7 new users link = app.create_chat_invite_link(chat_id, member_limit=7) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.ExportChatInvite( peer=await self.resolve_peer(chat_id), expire_date=utils.datetime_to_timestamp(expire_date), diff --git a/pyrogram/methods/invite_links/decline_chat_join_request.py b/pyrogram/methods/invite_links/decline_chat_join_request.py index d7c3d2f2..94e3c2fe 100644 --- a/pyrogram/methods/invite_links/decline_chat_join_request.py +++ b/pyrogram/methods/invite_links/decline_chat_join_request.py @@ -44,7 +44,7 @@ class DeclineChatJoinRequest: Returns: ``bool``: True on success. """ - await self.send( + await self.invoke( raw.functions.messages.HideChatJoinRequest( peer=await self.resolve_peer(chat_id), user_id=await self.resolve_peer(user_id), diff --git a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py index c0517178..8ba6754d 100644 --- a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py +++ b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py @@ -44,7 +44,7 @@ class DeleteChatAdminInviteLinks: ``bool``: On success ``True`` is returned. """ - return await self.send( + return await self.invoke( raw.functions.messages.DeleteRevokedExportedChatInvites( peer=await self.resolve_peer(chat_id), admin_id=await self.resolve_peer(admin_id), diff --git a/pyrogram/methods/invite_links/delete_chat_invite_link.py b/pyrogram/methods/invite_links/delete_chat_invite_link.py index 19f4b49b..1f38e46c 100644 --- a/pyrogram/methods/invite_links/delete_chat_invite_link.py +++ b/pyrogram/methods/invite_links/delete_chat_invite_link.py @@ -42,7 +42,7 @@ class DeleteChatInviteLink: ``bool``: On success ``True`` is returned. """ - return await self.send( + return await self.invoke( raw.functions.messages.DeleteExportedChatInvite( peer=await self.resolve_peer(chat_id), link=invite_link, diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py index 4a6755d6..96dcf79d 100644 --- a/pyrogram/methods/invite_links/edit_chat_invite_link.py +++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py @@ -74,7 +74,7 @@ class EditChatInviteLink: # Set no expiration date of a link link = app.edit_chat_invite_link(chat_id, invite_link, expire_date=0) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.EditExportedChatInvite( peer=await self.resolve_peer(chat_id), link=invite_link, diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py index 9734470f..66fb0227 100644 --- a/pyrogram/methods/invite_links/export_chat_invite_link.py +++ b/pyrogram/methods/invite_links/export_chat_invite_link.py @@ -53,7 +53,7 @@ class ExportChatInviteLink: # Generate a new primary link link = app.export_chat_invite_link(chat_id) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.ExportChatInvite( peer=await self.resolve_peer(chat_id), legacy_revoke_permanent=True diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py index 0c266082..1c79ce27 100644 --- a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py +++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py @@ -70,7 +70,7 @@ class GetChatAdminInviteLinks: offset_link = None while True: - r = await self.send( + r = await self.invoke( raw.functions.messages.GetExportedChatInvites( peer=await self.resolve_peer(chat_id), admin_id=await self.resolve_peer(admin_id), diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py index 419c76a7..c26af506 100644 --- a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py +++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py @@ -48,7 +48,7 @@ class GetChatAdminInviteLinksCount: Returns: ``int``: On success, the invite links count is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.GetExportedChatInvites( peer=await self.resolve_peer(chat_id), admin_id=await self.resolve_peer(admin_id), diff --git a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py index 0f41925a..61e082bc 100644 --- a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py +++ b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py @@ -40,7 +40,7 @@ class GetChatAdminsWithInviteLinks: List of :obj:`~pyrogram.types.ChatAdminWithInviteLink`: On success, the list of admins that have exported invite links is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.GetAdminsWithInvites( peer=await self.resolve_peer(chat_id) ) diff --git a/pyrogram/methods/invite_links/get_chat_invite_link.py b/pyrogram/methods/invite_links/get_chat_invite_link.py index 0fe0da8e..74479336 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link.py @@ -42,7 +42,7 @@ class GetChatInviteLink: Returns: :obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.GetExportedChatInvite( peer=await self.resolve_peer(chat_id), link=invite_link diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members.py b/pyrogram/methods/invite_links/get_chat_invite_link_members.py index 8269a346..28121ccc 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_members.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_members.py @@ -58,7 +58,7 @@ class GetChatInviteLinkMembers: offset_user = raw.types.InputUserEmpty() while True: - r = await self.send( + r = await self.invoke( raw.functions.messages.GetChatInviteImporters( peer=await self.resolve_peer(chat_id), link=invite_link, diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py index c37258fe..d5428957 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py @@ -41,7 +41,7 @@ class GetChatInviteLinkMembersCount: Returns: ``int``: On success, the joined chat members count is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.GetChatInviteImporters( peer=await self.resolve_peer(chat_id), link=invite_link, diff --git a/pyrogram/methods/invite_links/revoke_chat_invite_link.py b/pyrogram/methods/invite_links/revoke_chat_invite_link.py index 64af8e5f..a334bb8d 100644 --- a/pyrogram/methods/invite_links/revoke_chat_invite_link.py +++ b/pyrogram/methods/invite_links/revoke_chat_invite_link.py @@ -47,7 +47,7 @@ class RevokeChatInviteLink: :obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link object is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.EditExportedChatInvite( peer=await self.resolve_peer(chat_id), link=invite_link, diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py index 367cf47c..b204999f 100644 --- a/pyrogram/methods/messages/copy_media_group.py +++ b/pyrogram/methods/messages/copy_media_group.py @@ -109,7 +109,7 @@ class CopyMediaGroup: ) ) - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMultiMedia( peer=await self.resolve_peer(chat_id), multi_media=multi_media, diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py index 30438944..f8c3e7fe 100644 --- a/pyrogram/methods/messages/delete_messages.py +++ b/pyrogram/methods/messages/delete_messages.py @@ -66,14 +66,14 @@ class DeleteMessages: message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids] if isinstance(peer, raw.types.InputPeerChannel): - r = await self.send( + r = await self.invoke( raw.functions.channels.DeleteMessages( channel=peer, id=message_ids ) ) else: - r = await self.send( + r = await self.invoke( raw.functions.messages.DeleteMessages( id=message_ids, revoke=revoke or None diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index 0613bd73..1bf8d4d2 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -179,7 +179,7 @@ class EditInlineMedia: session = await get_session(self, dc_id) - return await session.send( + return await session.invoke( raw.functions.messages.EditInlineBotMessage( id=unpacked, media=media, diff --git a/pyrogram/methods/messages/edit_inline_reply_markup.py b/pyrogram/methods/messages/edit_inline_reply_markup.py index b3760c67..92c6851e 100644 --- a/pyrogram/methods/messages/edit_inline_reply_markup.py +++ b/pyrogram/methods/messages/edit_inline_reply_markup.py @@ -58,7 +58,7 @@ class EditInlineReplyMarkup: session = await get_session(self, dc_id) - return await session.send( + return await session.invoke( raw.functions.messages.EditInlineBotMessage( id=unpacked, reply_markup=await reply_markup.write(self) if reply_markup else None, diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py index ae4cab36..9a50d863 100644 --- a/pyrogram/methods/messages/edit_inline_text.py +++ b/pyrogram/methods/messages/edit_inline_text.py @@ -75,7 +75,7 @@ class EditInlineText: session = await get_session(self, dc_id) - return await session.send( + return await session.invoke( raw.functions.messages.EditInlineBotMessage( id=unpacked, no_webpage=disable_web_page_preview or None, diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index 1593bfb6..0e3f360c 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -87,7 +87,7 @@ class EditMessageMedia: if isinstance(media, types.InputMediaPhoto): if os.path.isfile(media.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedPhoto( @@ -111,7 +111,7 @@ class EditMessageMedia: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO) elif isinstance(media, types.InputMediaVideo): if os.path.isfile(media.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -148,7 +148,7 @@ class EditMessageMedia: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO) elif isinstance(media, types.InputMediaAudio): if os.path.isfile(media.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -184,7 +184,7 @@ class EditMessageMedia: media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO) elif isinstance(media, types.InputMediaAnimation): if os.path.isfile(media.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -222,7 +222,7 @@ class EditMessageMedia: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) elif isinstance(media, types.InputMediaDocument): if os.path.isfile(media.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -252,7 +252,7 @@ class EditMessageMedia: else: media = utils.get_input_media_from_file_id(media.media, FileType.DOCUMENT) - r = await self.send( + r = await self.invoke( raw.functions.messages.EditMessage( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py index 91b6fcd3..c164afbf 100644 --- a/pyrogram/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/methods/messages/edit_message_reply_markup.py @@ -58,7 +58,7 @@ class EditMessageReplyMarkup: InlineKeyboardMarkup([[ InlineKeyboardButton("New button", callback_data="new_data")]])) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.EditMessage( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py index 0f409cfe..551beaa1 100644 --- a/pyrogram/methods/messages/edit_message_text.py +++ b/pyrogram/methods/messages/edit_message_text.py @@ -77,7 +77,7 @@ class EditMessageText: disable_web_page_preview=True) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.EditMessage( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py index 12ed56aa..dbc5534e 100644 --- a/pyrogram/methods/messages/forward_messages.py +++ b/pyrogram/methods/messages/forward_messages.py @@ -79,7 +79,7 @@ class ForwardMessages: is_iterable = not isinstance(message_ids, int) message_ids = list(message_ids) if is_iterable else [message_ids] - r = await self.send( + r = await self.invoke( raw.functions.messages.ForwardMessages( to_peer=await self.resolve_peer(chat_id), from_peer=await self.resolve_peer(from_chat_id), diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py index f1de4592..6c72b484 100644 --- a/pyrogram/methods/messages/get_discussion_message.py +++ b/pyrogram/methods/messages/get_discussion_message.py @@ -49,7 +49,7 @@ class GetDiscussionMessage: # Comment to the post by replying m.reply("comment") """ - r = await self.send( + r = await self.invoke( raw.functions.messages.GetDiscussionMessage( peer=await self.resolve_peer(chat_id), msg_id=message_id diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py index a67d971e..ae8e1f37 100644 --- a/pyrogram/methods/messages/get_history.py +++ b/pyrogram/methods/messages/get_history.py @@ -86,7 +86,7 @@ class GetHistory: messages = await utils.parse_messages( self, - await self.send( + await self.invoke( raw.functions.messages.GetHistory( peer=await self.resolve_peer(chat_id), offset_id=offset_id, diff --git a/pyrogram/methods/messages/get_history_count.py b/pyrogram/methods/messages/get_history_count.py index a76c10b5..12e068ae 100644 --- a/pyrogram/methods/messages/get_history_count.py +++ b/pyrogram/methods/messages/get_history_count.py @@ -51,7 +51,7 @@ class GetHistoryCount: app.get_history_count(chat_id) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.GetHistory( peer=await self.resolve_peer(chat_id), offset_id=0, diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py index e9e408b5..a6a361af 100644 --- a/pyrogram/methods/messages/get_messages.py +++ b/pyrogram/methods/messages/get_messages.py @@ -111,7 +111,7 @@ class GetMessages: else: rpc = raw.functions.messages.GetMessages(id=ids) - r = await self.send(rpc, sleep_threshold=-1) + r = await self.invoke(rpc, sleep_threshold=-1) messages = await utils.parse_messages(self, r, replies=replies) diff --git a/pyrogram/methods/messages/inline_session.py b/pyrogram/methods/messages/inline_session.py index c4ac50aa..57fa7945 100644 --- a/pyrogram/methods/messages/inline_session.py +++ b/pyrogram/methods/messages/inline_session.py @@ -40,14 +40,14 @@ async def get_session(client: "pyrogram.Client", dc_id: int): await session.start() for _ in range(3): - exported_auth = await client.send( + exported_auth = await client.invoke( raw.functions.auth.ExportAuthorization( dc_id=dc_id ) ) try: - await session.send( + await session.invoke( raw.functions.auth.ImportAuthorization( id=exported_auth.id, bytes=exported_auth.bytes diff --git a/pyrogram/methods/messages/read_history.py b/pyrogram/methods/messages/read_history.py index 66b8bf50..204d9e31 100644 --- a/pyrogram/methods/messages/read_history.py +++ b/pyrogram/methods/messages/read_history.py @@ -66,6 +66,6 @@ class ReadHistory: max_id=max_id ) - await self.send(q) + await self.invoke(q) return True diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py index f49807cd..8aab69f0 100644 --- a/pyrogram/methods/messages/retract_vote.py +++ b/pyrogram/methods/messages/retract_vote.py @@ -48,7 +48,7 @@ class RetractVote: app.retract_vote(chat_id, message_id) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendVote( peer=await self.resolve_peer(chat_id), msg_id=message_id, diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py index 3f0d4e9f..a6ab5557 100644 --- a/pyrogram/methods/messages/search_global.py +++ b/pyrogram/methods/messages/search_global.py @@ -79,7 +79,7 @@ class SearchGlobal: while True: messages = await utils.parse_messages( self, - await self.send( + await self.invoke( raw.functions.messages.SearchGlobal( q=query, filter=filter.value(), diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py index c848546e..afdad4c1 100644 --- a/pyrogram/methods/messages/search_global_count.py +++ b/pyrogram/methods/messages/search_global_count.py @@ -41,7 +41,7 @@ class SearchGlobalCount: Returns: ``int``: On success, the messages count is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SearchGlobal( q=query, filter=filter.value(), diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py index b448a1c2..b40826d9 100644 --- a/pyrogram/methods/messages/search_messages.py +++ b/pyrogram/methods/messages/search_messages.py @@ -32,7 +32,7 @@ async def get_chunk( limit: int = 100, from_user: Union[int, str] = None ) -> List["types.Message"]: - r = await client.send( + r = await client.invoke( raw.functions.messages.Search( peer=await client.resolve_peer(chat_id), q=query, diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py index 85c25d06..301563e1 100644 --- a/pyrogram/methods/messages/search_messages_count.py +++ b/pyrogram/methods/messages/search_messages_count.py @@ -55,7 +55,7 @@ class SearchMessagesCount: Returns: ``int``: On success, the messages count is returned. """ - r = await self.send( + r = await self.invoke( raw.functions.messages.Search( peer=await self.resolve_peer(chat_id), q=query, diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index 2e84fe82..9403b1e4 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -216,7 +216,7 @@ class SendAnimation: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, @@ -249,7 +249,7 @@ class SendAnimation: document.file_id, FileType.ANIMATION ).id - await self.send( + await self.invoke( raw.functions.messages.SaveGif( id=document_id, unsave=True diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py index 47e914a8..e0a98f85 100644 --- a/pyrogram/methods/messages/send_audio.py +++ b/pyrogram/methods/messages/send_audio.py @@ -210,7 +210,7 @@ class SendAudio: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py index 4763e94d..88a5f309 100644 --- a/pyrogram/methods/messages/send_cached_media.py +++ b/pyrogram/methods/messages/send_cached_media.py @@ -96,7 +96,7 @@ class SendCachedMedia: app.send_cached_media("me", file_id) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=utils.get_input_media_from_file_id(file_id), diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py index 9145653e..39f8d85f 100644 --- a/pyrogram/methods/messages/send_chat_action.py +++ b/pyrogram/methods/messages/send_chat_action.py @@ -70,7 +70,7 @@ class SendChatAction: else: action = action.value() - return await self.send( + return await self.invoke( raw.functions.messages.SetTyping( peer=await self.resolve_peer(chat_id), action=action diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py index 6285b502..b4683338 100644 --- a/pyrogram/methods/messages/send_contact.py +++ b/pyrogram/methods/messages/send_contact.py @@ -88,7 +88,7 @@ class SendContact: app.send_contact("me", "+1-123-456-7890", "Name") """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaContact( diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py index c3a6bb42..b15cfe2d 100644 --- a/pyrogram/methods/messages/send_dice.py +++ b/pyrogram/methods/messages/send_dice.py @@ -88,7 +88,7 @@ class SendDice: app.send_dice(chat_id, "🏀") """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaDice(emoticon=emoji), diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py index 79f6e160..5b480cb3 100644 --- a/pyrogram/methods/messages/send_document.py +++ b/pyrogram/methods/messages/send_document.py @@ -188,7 +188,7 @@ class SendDocument: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py index 3e9bf37c..1364543b 100644 --- a/pyrogram/methods/messages/send_location.py +++ b/pyrogram/methods/messages/send_location.py @@ -80,7 +80,7 @@ class SendLocation: app.send_location("me", 51.500729, -0.124583) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaGeoPoint( diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py index ccb61361..382b2a92 100644 --- a/pyrogram/methods/messages/send_media_group.py +++ b/pyrogram/methods/messages/send_media_group.py @@ -94,7 +94,7 @@ class SendMediaGroup: if isinstance(i, types.InputMediaPhoto): if isinstance(i.media, str): if os.path.isfile(i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedPhoto( @@ -111,7 +111,7 @@ class SendMediaGroup: ) ) elif re.match("^https?://", i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaPhotoExternal( @@ -130,7 +130,7 @@ class SendMediaGroup: else: media = utils.get_input_media_from_file_id(i.media, FileType.PHOTO) else: - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedPhoto( @@ -149,7 +149,7 @@ class SendMediaGroup: elif isinstance(i, types.InputMediaVideo): if isinstance(i.media, str): if os.path.isfile(i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -177,7 +177,7 @@ class SendMediaGroup: ) ) elif re.match("^https?://", i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaDocumentExternal( @@ -196,7 +196,7 @@ class SendMediaGroup: else: media = utils.get_input_media_from_file_id(i.media, FileType.VIDEO) else: - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -226,7 +226,7 @@ class SendMediaGroup: elif isinstance(i, types.InputMediaAudio): if isinstance(i.media, str): if os.path.isfile(i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -253,7 +253,7 @@ class SendMediaGroup: ) ) elif re.match("^https?://", i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaDocumentExternal( @@ -272,7 +272,7 @@ class SendMediaGroup: else: media = utils.get_input_media_from_file_id(i.media, FileType.AUDIO) else: - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -301,7 +301,7 @@ class SendMediaGroup: elif isinstance(i, types.InputMediaDocument): if isinstance(i.media, str): if os.path.isfile(i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -323,7 +323,7 @@ class SendMediaGroup: ) ) elif re.match("^https?://", i.media): - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaDocumentExternal( @@ -342,7 +342,7 @@ class SendMediaGroup: else: media = utils.get_input_media_from_file_id(i.media, FileType.DOCUMENT) else: - media = await self.send( + media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( @@ -376,7 +376,7 @@ class SendMediaGroup: ) ) - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMultiMedia( peer=await self.resolve_peer(chat_id), multi_media=multi_media, diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py index 70544178..414f7447 100644 --- a/pyrogram/methods/messages/send_message.py +++ b/pyrogram/methods/messages/send_message.py @@ -123,7 +123,7 @@ class SendMessage: message, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values() - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMessage( peer=await self.resolve_peer(chat_id), no_webpage=disable_web_page_preview or None, diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 5cacfb39..e536d3a0 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -165,7 +165,7 @@ class SendPhoto: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py index 10545256..0dd877b9 100644 --- a/pyrogram/methods/messages/send_poll.py +++ b/pyrogram/methods/messages/send_poll.py @@ -100,7 +100,7 @@ class SendPoll: app.send_poll(chat_id, "Is this a poll question?", ["Yes", "No", "Maybe"]) """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaPoll( diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py index b096934f..34c2d92c 100644 --- a/pyrogram/methods/messages/send_reaction.py +++ b/pyrogram/methods/messages/send_reaction.py @@ -54,7 +54,7 @@ class SendReaction: # Retract a reaction app.send_reaction(chat_id, message_id) """ - await self.send( + await self.invoke( raw.functions.messages.SendReaction( peer=await self.resolve_peer(chat_id), msg_id=message_id, diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py index 460cfc63..ca6f47a5 100644 --- a/pyrogram/methods/messages/send_sticker.py +++ b/pyrogram/methods/messages/send_sticker.py @@ -147,7 +147,7 @@ class SendSticker: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py index 4dd81f7a..7ddb98ef 100644 --- a/pyrogram/methods/messages/send_venue.py +++ b/pyrogram/methods/messages/send_venue.py @@ -99,7 +99,7 @@ class SendVenue: "me", 51.500729, -0.124583, "Elizabeth Tower", "Westminster, London SW1A 0AA, UK") """ - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaVenue( diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index 9fd85213..e1c245b1 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -222,7 +222,7 @@ class SendVideo: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py index b4fd8891..7412e0ea 100644 --- a/pyrogram/methods/messages/send_video_note.py +++ b/pyrogram/methods/messages/send_video_note.py @@ -171,7 +171,7 @@ class SendVideoNote: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py index 5179866e..08e1bdc0 100644 --- a/pyrogram/methods/messages/send_voice.py +++ b/pyrogram/methods/messages/send_voice.py @@ -172,7 +172,7 @@ class SendVoice: while True: try: - r = await self.send( + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=media, diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py index 3fdba750..e642e1b6 100644 --- a/pyrogram/methods/messages/stop_poll.py +++ b/pyrogram/methods/messages/stop_poll.py @@ -56,7 +56,7 @@ class StopPoll: """ poll = (await self.get_messages(chat_id, message_id)).poll - r = await self.send( + r = await self.invoke( raw.functions.messages.EditMessage( peer=await self.resolve_peer(chat_id), id=message_id, diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py index 70a50365..3fea2e22 100644 --- a/pyrogram/methods/messages/vote_poll.py +++ b/pyrogram/methods/messages/vote_poll.py @@ -56,7 +56,7 @@ class VotePoll: poll = (await self.get_messages(chat_id, message_id)).poll options = [options] if not isinstance(options, list) else options - r = await self.send( + r = await self.invoke( raw.functions.messages.SendVote( peer=await self.resolve_peer(chat_id), msg_id=message_id, diff --git a/pyrogram/methods/password/change_cloud_password.py b/pyrogram/methods/password/change_cloud_password.py index a0e82963..3f7dee00 100644 --- a/pyrogram/methods/password/change_cloud_password.py +++ b/pyrogram/methods/password/change_cloud_password.py @@ -57,7 +57,7 @@ class ChangeCloudPassword: # Change password and hint app.change_cloud_password("current_password", "new_password", new_hint="hint") """ - r = await self.send(raw.functions.account.GetPassword()) + r = await self.invoke(raw.functions.account.GetPassword()) if not r.has_password: raise ValueError("There is no cloud password to change") @@ -66,7 +66,7 @@ class ChangeCloudPassword: new_hash = btoi(compute_password_hash(r.new_algo, new_password)) new_hash = itob(pow(r.new_algo.g, new_hash, btoi(r.new_algo.p))) - await self.send( + await self.invoke( raw.functions.account.UpdatePasswordSettings( password=compute_password_check(r, current_password), new_settings=raw.types.account.PasswordInputSettings( diff --git a/pyrogram/methods/password/enable_cloud_password.py b/pyrogram/methods/password/enable_cloud_password.py index 840acfdd..fd8b3dbf 100644 --- a/pyrogram/methods/password/enable_cloud_password.py +++ b/pyrogram/methods/password/enable_cloud_password.py @@ -62,7 +62,7 @@ class EnableCloudPassword: # Enable password with hint and email app.enable_cloud_password("password", hint="hint", email="user@email.com") """ - r = await self.send(raw.functions.account.GetPassword()) + r = await self.invoke(raw.functions.account.GetPassword()) if r.has_password: raise ValueError("There is already a cloud password enabled") @@ -71,7 +71,7 @@ class EnableCloudPassword: new_hash = btoi(compute_password_hash(r.new_algo, password)) new_hash = itob(pow(r.new_algo.g, new_hash, btoi(r.new_algo.p))) - await self.send( + await self.invoke( raw.functions.account.UpdatePasswordSettings( password=raw.types.InputCheckPasswordEmpty(), new_settings=raw.types.account.PasswordInputSettings( diff --git a/pyrogram/methods/password/remove_cloud_password.py b/pyrogram/methods/password/remove_cloud_password.py index 1a1c9a0b..845547d6 100644 --- a/pyrogram/methods/password/remove_cloud_password.py +++ b/pyrogram/methods/password/remove_cloud_password.py @@ -43,12 +43,12 @@ class RemoveCloudPassword: app.remove_cloud_password("password") """ - r = await self.send(raw.functions.account.GetPassword()) + r = await self.invoke(raw.functions.account.GetPassword()) if not r.has_password: raise ValueError("There is no cloud password to remove") - await self.send( + await self.invoke( raw.functions.account.UpdatePasswordSettings( password=compute_password_check(r, password), new_settings=raw.types.account.PasswordInputSettings( diff --git a/pyrogram/methods/users/block_user.py b/pyrogram/methods/users/block_user.py index b1d96537..3298e601 100644 --- a/pyrogram/methods/users/block_user.py +++ b/pyrogram/methods/users/block_user.py @@ -44,7 +44,7 @@ class BlockUser: app.block_user(user_id) """ return bool( - await self.send( + await self.invoke( raw.functions.contacts.Block( id=await self.resolve_peer(user_id) ) diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py index a1df82eb..107f11a6 100644 --- a/pyrogram/methods/users/delete_profile_photos.py +++ b/pyrogram/methods/users/delete_profile_photos.py @@ -54,7 +54,7 @@ class DeleteProfilePhotos: photo_ids = photo_ids if isinstance(photo_ids, list) else [photo_ids] input_photos = [utils.get_input_media_from_file_id(i, FileType.PHOTO).id for i in photo_ids] - return bool(await self.send( + return bool(await self.invoke( raw.functions.photos.DeletePhotos( id=input_photos ) diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py index e083e3c9..6c7d5ce7 100644 --- a/pyrogram/methods/users/get_common_chats.py +++ b/pyrogram/methods/users/get_common_chats.py @@ -52,7 +52,7 @@ class GetCommonChats: peer = await self.resolve_peer(user_id) if isinstance(peer, raw.types.InputPeerUser): - r = await self.send( + r = await self.invoke( raw.functions.messages.GetCommonChats( user_id=peer, max_id=0, diff --git a/pyrogram/methods/users/get_me.py b/pyrogram/methods/users/get_me.py index 17ffe3b8..2869f85c 100644 --- a/pyrogram/methods/users/get_me.py +++ b/pyrogram/methods/users/get_me.py @@ -36,7 +36,7 @@ class GetMe: me = app.get_me() print(me) """ - r = await self.send( + r = await self.invoke( raw.functions.users.GetFullUser( id=raw.types.InputUserSelf() ) diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_profile_photos.py index 62341550..ec35aa9e 100644 --- a/pyrogram/methods/users/get_profile_photos.py +++ b/pyrogram/methods/users/get_profile_photos.py @@ -65,7 +65,7 @@ class GetProfilePhotos: peer_id = await self.resolve_peer(chat_id) if isinstance(peer_id, raw.types.InputPeerChannel): - r = await self.send( + r = await self.invoke( raw.functions.channels.GetFullChannel( channel=peer_id ) @@ -75,7 +75,7 @@ class GetProfilePhotos: r = await utils.parse_messages( self, - await self.send( + await self.invoke( raw.functions.messages.Search( peer=peer_id, q="", @@ -107,7 +107,7 @@ class GetProfilePhotos: return types.List(photos[offset:limit]) else: - r = await self.send( + r = await self.invoke( raw.functions.photos.GetUserPhotos( user_id=peer_id, offset=offset, diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_profile_photos_count.py index c0065dd7..41e50f5e 100644 --- a/pyrogram/methods/users/get_profile_photos_count.py +++ b/pyrogram/methods/users/get_profile_photos_count.py @@ -48,7 +48,7 @@ class GetProfilePhotosCount: peer_id = await self.resolve_peer(chat_id) if isinstance(peer_id, raw.types.InputPeerChannel): - r = await self.send( + r = await self.invoke( raw.functions.messages.GetSearchCounters( peer=peer_id, filters=[raw.types.InputMessagesFilterChatPhotos()], @@ -57,7 +57,7 @@ class GetProfilePhotosCount: return r[0].count else: - r = await self.send( + r = await self.invoke( raw.functions.photos.GetUserPhotos( user_id=peer_id, offset=0, diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py index 0e9c9614..6f085c4f 100644 --- a/pyrogram/methods/users/get_users.py +++ b/pyrogram/methods/users/get_users.py @@ -56,7 +56,7 @@ class GetUsers: user_ids = list(user_ids) if is_iterable else [user_ids] user_ids = await asyncio.gather(*[self.resolve_peer(i) for i in user_ids]) - r = await self.send( + r = await self.invoke( raw.functions.users.GetUsers( id=user_ids ) diff --git a/pyrogram/methods/users/set_profile_photo.py b/pyrogram/methods/users/set_profile_photo.py index a68db7cd..a7d59092 100644 --- a/pyrogram/methods/users/set_profile_photo.py +++ b/pyrogram/methods/users/set_profile_photo.py @@ -64,7 +64,7 @@ class SetProfilePhoto: """ return bool( - await self.send( + await self.invoke( raw.functions.photos.UploadProfilePhoto( file=await self.save_file(photo), video=await self.save_file(video) diff --git a/pyrogram/methods/users/set_username.py b/pyrogram/methods/users/set_username.py index eeffc25f..68e443f1 100644 --- a/pyrogram/methods/users/set_username.py +++ b/pyrogram/methods/users/set_username.py @@ -47,7 +47,7 @@ class SetUsername: """ return bool( - await self.send( + await self.invoke( raw.functions.account.UpdateUsername( username=username or "" ) diff --git a/pyrogram/methods/users/unblock_user.py b/pyrogram/methods/users/unblock_user.py index 433105ac..75930658 100644 --- a/pyrogram/methods/users/unblock_user.py +++ b/pyrogram/methods/users/unblock_user.py @@ -44,7 +44,7 @@ class UnblockUser: app.unblock_user(user_id) """ return bool( - await self.send( + await self.invoke( raw.functions.contacts.Unblock( id=await self.resolve_peer(user_id) ) diff --git a/pyrogram/methods/users/update_profile.py b/pyrogram/methods/users/update_profile.py index c77c8b4b..779aa6cf 100644 --- a/pyrogram/methods/users/update_profile.py +++ b/pyrogram/methods/users/update_profile.py @@ -60,7 +60,7 @@ class UpdateProfile: """ return bool( - await self.send( + await self.invoke( raw.functions.account.UpdateProfile( first_name=first_name, last_name=last_name, diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py index 61ce87a2..ab4aef82 100644 --- a/pyrogram/methods/utilities/start.py +++ b/pyrogram/methods/utilities/start.py @@ -58,10 +58,10 @@ class Start: await self.authorize() if not await self.storage.is_bot() and self.takeout: - self.takeout_id = (await self.send(raw.functions.account.InitTakeoutSession())).id + self.takeout_id = (await self.invoke(raw.functions.account.InitTakeoutSession())).id log.warning(f"Takeout session {self.takeout_id} initiated") - await self.send(raw.functions.updates.GetState()) + await self.invoke(raw.functions.updates.GetState()) except (Exception, KeyboardInterrupt): await self.disconnect() raise diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index d4083b21..7df4fede 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -59,7 +59,7 @@ class Auth: b.seek(20) # Skip auth_key_id (8), message_id (8) and message_length (4) return TLObject.read(b) - async def send(self, data: TLObject): + async def invoke(self, data: TLObject): data = self.pack(data) await self.connection.send(data) response = BytesIO(await self.connection.recv()) @@ -86,7 +86,7 @@ class Auth: # Step 1; Step 2 nonce = int.from_bytes(urandom(16), "little", signed=True) log.debug(f"Send req_pq: {nonce}") - res_pq = await self.send(raw.functions.ReqPqMulti(nonce=nonce)) + res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce)) log.debug(f"Got ResPq: {res_pq.server_nonce}") log.debug(f"Server public key fingerprints: {res_pq.server_public_key_fingerprints}") @@ -130,7 +130,7 @@ class Auth: # Step 5. TODO: Handle "server_DH_params_fail". Code assumes response is ok log.debug("Send req_DH_params") - server_dh_params = await self.send( + server_dh_params = await self.invoke( raw.functions.ReqDHParams( nonce=nonce, server_nonce=server_nonce, @@ -190,7 +190,7 @@ class Auth: encrypted_data = aes.ige256_encrypt(data_with_hash, tmp_aes_key, tmp_aes_iv) log.debug("Send set_client_DH_params") - set_client_dh_params_answer = await self.send( + set_client_dh_params_answer = await self.invoke( raw.functions.SetClientDHParams( nonce=nonce, server_nonce=server_nonce, diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 05d1fd4a..3b0edca2 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -106,10 +106,10 @@ class Session: self.network_task = self.loop.create_task(self.network_worker()) - await self._send(raw.functions.Ping(ping_id=0), timeout=self.START_TIMEOUT) + await self.send(raw.functions.Ping(ping_id=0), timeout=self.START_TIMEOUT) if not self.is_cdn: - await self._send( + await self.send( raw.functions.InvokeWithLayer( layer=layer, query=raw.functions.InitConnection( @@ -240,7 +240,7 @@ class Session: log.debug(f"Send {len(self.pending_acks)} acks") try: - await self._send(raw.types.MsgsAck(msg_ids=list(self.pending_acks)), False) + await self.send(raw.types.MsgsAck(msg_ids=list(self.pending_acks)), False) except (OSError, TimeoutError): pass else: @@ -258,7 +258,7 @@ class Session: break try: - await self._send( + await self.send( raw.functions.PingDelayDisconnect( ping_id=0, disconnect_delay=self.WAIT_TIMEOUT + 10 ), False @@ -287,7 +287,7 @@ class Session: log.info("NetworkTask stopped") - async def _send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT): + async def send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT): message = self.msg_factory(data) msg_id = message.msg_id @@ -334,13 +334,13 @@ class Session: raise BadMsgNotification(result.error_code) elif isinstance(result, raw.types.BadServerSalt): self.salt = result.new_server_salt - return await self._send(data, wait_response, timeout) + return await self.send(data, wait_response, timeout) else: return result - async def send( + async def invoke( self, - data: TLObject, + query: TLObject, retries: int = MAX_RETRIES, timeout: float = WAIT_TIMEOUT, sleep_threshold: float = SLEEP_THRESHOLD @@ -350,16 +350,14 @@ class Session: except asyncio.TimeoutError: pass - if isinstance(data, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): - query = data.query - else: - query = data + if isinstance(query, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): + query = query.query - query = ".".join(query.QUALNAME.split(".")[1:]) + query_name = ".".join(query.QUALNAME.split(".")[1:]) while True: try: - return await self._send(data, timeout=timeout) + return await self.send(query, timeout=timeout) except FloodWait as e: amount = e.x @@ -367,7 +365,7 @@ class Session: raise log.warning(f'[{self.client.session_name}] Waiting for {amount} seconds before continuing ' - f'(required by "{query}")') + f'(required by "{query_name}")') await asyncio.sleep(amount) except (OSError, TimeoutError, InternalServerError, ServiceUnavailable) as e: @@ -375,8 +373,8 @@ class Session: raise e from None (log.warning if retries < 2 else log.info)( - f'[{Session.MAX_RETRIES - retries + 1}] Retrying "{query}" due to {str(e) or repr(e)}') + f'[{Session.MAX_RETRIES - retries + 1}] Retrying "{query_name}" due to {str(e) or repr(e)}') await asyncio.sleep(0.5) - return await self.send(data, retries - 1, timeout) + return await self.invoke(query, retries - 1, timeout) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index e9f3cab6..f7965e6a 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -462,7 +462,7 @@ class Message(Object, Update): if isinstance(message.from_id, raw.types.PeerUser) and isinstance(message.peer_id, raw.types.PeerUser): if from_id not in users or peer_id not in users: try: - r = await client.send( + r = await client.invoke( raw.functions.users.GetUsers( id=[ await client.resolve_peer(from_id), diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py index fa6e0be3..201b579f 100644 --- a/pyrogram/types/messages_and_media/sticker.py +++ b/pyrogram/types/messages_and_media/sticker.py @@ -112,7 +112,7 @@ class Sticker(Object): cache = {} @staticmethod - async def _get_sticker_set_name(send, input_sticker_set_id): + async def _get_sticker_set_name(invoke, input_sticker_set_id): try: set_id = input_sticker_set_id[0] set_access_hash = input_sticker_set_id[1] @@ -122,7 +122,7 @@ class Sticker(Object): if name is not None: return name - name = (await send( + name = (await invoke( raw.functions.messages.GetStickerSet( stickerset=raw.types.InputStickerSetID( id=set_id, @@ -154,7 +154,7 @@ class Sticker(Object): if isinstance(sticker_set, raw.types.InputStickerSetID): input_sticker_set_id = (sticker_set.id, sticker_set.access_hash) - set_name = await Sticker._get_sticker_set_name(client.send, input_sticker_set_id) + set_name = await Sticker._get_sticker_set_name(client.invoke, input_sticker_set_id) else: set_name = None