Make the new methods async

This commit is contained in:
Dan 2018-07-17 08:28:28 +02:00
parent 8a69c2d74e
commit ccd651f1fc
8 changed files with 32 additions and 32 deletions

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class DeleteChatPhoto(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. """Use this method to delete a chat photo.
Photos can't be changed for private chats. 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. 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 <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id belongs to user. ``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): if isinstance(peer, types.InputPeerChat):
self.send( await self.send(
functions.messages.EditChatPhoto( functions.messages.EditChatPhoto(
chat_id=peer.chat_id, chat_id=peer.chat_id,
photo=types.InputChatPhotoEmpty() photo=types.InputChatPhotoEmpty()
) )
) )
elif isinstance(peer, types.InputPeerChannel): elif isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.EditPhoto( functions.channels.EditPhoto(
channel=peer, channel=peer,
photo=types.InputChatPhotoEmpty() photo=types.InputChatPhotoEmpty()

View File

@ -30,17 +30,17 @@ class Filters:
class GetChatMembers(BaseClient): class GetChatMembers(BaseClient):
def get_chat_members(self, async def get_chat_members(self,
chat_id: int or str, chat_id: int or str,
offset: int = 0, offset: int = 0,
limit: int = 200, limit: int = 200,
query: str = "", query: str = "",
filter: str = Filters.ALL): filter: str = Filters.ALL):
peer = self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChat): if isinstance(peer, types.InputPeerChat):
return utils.parse_chat_members( return utils.parse_chat_members(
self.send( await self.send(
functions.messages.GetFullChat( functions.messages.GetFullChat(
peer.chat_id peer.chat_id
) )
@ -65,7 +65,7 @@ class GetChatMembers(BaseClient):
raise ValueError("Invalid filter \"{}\"".format(filter)) raise ValueError("Invalid filter \"{}\"".format(filter))
return utils.parse_chat_members( return utils.parse_chat_members(
self.send( await self.send(
functions.channels.GetParticipants( functions.channels.GetParticipants(
channel=peer, channel=peer,
filter=filter, filter=filter,

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class PinChatMessage(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. """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 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. the supergroup or "can_edit_messages" admin right in the channel.
@ -45,10 +45,10 @@ class PinChatMessage(BaseClient):
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. ``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): if isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.UpdatePinnedMessage( functions.channels.UpdatePinnedMessage(
channel=peer, channel=peer,
id=message_id, id=message_id,

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class SetChatDescription(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. """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. 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 <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. ``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): if isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.EditAbout( functions.channels.EditAbout(
channel=peer, channel=peer,
about=description about=description

View File

@ -25,7 +25,7 @@ from ...ext import BaseClient
class SetChatPhoto(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. """Use this method to set a new profile photo for the chat.
Photos can't be changed for private chats. 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. 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 <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id belongs to user. ``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): if os.path.exists(photo):
photo = types.InputChatUploadedPhoto(file=self.save_file(photo)) photo = types.InputChatUploadedPhoto(file=self.save_file(photo))
@ -64,14 +64,14 @@ class SetChatPhoto(BaseClient):
) )
if isinstance(peer, types.InputPeerChat): if isinstance(peer, types.InputPeerChat):
self.send( await self.send(
functions.messages.EditChatPhoto( functions.messages.EditChatPhoto(
chat_id=peer.chat_id, chat_id=peer.chat_id,
photo=photo photo=photo
) )
) )
elif isinstance(peer, types.InputPeerChannel): elif isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.EditPhoto( functions.channels.EditPhoto(
channel=peer, channel=peer,
photo=photo photo=photo

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class SetChatTitle(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. """Use this method to change the title of a chat.
Titles can't be changed for private chats. 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. 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 <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id belongs to user. ``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): if isinstance(peer, types.InputPeerChat):
self.send( await self.send(
functions.messages.EditChatTitle( functions.messages.EditChatTitle(
chat_id=peer.chat_id, chat_id=peer.chat_id,
title=title title=title
) )
) )
elif isinstance(peer, types.InputPeerChannel): elif isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.EditTitle( functions.channels.EditTitle(
channel=peer, channel=peer,
title=title title=title

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class UnpinChatMessage(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. """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 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. right in the supergroup or "can_edit_messages" admin right in the channel.
@ -38,10 +38,10 @@ class UnpinChatMessage(BaseClient):
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. ``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): if isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.UpdatePinnedMessage( functions.channels.UpdatePinnedMessage(
channel=peer, channel=peer,
id=0 id=0

View File

@ -572,7 +572,7 @@ class Message(Object):
else: else:
raise ValueError("The message doesn't contain any keyboard") 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: """Use this method as a shortcut for:
.. code-block:: python .. code-block:: python
@ -602,7 +602,7 @@ class Message(Object):
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
``ValueError``: If the message doesn't contain any downloadable media ``ValueError``: If the message doesn't contain any downloadable media
""" """
return self._client.download_media( return await self._client.download_media(
message=self, message=self,
file_name=file_name, file_name=file_name,
block=block block=block