Even more async chore

This commit is contained in:
Dan 2018-06-18 21:30:13 +02:00
parent 21af0f3e82
commit 4d72f84991
36 changed files with 344 additions and 344 deletions

View File

@ -21,12 +21,12 @@ from ....ext import BaseClient
class AnswerCallbackQuery(BaseClient): class AnswerCallbackQuery(BaseClient):
def answer_callback_query(self, async def answer_callback_query(self,
callback_query_id: str, callback_query_id: str,
text: str = None, text: str = None,
show_alert: bool = None, show_alert: bool = None,
url: str = None, url: str = None,
cache_time: int = 0): cache_time: int = 0):
"""Use this method to send answers to callback queries sent from inline keyboards. """Use this method to send answers to callback queries sent from inline keyboards.
The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
@ -51,7 +51,7 @@ class AnswerCallbackQuery(BaseClient):
The maximum amount of time in seconds that the result of the callback query may be cached client-side. The maximum amount of time in seconds that the result of the callback query may be cached client-side.
Telegram apps will support caching starting in version 3.14. Defaults to 0. Telegram apps will support caching starting in version 3.14. Defaults to 0.
""" """
return self.send( return await self.send(
functions.messages.SetBotCallbackAnswer( functions.messages.SetBotCallbackAnswer(
query_id=int(callback_query_id), query_id=int(callback_query_id),
cache_time=cache_time, cache_time=cache_time,

View File

@ -22,12 +22,12 @@ from ....ext import BaseClient
class GetInlineBotResults(BaseClient): class GetInlineBotResults(BaseClient):
def get_inline_bot_results(self, async def get_inline_bot_results(self,
bot: int or str, bot: int or str,
query: str, query: str,
offset: str = "", offset: str = "",
latitude: float = None, latitude: float = None,
longitude: float = None): longitude: float = None):
"""Use this method to get bot results via inline queries. """Use this method to get bot results via inline queries.
You can then send a result using :obj:`send_inline_bot_result <pyrogram.Client.send_inline_bot_result>` You can then send a result using :obj:`send_inline_bot_result <pyrogram.Client.send_inline_bot_result>`
@ -60,9 +60,9 @@ class GetInlineBotResults(BaseClient):
# TODO: Don't return the raw type # TODO: Don't return the raw type
try: try:
return self.send( return await self.send(
functions.messages.GetInlineBotResults( functions.messages.GetInlineBotResults(
bot=self.resolve_peer(bot), bot=await self.resolve_peer(bot),
peer=types.InputPeerSelf(), peer=types.InputPeerSelf(),
query=query, query=query,
offset=offset, offset=offset,

View File

@ -21,12 +21,12 @@ from ....ext import BaseClient
class SendInlineBotResult(BaseClient): class SendInlineBotResult(BaseClient):
def send_inline_bot_result(self, async def send_inline_bot_result(self,
chat_id: int or str, chat_id: int or str,
query_id: int, query_id: int,
result_id: str, result_id: str,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None):
"""Use this method to send an inline bot result. """Use this method to send an inline bot result.
Bot results can be retrieved using :obj:`get_inline_bot_results <pyrogram.Client.get_inline_bot_results>` Bot results can be retrieved using :obj:`get_inline_bot_results <pyrogram.Client.get_inline_bot_results>`
@ -56,9 +56,9 @@ class SendInlineBotResult(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
return self.send( return await self.send(
functions.messages.SendInlineBotResult( functions.messages.SendInlineBotResult(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
query_id=query_id, query_id=query_id,
id=result_id, id=result_id,
random_id=self.rnd_id(), random_id=self.rnd_id(),

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class ExportChatInviteLink(BaseClient): class ExportChatInviteLink(BaseClient):
def export_chat_invite_link(self, chat_id: int or str): async def export_chat_invite_link(self, chat_id: int or str):
"""Use this method to generate a new invite link for a chat; any previously generated link is revoked. """Use this method to generate a new invite link for a chat; any previously generated link is revoked.
You must be an administrator in the chat for this to work and have the appropriate admin rights. You must be an administrator in the chat for this to work and have the appropriate admin rights.
@ -37,16 +37,16 @@ class ExportChatInviteLink(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
peer = self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChat): if isinstance(peer, types.InputPeerChat):
return self.send( return await self.send(
functions.messages.ExportChatInvite( functions.messages.ExportChatInvite(
chat_id=peer.chat_id chat_id=peer.chat_id
) )
).link ).link
elif isinstance(peer, types.InputPeerChannel): elif isinstance(peer, types.InputPeerChannel):
return self.send( return await self.send(
functions.channels.ExportInvite( functions.channels.ExportInvite(
channel=peer channel=peer
) )

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient, utils
class GetChat(BaseClient): class GetChat(BaseClient):
def get_chat(self, chat_id: int or str): async def get_chat(self, chat_id: int or str):
"""Use this method to get up to date information about the chat (current name of the user for """Use this method to get up to date information about the chat (current name of the user for
one-on-one conversations, current username of a user, group or channel, etc.) one-on-one conversations, current username of a user, group or channel, etc.)
@ -31,13 +31,13 @@ class GetChat(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
peer = self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel): if isinstance(peer, types.InputPeerChannel):
r = self.send(functions.channels.GetFullChannel(peer)) r = await self.send(functions.channels.GetFullChannel(peer))
elif isinstance(peer, (types.InputPeerUser, types.InputPeerSelf)): elif isinstance(peer, (types.InputPeerUser, types.InputPeerSelf)):
r = self.send(functions.users.GetFullUser(peer)) r = await self.send(functions.users.GetFullUser(peer))
else: else:
r = self.send(functions.messages.GetFullChat(peer.chat_id)) r = await self.send(functions.messages.GetFullChat(peer.chat_id))
return utils.parse_chat_full(self, r) return await utils.parse_chat_full(self, r)

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class JoinChat(BaseClient): class JoinChat(BaseClient):
def join_chat(self, chat_id: str): async def join_chat(self, chat_id: str):
"""Use this method to join a group chat or channel. """Use this method to join a group chat or channel.
Args: Args:
@ -35,13 +35,13 @@ class JoinChat(BaseClient):
match = self.INVITE_LINK_RE.match(chat_id) match = self.INVITE_LINK_RE.match(chat_id)
if match: if match:
return self.send( return await self.send(
functions.messages.ImportChatInvite( functions.messages.ImportChatInvite(
hash=match.group(1) hash=match.group(1)
) )
) )
else: else:
resolved_peer = self.send( resolved_peer = await self.send(
functions.contacts.ResolveUsername( functions.contacts.ResolveUsername(
username=chat_id.lower().strip("@") username=chat_id.lower().strip("@")
) )
@ -52,7 +52,7 @@ class JoinChat(BaseClient):
access_hash=resolved_peer.chats[0].access_hash access_hash=resolved_peer.chats[0].access_hash
) )
return self.send( return await self.send(
functions.channels.JoinChannel( functions.channels.JoinChannel(
channel=channel channel=channel
) )

View File

@ -21,10 +21,10 @@ from ...ext import BaseClient
class KickChatMember(BaseClient): class KickChatMember(BaseClient):
def kick_chat_member(self, async def kick_chat_member(self,
chat_id: int or str, chat_id: int or str,
user_id: int or str, user_id: int or str,
until_date: int = 0): until_date: int = 0):
"""Use this method to kick a user from a group, a supergroup or a channel. """Use this method to kick a user from a group, a supergroup or a channel.
In the case of supergroups and channels, the user will not be able to return to the group on their own using In the case of supergroups and channels, the user will not be able to return to the group on their own using
invite links, etc., unless unbanned first. You must be an administrator in the chat for this to work and must invite links, etc., unless unbanned first. You must be an administrator in the chat for this to work and must
@ -55,11 +55,11 @@ class KickChatMember(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
chat_peer = self.resolve_peer(chat_id) chat_peer = await self.resolve_peer(chat_id)
user_peer = self.resolve_peer(user_id) user_peer = await self.resolve_peer(user_id)
if isinstance(chat_peer, types.InputPeerChannel): if isinstance(chat_peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.EditBanned( functions.channels.EditBanned(
channel=chat_peer, channel=chat_peer,
user_id=user_peer, user_id=user_peer,
@ -77,7 +77,7 @@ class KickChatMember(BaseClient):
) )
) )
else: else:
self.send( await self.send(
functions.messages.DeleteChatUser( functions.messages.DeleteChatUser(
chat_id=abs(chat_id), chat_id=abs(chat_id),
user_id=user_peer user_id=user_peer

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class LeaveChat(BaseClient): class LeaveChat(BaseClient):
def leave_chat(self, chat_id: int or str, delete: bool = False): async def leave_chat(self, chat_id: int or str, delete: bool = False):
"""Use this method to leave a group chat or channel. """Use this method to leave a group chat or channel.
Args: Args:
@ -35,16 +35,16 @@ class LeaveChat(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
peer = self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel): if isinstance(peer, types.InputPeerChannel):
return self.send( return await self.send(
functions.channels.LeaveChannel( functions.channels.LeaveChannel(
channel=self.resolve_peer(chat_id) channel=await self.resolve_peer(chat_id)
) )
) )
elif isinstance(peer, types.InputPeerChat): elif isinstance(peer, types.InputPeerChat):
r = self.send( r = await self.send(
functions.messages.DeleteChatUser( functions.messages.DeleteChatUser(
chat_id=peer.chat_id, chat_id=peer.chat_id,
user_id=types.InputPeerSelf() user_id=types.InputPeerSelf()
@ -52,7 +52,7 @@ class LeaveChat(BaseClient):
) )
if delete: if delete:
self.send( await self.send(
functions.messages.DeleteHistory( functions.messages.DeleteHistory(
peer=peer, peer=peer,
max_id=0 max_id=0

View File

@ -21,17 +21,17 @@ from ...ext import BaseClient
class PromoteChatMember(BaseClient): class PromoteChatMember(BaseClient):
def promote_chat_member(self, async def promote_chat_member(self,
chat_id: int or str, chat_id: int or str,
user_id: int or str, user_id: int or str,
can_change_info: bool = True, can_change_info: bool = True,
can_post_messages: bool = True, can_post_messages: bool = True,
can_edit_messages: bool = True, can_edit_messages: bool = True,
can_delete_messages: bool = True, can_delete_messages: bool = True,
can_invite_users: bool = True, can_invite_users: bool = True,
can_restrict_members: bool = True, can_restrict_members: bool = True,
can_pin_messages: bool = True, can_pin_messages: bool = True,
can_promote_members: bool = False): can_promote_members: bool = False):
"""Use this method to promote or demote a user in a supergroup or a channel. """Use this method to promote or demote a user in 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.
Pass False for all boolean parameters to demote a user. Pass False for all boolean parameters to demote a user.
@ -77,10 +77,10 @@ class PromoteChatMember(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
self.send( await self.send(
functions.channels.EditAdmin( functions.channels.EditAdmin(
channel=self.resolve_peer(chat_id), channel=await self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id), user_id=await self.resolve_peer(user_id),
admin_rights=types.ChannelAdminRights( admin_rights=types.ChannelAdminRights(
change_info=can_change_info or None, change_info=can_change_info or None,
post_messages=can_post_messages or None, post_messages=can_post_messages or None,

View File

@ -21,14 +21,14 @@ from ...ext import BaseClient
class RestrictChatMember(BaseClient): class RestrictChatMember(BaseClient):
def restrict_chat_member(self, async def restrict_chat_member(self,
chat_id: int or str, chat_id: int or str,
user_id: int or str, user_id: int or str,
until_date: int = 0, until_date: int = 0,
can_send_messages: bool = False, can_send_messages: bool = False,
can_send_media_messages: bool = False, can_send_media_messages: bool = False,
can_send_other_messages: bool = False, can_send_other_messages: bool = False,
can_add_web_page_previews: bool = False): can_add_web_page_previews: bool = False):
"""Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for """Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for
this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift
restrictions from a user. restrictions from a user.
@ -93,10 +93,10 @@ class RestrictChatMember(BaseClient):
send_media = None send_media = None
embed_links = None embed_links = None
self.send( await self.send(
functions.channels.EditBanned( functions.channels.EditBanned(
channel=self.resolve_peer(chat_id), channel=await self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id), user_id=await self.resolve_peer(user_id),
banned_rights=types.ChannelBannedRights( banned_rights=types.ChannelBannedRights(
until_date=until_date, until_date=until_date,
send_messages=send_messages, send_messages=send_messages,

View File

@ -21,9 +21,9 @@ from ...ext import BaseClient
class UnbanChatMember(BaseClient): class UnbanChatMember(BaseClient):
def unban_chat_member(self, async def unban_chat_member(self,
chat_id: int or str, chat_id: int or str,
user_id: int or str): user_id: int or str):
"""Use this method to unban a previously kicked user in a supergroup or channel. """Use this method to unban a previously kicked user in a supergroup or channel.
The user will **not** return to the group or channel automatically, but will be able to join via link, etc. The user will **not** return to the group or channel automatically, but will be able to join via link, etc.
You must be an administrator for this to work. You must be an administrator for this to work.
@ -43,10 +43,10 @@ class UnbanChatMember(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
self.send( await self.send(
functions.channels.EditBanned( functions.channels.EditBanned(
channel=self.resolve_peer(chat_id), channel=await self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id), user_id=await self.resolve_peer(user_id),
banned_rights=types.ChannelBannedRights( banned_rights=types.ChannelBannedRights(
until_date=0 until_date=0
) )

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class AddContacts(BaseClient): class AddContacts(BaseClient):
def add_contacts(self, contacts: list): async def add_contacts(self, contacts: list):
"""Use this method to add contacts to your Telegram address book. """Use this method to add contacts to your Telegram address book.
Args: Args:
@ -34,7 +34,7 @@ class AddContacts(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
imported_contacts = self.send( imported_contacts = await self.send(
functions.contacts.ImportContacts( functions.contacts.ImportContacts(
contacts=contacts contacts=contacts
) )

View File

@ -22,7 +22,7 @@ from ...ext import BaseClient
class DeleteContacts(BaseClient): class DeleteContacts(BaseClient):
def delete_contacts(self, ids: list): async def delete_contacts(self, ids: list):
"""Use this method to delete contacts from your Telegram address book """Use this method to delete contacts from your Telegram address book
Args: Args:
@ -40,14 +40,14 @@ class DeleteContacts(BaseClient):
for i in ids: for i in ids:
try: try:
input_user = self.resolve_peer(i) input_user = await self.resolve_peer(i)
except PeerIdInvalid: except PeerIdInvalid:
continue continue
else: else:
if isinstance(input_user, types.InputPeerUser): if isinstance(input_user, types.InputPeerUser):
contacts.append(input_user) contacts.append(input_user)
return self.send( return await self.send(
functions.contacts.DeleteContacts( functions.contacts.DeleteContacts(
id=contacts id=contacts
) )

View File

@ -16,8 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import logging import logging
import time
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.api.errors import FloodWait from pyrogram.api.errors import FloodWait
@ -27,7 +27,7 @@ log = logging.getLogger(__name__)
class GetContacts(BaseClient): class GetContacts(BaseClient):
def get_contacts(self): async def get_contacts(self):
"""Use this method to get contacts from your Telegram address book """Use this method to get contacts from your Telegram address book
Requires no parameters. Requires no parameters.
@ -40,10 +40,10 @@ class GetContacts(BaseClient):
""" """
while True: while True:
try: try:
contacts = self.send(functions.contacts.GetContacts(0)) contacts = await self.send(functions.contacts.GetContacts(0))
except FloodWait as e: except FloodWait as e:
log.warning("get_contacts flood: waiting {} seconds".format(e.x)) log.warning("get_contacts flood: waiting {} seconds".format(e.x))
time.sleep(e.x) await asyncio.sleep(e.x)
continue continue
else: else:
if isinstance(contacts, types.contacts.Contacts): if isinstance(contacts, types.contacts.Contacts):

View File

@ -16,19 +16,19 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from threading import Event import asyncio
from pyrogram.client import types as pyrogram_types from pyrogram.client import types as pyrogram_types
from ..ext import BaseClient from ..ext import BaseClient
class DownloadMedia(BaseClient): class DownloadMedia(BaseClient):
def download_media(self, async def download_media(self,
message: pyrogram_types.Message or str, message: pyrogram_types.Message or str,
file_name: str = "", file_name: str = "",
block: bool = True, block: bool = True,
progress: callable = None, progress: callable = None,
progress_args: tuple = None): progress_args: tuple = None):
"""Use this method to download the media from a Message. """Use this method to download the media from a Message.
Args: Args:
@ -114,12 +114,12 @@ class DownloadMedia(BaseClient):
else: else:
return return
done = Event() done = asyncio.Event()
path = [None] path = [None]
self.download_queue.put((media, file_name, done, progress, progress_args, path)) self.download_queue.put_nowait((media, file_name, done, progress, progress_args, path))
if block: if block:
done.wait() await done.wait()
return path[0] return path[0]

View File

@ -21,10 +21,10 @@ from ....ext import BaseClient, ChatAction
class SendChatAction(BaseClient): class SendChatAction(BaseClient):
def send_chat_action(self, async def send_chat_action(self,
chat_id: int or str, chat_id: int or str,
action: ChatAction or str, action: ChatAction or str,
progress: int = 0): progress: int = 0):
"""Use this method when you need to tell the other party that something is happening on your side. """Use this method when you need to tell the other party that something is happening on your side.
Args: Args:
@ -63,9 +63,9 @@ class SendChatAction(BaseClient):
else: else:
action = action() action = action()
return self.send( return await self.send(
functions.messages.SetTyping( functions.messages.SetTyping(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
action=action action=action
) )
) )

View File

@ -21,11 +21,11 @@ from ...ext import BaseClient, utils
class ForwardMessages(BaseClient): class ForwardMessages(BaseClient):
def forward_messages(self, async def forward_messages(self,
chat_id: int or str, chat_id: int or str,
from_chat_id: int or str, from_chat_id: int or str,
message_ids, message_ids,
disable_notification: bool = None): disable_notification: bool = None):
"""Use this method to forward messages of any kind. """Use this method to forward messages of any kind.
Args: Args:
@ -61,10 +61,10 @@ class ForwardMessages(BaseClient):
is_iterable = not isinstance(message_ids, int) is_iterable = not isinstance(message_ids, int)
message_ids = list(message_ids) if is_iterable else [message_ids] message_ids = list(message_ids) if is_iterable else [message_ids]
r = self.send( r = await self.send(
functions.messages.ForwardMessages( functions.messages.ForwardMessages(
to_peer=self.resolve_peer(chat_id), to_peer=await self.resolve_peer(chat_id),
from_peer=self.resolve_peer(from_chat_id), from_peer=await self.resolve_peer(from_chat_id),
id=message_ids, id=message_ids,
silent=disable_notification or None, silent=disable_notification or None,
random_id=[self.rnd_id() for _ in message_ids] random_id=[self.rnd_id() for _ in message_ids]
@ -79,7 +79,7 @@ class ForwardMessages(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
messages.append( messages.append(
utils.parse_messages( await utils.parse_messages(
self, i.message, self, i.message,
users, chats users, chats
) )

View File

@ -22,12 +22,12 @@ from ...ext import BaseClient, utils
class GetHistory(BaseClient): class GetHistory(BaseClient):
def get_history(self, async def get_history(self,
chat_id: int or str, chat_id: int or str,
offset: int = 0, offset: int = 0,
limit: int = 100, limit: int = 100,
offset_id: int = 0, offset_id: int = 0,
offset_date: int = 0): offset_date: int = 0):
"""Use this method to retrieve the history of a chat. """Use this method to retrieve the history of a chat.
You can get up to 100 messages at once. You can get up to 100 messages at once.
@ -60,9 +60,9 @@ class GetHistory(BaseClient):
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
r = self.send( r = await self.send(
functions.messages.GetHistory( functions.messages.GetHistory(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
offset_id=offset_id, offset_id=offset_id,
offset_date=offset_date, offset_date=offset_date,
add_offset=offset, add_offset=offset,
@ -83,7 +83,7 @@ class GetHistory(BaseClient):
} }
if reply_to_messages: if reply_to_messages:
temp = self.get_messages( temp = await self.get_messages(
chat_id, reply_to_messages, chat_id, reply_to_messages,
replies=0 replies=0
) )
@ -93,7 +93,7 @@ class GetHistory(BaseClient):
for i in range(len(temp)): for i in range(len(temp)):
reply_to_messages[temp[i].message_id] = temp[i] reply_to_messages[temp[i].message_id] = temp[i]
messages = utils.parse_messages( messages = await utils.parse_messages(
self, r.messages, self, r.messages,
users, chats, users, chats,
replies=0 replies=0

View File

@ -21,10 +21,10 @@ from ...ext import BaseClient, utils
class GetMessages(BaseClient): class GetMessages(BaseClient):
def get_messages(self, async def get_messages(self,
chat_id: int or str, chat_id: int or str,
message_ids, message_ids,
replies: int = 1): replies: int = 1):
"""Use this method to get messages that belong to a specific chat. """Use this method to get messages that belong to a specific chat.
You can retrieve up to 200 messages at once. You can retrieve up to 200 messages at once.
@ -51,7 +51,7 @@ class GetMessages(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
peer = self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
is_iterable = not isinstance(message_ids, int) is_iterable = not isinstance(message_ids, int)
message_ids = list(message_ids) if is_iterable else [message_ids] message_ids = list(message_ids) if is_iterable else [message_ids]
message_ids = [types.InputMessageID(i) for i in message_ids] message_ids = [types.InputMessageID(i) for i in message_ids]
@ -66,9 +66,9 @@ class GetMessages(BaseClient):
id=message_ids id=message_ids
) )
r = self.send(rpc) r = await self.send(rpc)
messages = utils.parse_messages( messages = await utils.parse_messages(
self, r.messages, self, r.messages,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},

View File

@ -27,19 +27,19 @@ from ....ext import BaseClient, utils
class SendAudio(BaseClient): class SendAudio(BaseClient):
def send_audio(self, async def send_audio(self,
chat_id: int or str, chat_id: int or str,
audio: str, audio: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
duration: int = 0, duration: int = 0,
performer: str = None, performer: str = None,
title: str = None, title: str = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send audio files. """Use this method to send audio files.
For sending voice messages, use the :obj:`send_voice()` method instead. For sending voice messages, use the :obj:`send_voice()` method instead.
@ -118,7 +118,7 @@ class SendAudio(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(audio): if os.path.exists(audio):
file = self.save_file(audio, progress=progress, progress_args=progress_args) file = await self.save_file(audio, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"), mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"),
file=file, file=file,
@ -160,9 +160,9 @@ class SendAudio(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -172,11 +172,11 @@ class SendAudio(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(audio, file_id=file.id, file_part=e.x) await self.save_file(audio, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -21,14 +21,14 @@ from ....ext import BaseClient, utils
class SendContact(BaseClient): class SendContact(BaseClient):
def send_contact(self, async def send_contact(self,
chat_id: int or str, chat_id: int or str,
phone_number: str, phone_number: str,
first_name: str, first_name: str,
last_name: str = "", last_name: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None): reply_markup=None):
"""Use this method to send phone contacts. """Use this method to send phone contacts.
Args: Args:
@ -64,9 +64,9 @@ class SendContact(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=types.InputMediaContact( media=types.InputMediaContact(
phone_number, phone_number,
first_name, first_name,
@ -82,7 +82,7 @@ class SendContact(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -27,16 +27,16 @@ from ....ext import BaseClient, utils
class SendDocument(BaseClient): class SendDocument(BaseClient):
def send_document(self, async def send_document(self,
chat_id: int or str, chat_id: int or str,
document: str, document: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send general files. """Use this method to send general files.
Args: Args:
@ -104,7 +104,7 @@ class SendDocument(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(document): if os.path.exists(document):
file = self.save_file(document, progress=progress, progress_args=progress_args) file = await self.save_file(document, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"), mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"),
file=file, file=file,
@ -141,9 +141,9 @@ class SendDocument(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -153,11 +153,11 @@ class SendDocument(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(document, file_id=file.id, file_part=e.x) await self.save_file(document, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -27,7 +27,7 @@ from ....ext import BaseClient, utils
class SendGIF(BaseClient): class SendGIF(BaseClient):
def send_gif(self, async def send_gif(self,
chat_id: int or str, chat_id: int or str,
gif: str, gif: str,
caption: str = "", caption: str = "",
@ -122,8 +122,8 @@ class SendGIF(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(gif): if os.path.exists(gif):
thumb = None if thumb is None else self.save_file(thumb) thumb = None if thumb is None else await self.save_file(thumb)
file = self.save_file(gif, progress=progress, progress_args=progress_args) file = await self.save_file(gif, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map[".mp4"], mime_type=mimetypes.types_map[".mp4"],
file=file, file=file,
@ -168,9 +168,9 @@ class SendGIF(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -180,11 +180,11 @@ class SendGIF(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(gif, file_id=file.id, file_part=e.x) await self.save_file(gif, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -21,13 +21,13 @@ from ....ext import BaseClient, utils
class SendLocation(BaseClient): class SendLocation(BaseClient):
def send_location(self, async def send_location(self,
chat_id: int or str, chat_id: int or str,
latitude: float, latitude: float,
longitude: float, longitude: float,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None): reply_markup=None):
"""Use this method to send points on the map. """Use this method to send points on the map.
Args: Args:
@ -60,9 +60,9 @@ class SendLocation(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=types.InputMediaGeoPoint( media=types.InputMediaGeoPoint(
types.InputGeoPoint( types.InputGeoPoint(
latitude, latitude,
@ -79,7 +79,7 @@ class SendLocation(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -31,11 +31,11 @@ class SendMediaGroup(BaseClient):
# TODO: Add progress parameter # TODO: Add progress parameter
# TODO: Return new Message object # TODO: Return new Message object
# TODO: Figure out how to send albums using URLs # TODO: Figure out how to send albums using URLs
def send_media_group(self, async def send_media_group(self,
chat_id: int or str, chat_id: int or str,
media: list, media: list,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None):
"""Use this method to send a group of photos or videos as an album. """Use this method to send a group of photos or videos as an album.
On success, an Update containing the sent Messages is returned. On success, an Update containing the sent Messages is returned.
@ -65,11 +65,11 @@ class SendMediaGroup(BaseClient):
if isinstance(i, pyrogram_types.InputMediaPhoto): if isinstance(i, pyrogram_types.InputMediaPhoto):
if os.path.exists(i.media): if os.path.exists(i.media):
media = self.send( media = await self.send(
functions.messages.UploadMedia( functions.messages.UploadMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=types.InputMediaUploadedPhoto( media=types.InputMediaUploadedPhoto(
file=self.save_file(i.media) file=await self.save_file(i.media)
) )
) )
) )
@ -104,11 +104,11 @@ class SendMediaGroup(BaseClient):
) )
elif isinstance(i, pyrogram_types.InputMediaVideo): elif isinstance(i, pyrogram_types.InputMediaVideo):
if os.path.exists(i.media): if os.path.exists(i.media):
media = self.send( media = await self.send(
functions.messages.UploadMedia( functions.messages.UploadMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument( media=types.InputMediaUploadedDocument(
file=self.save_file(i.media), file=await self.save_file(i.media),
mime_type=mimetypes.types_map[".mp4"], mime_type=mimetypes.types_map[".mp4"],
attributes=[ attributes=[
types.DocumentAttributeVideo( types.DocumentAttributeVideo(
@ -160,9 +160,9 @@ class SendMediaGroup(BaseClient):
) )
) )
return self.send( return await self.send(
functions.messages.SendMultiMedia( functions.messages.SendMultiMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
multi_media=multi_media, multi_media=multi_media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id reply_to_msg_id=reply_to_message_id

View File

@ -26,17 +26,17 @@ from ....ext import BaseClient, utils
class SendPhoto(BaseClient): class SendPhoto(BaseClient):
def send_photo(self, async def send_photo(self,
chat_id: int or str, chat_id: int or str,
photo: str, photo: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
ttl_seconds: int = None, ttl_seconds: int = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send photos. """Use this method to send photos.
Args: Args:
@ -109,7 +109,7 @@ class SendPhoto(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(photo): if os.path.exists(photo):
file = self.save_file(photo, progress=progress, progress_args=progress_args) file = await self.save_file(photo, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedPhoto( media = types.InputMediaUploadedPhoto(
file=file, file=file,
ttl_seconds=ttl_seconds ttl_seconds=ttl_seconds
@ -145,9 +145,9 @@ class SendPhoto(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -157,11 +157,11 @@ class SendPhoto(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(photo, file_id=file.id, file_part=e.x) await self.save_file(photo, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -26,14 +26,14 @@ from ....ext import BaseClient, utils
class SendSticker(BaseClient): class SendSticker(BaseClient):
def send_sticker(self, async def send_sticker(self,
chat_id: int or str, chat_id: int or str,
sticker: str, sticker: str,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send .webp stickers. """Use this method to send .webp stickers.
Args: Args:
@ -92,7 +92,7 @@ class SendSticker(BaseClient):
file = None file = None
if os.path.exists(sticker): if os.path.exists(sticker):
file = self.save_file(sticker, progress=progress, progress_args=progress_args) file = await self.save_file(sticker, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type="image/webp", mime_type="image/webp",
file=file, file=file,
@ -129,9 +129,9 @@ class SendSticker(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -141,11 +141,11 @@ class SendSticker(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(sticker, file_id=file.id, file_part=e.x) await self.save_file(sticker, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -21,16 +21,16 @@ from ....ext import BaseClient, utils
class SendVenue(BaseClient): class SendVenue(BaseClient):
def send_venue(self, async def send_venue(self,
chat_id: int or str, chat_id: int or str,
latitude: float, latitude: float,
longitude: float, longitude: float,
title: str, title: str,
address: str, address: str,
foursquare_id: str = "", foursquare_id: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None): reply_markup=None):
"""Use this method to send information about a venue. """Use this method to send information about a venue.
Args: Args:
@ -72,9 +72,9 @@ class SendVenue(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=types.InputMediaVenue( media=types.InputMediaVenue(
geo_point=types.InputGeoPoint( geo_point=types.InputGeoPoint(
lat=latitude, lat=latitude,
@ -96,7 +96,7 @@ class SendVenue(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -27,21 +27,21 @@ from ....ext import BaseClient, utils
class SendVideo(BaseClient): class SendVideo(BaseClient):
def send_video(self, async def send_video(self,
chat_id: int or str, chat_id: int or str,
video: str, video: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
duration: int = 0, duration: int = 0,
width: int = 0, width: int = 0,
height: int = 0, height: int = 0,
thumb: str = None, thumb: str = None,
supports_streaming: bool = True, supports_streaming: bool = True,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send video files. """Use this method to send video files.
Args: Args:
@ -127,7 +127,7 @@ class SendVideo(BaseClient):
if os.path.exists(video): if os.path.exists(video):
thumb = None if thumb is None else self.save_file(thumb) thumb = None if thumb is None else self.save_file(thumb)
file = self.save_file(video, progress=progress, progress_args=progress_args) file = await self.save_file(video, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map[".mp4"], mime_type=mimetypes.types_map[".mp4"],
file=file, file=file,
@ -171,9 +171,9 @@ class SendVideo(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -183,11 +183,11 @@ class SendVideo(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(video, file_id=file.id, file_part=e.x) await self.save_file(video, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -27,16 +27,16 @@ from ....ext import BaseClient, utils
class SendVideoNote(BaseClient): class SendVideoNote(BaseClient):
def send_video_note(self, async def send_video_note(self,
chat_id: int or str, chat_id: int or str,
video_note: str, video_note: str,
duration: int = 0, duration: int = 0,
length: int = 1, length: int = 1,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send video messages. """Use this method to send video messages.
Args: Args:
@ -101,7 +101,7 @@ class SendVideoNote(BaseClient):
file = None file = None
if os.path.exists(video_note): if os.path.exists(video_note):
file = self.save_file(video_note, progress=progress, progress_args=progress_args) file = await self.save_file(video_note, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map[".mp4"], mime_type=mimetypes.types_map[".mp4"],
file=file, file=file,
@ -139,9 +139,9 @@ class SendVideoNote(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -151,11 +151,11 @@ class SendVideoNote(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(video_note, file_id=file.id, file_part=e.x) await self.save_file(video_note, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -27,17 +27,17 @@ from ....ext import BaseClient, utils
class SendVoice(BaseClient): class SendVoice(BaseClient):
def send_voice(self, async def send_voice(self,
chat_id: int or str, chat_id: int or str,
voice: str, voice: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
duration: int = 0, duration: int = 0,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None, progress: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send audio files. """Use this method to send audio files.
Args: Args:
@ -108,7 +108,7 @@ class SendVoice(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(voice): if os.path.exists(voice):
file = self.save_file(voice, progress=progress, progress_args=progress_args) file = await self.save_file(voice, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"), mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"),
file=file, file=file,
@ -148,9 +148,9 @@ class SendVoice(BaseClient):
while True: while True:
try: try:
r = self.send( r = await self.send(
functions.messages.SendMedia( functions.messages.SendMedia(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
media=media, media=media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -160,11 +160,11 @@ class SendVoice(BaseClient):
) )
) )
except FilePartMissing as e: except FilePartMissing as e:
self.save_file(voice, file_id=file.id, file_part=e.x) await self.save_file(voice, file_id=file.id, file_part=e.x)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -22,14 +22,14 @@ from ...ext import utils, BaseClient
class SendMessage(BaseClient): class SendMessage(BaseClient):
def send_message(self, async def send_message(self,
chat_id: int or str, chat_id: int or str,
text: str, text: str,
parse_mode: str = "", parse_mode: str = "",
disable_web_page_preview: bool = None, disable_web_page_preview: bool = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None): reply_markup=None):
"""Use this method to send text messages. """Use this method to send text messages.
Args: Args:
@ -69,9 +69,9 @@ class SendMessage(BaseClient):
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
r = self.send( r = await self.send(
functions.messages.SendMessage( functions.messages.SendMessage(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
no_webpage=disable_web_page_preview or None, no_webpage=disable_web_page_preview or None,
silent=disable_notification or None, silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
@ -91,7 +91,7 @@ class SendMessage(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -21,10 +21,10 @@ from ....ext import BaseClient
class DeleteMessages(BaseClient): class DeleteMessages(BaseClient):
def delete_messages(self, async def delete_messages(self,
chat_id: int or str, chat_id: int or str,
message_ids, message_ids,
revoke: bool = True): revoke: bool = True):
"""Use this method to delete messages, including service messages, with the following limitations: """Use this method to delete messages, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago. - A message can only be deleted if it was sent less than 48 hours ago.
@ -56,18 +56,18 @@ class DeleteMessages(BaseClient):
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
peer = self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids] message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids]
if isinstance(peer, types.InputPeerChannel): if isinstance(peer, types.InputPeerChannel):
self.send( await self.send(
functions.channels.DeleteMessages( functions.channels.DeleteMessages(
channel=peer, channel=peer,
id=message_ids id=message_ids
) )
) )
else: else:
self.send( await self.send(
functions.messages.DeleteMessages( functions.messages.DeleteMessages(
id=message_ids, id=message_ids,
revoke=revoke or None revoke=revoke or None

View File

@ -21,12 +21,12 @@ from ....ext import BaseClient, utils
class EditMessageCaption(BaseClient): class EditMessageCaption(BaseClient):
def edit_message_caption(self, async def edit_message_caption(self,
chat_id: int or str, chat_id: int or str,
message_id: int, message_id: int,
caption: str, caption: str,
parse_mode: str = "", parse_mode: str = "",
reply_markup=None): reply_markup=None):
"""Use this method to edit captions of messages. """Use this method to edit captions of messages.
Args: Args:
@ -58,9 +58,9 @@ class EditMessageCaption(BaseClient):
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
r = self.send( r = await self.send(
functions.messages.EditMessage( functions.messages.EditMessage(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
id=message_id, id=message_id,
reply_markup=reply_markup.write() if reply_markup else None, reply_markup=reply_markup.write() if reply_markup else None,
**style.parse(caption) **style.parse(caption)
@ -69,7 +69,7 @@ class EditMessageCaption(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -21,10 +21,10 @@ from ....ext import BaseClient, utils
class EditMessageReplyMarkup(BaseClient): class EditMessageReplyMarkup(BaseClient):
def edit_message_reply_markup(self, async def edit_message_reply_markup(self,
chat_id: int or str, chat_id: int or str,
message_id: int, message_id: int,
reply_markup=None): reply_markup=None):
"""Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). """Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
Args: Args:
@ -48,9 +48,9 @@ class EditMessageReplyMarkup(BaseClient):
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
r = self.send( r = await self.send(
functions.messages.EditMessage( functions.messages.EditMessage(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
id=message_id, id=message_id,
reply_markup=reply_markup.write() if reply_markup else None reply_markup=reply_markup.write() if reply_markup else None
) )
@ -58,7 +58,7 @@ class EditMessageReplyMarkup(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -21,13 +21,13 @@ from ....ext import BaseClient, utils
class EditMessageText(BaseClient): class EditMessageText(BaseClient):
def edit_message_text(self, async def edit_message_text(self,
chat_id: int or str, chat_id: int or str,
message_id: int, message_id: int,
text: str, text: str,
parse_mode: str = "", parse_mode: str = "",
disable_web_page_preview: bool = None, disable_web_page_preview: bool = None,
reply_markup=None): reply_markup=None):
"""Use this method to edit text messages. """Use this method to edit text messages.
Args: Args:
@ -62,9 +62,9 @@ class EditMessageText(BaseClient):
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
r = self.send( r = await self.send(
functions.messages.EditMessage( functions.messages.EditMessage(
peer=self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
id=message_id, id=message_id,
no_webpage=disable_web_page_preview or None, no_webpage=disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else None, reply_markup=reply_markup.write() if reply_markup else None,
@ -74,7 +74,7 @@ class EditMessageText(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return utils.parse_messages( return await utils.parse_messages(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}