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):
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 <pyrogram.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()

View File

@ -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,

View File

@ -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 <pyrogram.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,

View File

@ -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 <pyrogram.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

View File

@ -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 <pyrogram.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

View File

@ -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 <pyrogram.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

View File

@ -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 <pyrogram.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

View File

@ -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 <pyrogram.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