From ccd651f1fcd7d42070d062112827423e29f307b4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 17 Jul 2018 08:28:28 +0200 Subject: [PATCH] Make the new methods async --- .../client/methods/chats/delete_chat_photo.py | 8 ++++---- .../client/methods/chats/get_chat_members.py | 18 +++++++++--------- .../client/methods/chats/pin_chat_message.py | 6 +++--- .../methods/chats/set_chat_description.py | 6 +++--- .../client/methods/chats/set_chat_photo.py | 8 ++++---- .../client/methods/chats/set_chat_title.py | 8 ++++---- .../client/methods/chats/unpin_chat_message.py | 6 +++--- pyrogram/client/types/message.py | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index 57d90b11..d8eff6a4 100644 --- a/pyrogram/client/methods/chats/delete_chat_photo.py +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -21,7 +21,7 @@ from ...ext import BaseClient class DeleteChatPhoto(BaseClient): - def delete_chat_photo(self, chat_id: int or str): + async def delete_chat_photo(self, chat_id: int or str): """Use this method to delete a chat photo. Photos can't be changed for private chats. You must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -42,17 +42,17 @@ class DeleteChatPhoto(BaseClient): :class:`Error ` ``ValueError``: If a chat_id belongs to user. """ - peer = self.resolve_peer(chat_id) + peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): - self.send( + await self.send( functions.messages.EditChatPhoto( chat_id=peer.chat_id, photo=types.InputChatPhotoEmpty() ) ) elif isinstance(peer, types.InputPeerChannel): - self.send( + await self.send( functions.channels.EditPhoto( channel=peer, photo=types.InputChatPhotoEmpty() diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index a851ef58..295a32c5 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -30,17 +30,17 @@ class Filters: class GetChatMembers(BaseClient): - def get_chat_members(self, - chat_id: int or str, - offset: int = 0, - limit: int = 200, - query: str = "", - filter: str = Filters.ALL): - peer = self.resolve_peer(chat_id) + async def get_chat_members(self, + chat_id: int or str, + offset: int = 0, + limit: int = 200, + query: str = "", + filter: str = Filters.ALL): + peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): return utils.parse_chat_members( - self.send( + await self.send( functions.messages.GetFullChat( peer.chat_id ) @@ -65,7 +65,7 @@ class GetChatMembers(BaseClient): raise ValueError("Invalid filter \"{}\"".format(filter)) return utils.parse_chat_members( - self.send( + await self.send( functions.channels.GetParticipants( channel=peer, filter=filter, diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py index e9bc533e..9e6f49c9 100644 --- a/pyrogram/client/methods/chats/pin_chat_message.py +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -21,7 +21,7 @@ from ...ext import BaseClient class PinChatMessage(BaseClient): - def pin_chat_message(self, chat_id: int or str, message_id: int, disable_notification: bool = None): + async def pin_chat_message(self, chat_id: int or str, message_id: int, disable_notification: bool = None): """Use this method to pin a message in a supergroup or a channel. You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in the supergroup or "can_edit_messages" admin right in the channel. @@ -45,10 +45,10 @@ class PinChatMessage(BaseClient): :class:`Error ` ``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. """ - peer = self.resolve_peer(chat_id) + peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): - self.send( + await self.send( functions.channels.UpdatePinnedMessage( channel=peer, id=message_id, diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py index c9597a62..8f647818 100644 --- a/pyrogram/client/methods/chats/set_chat_description.py +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -21,7 +21,7 @@ from ...ext import BaseClient class SetChatDescription(BaseClient): - def set_chat_description(self, chat_id: int or str, description: str): + async def set_chat_description(self, chat_id: int or str, description: str): """Use this method to change the description of a supergroup or a channel. You must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -40,10 +40,10 @@ class SetChatDescription(BaseClient): :class:`Error ` ``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. """ - peer = self.resolve_peer(chat_id) + peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): - self.send( + await self.send( functions.channels.EditAbout( channel=peer, about=description diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py index d98fefde..558671b7 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -25,7 +25,7 @@ from ...ext import BaseClient class SetChatPhoto(BaseClient): - def set_chat_photo(self, chat_id: int or str, photo: str): + async def set_chat_photo(self, chat_id: int or str, photo: str): """Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. You must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -49,7 +49,7 @@ class SetChatPhoto(BaseClient): :class:`Error ` ``ValueError``: If a chat_id belongs to user. """ - peer = self.resolve_peer(chat_id) + peer = await self.resolve_peer(chat_id) if os.path.exists(photo): photo = types.InputChatUploadedPhoto(file=self.save_file(photo)) @@ -64,14 +64,14 @@ class SetChatPhoto(BaseClient): ) if isinstance(peer, types.InputPeerChat): - self.send( + await self.send( functions.messages.EditChatPhoto( chat_id=peer.chat_id, photo=photo ) ) elif isinstance(peer, types.InputPeerChannel): - self.send( + await self.send( functions.channels.EditPhoto( channel=peer, photo=photo diff --git a/pyrogram/client/methods/chats/set_chat_title.py b/pyrogram/client/methods/chats/set_chat_title.py index f6644a01..2769ccb9 100644 --- a/pyrogram/client/methods/chats/set_chat_title.py +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -21,7 +21,7 @@ from ...ext import BaseClient class SetChatTitle(BaseClient): - def set_chat_title(self, chat_id: int or str, title: str): + async def set_chat_title(self, chat_id: int or str, title: str): """Use this method to change the title of a chat. Titles can't be changed for private chats. You must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -45,17 +45,17 @@ class SetChatTitle(BaseClient): :class:`Error ` ``ValueError``: If a chat_id belongs to user. """ - peer = self.resolve_peer(chat_id) + peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): - self.send( + await self.send( functions.messages.EditChatTitle( chat_id=peer.chat_id, title=title ) ) elif isinstance(peer, types.InputPeerChannel): - self.send( + await self.send( functions.channels.EditTitle( channel=peer, title=title diff --git a/pyrogram/client/methods/chats/unpin_chat_message.py b/pyrogram/client/methods/chats/unpin_chat_message.py index b1eeec79..9b6b4144 100644 --- a/pyrogram/client/methods/chats/unpin_chat_message.py +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -21,7 +21,7 @@ from ...ext import BaseClient class UnpinChatMessage(BaseClient): - def unpin_chat_message(self, chat_id: int or str): + async def unpin_chat_message(self, chat_id: int or str): """Use this method to unpin a message in a supergroup or a channel. You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in the supergroup or "can_edit_messages" admin right in the channel. @@ -38,10 +38,10 @@ class UnpinChatMessage(BaseClient): :class:`Error ` ``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. """ - peer = self.resolve_peer(chat_id) + peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): - self.send( + await self.send( functions.channels.UpdatePinnedMessage( channel=peer, id=0 diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index c9137328..51de2a6f 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -572,7 +572,7 @@ class Message(Object): else: raise ValueError("The message doesn't contain any keyboard") - def download(self, file_name: str = "", block: bool = True): + async def download(self, file_name: str = "", block: bool = True): """Use this method as a shortcut for: .. code-block:: python @@ -602,7 +602,7 @@ class Message(Object): :class:`Error ` ``ValueError``: If the message doesn't contain any downloadable media """ - return self._client.download_media( + return await self._client.download_media( message=self, file_name=file_name, block=block