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,7 +21,7 @@ from ....ext import BaseClient
class AnswerCallbackQuery(BaseClient):
def answer_callback_query(self,
async def answer_callback_query(self,
callback_query_id: str,
text: str = None,
show_alert: bool = None,
@ -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.
Telegram apps will support caching starting in version 3.14. Defaults to 0.
"""
return self.send(
return await self.send(
functions.messages.SetBotCallbackAnswer(
query_id=int(callback_query_id),
cache_time=cache_time,

View File

@ -22,7 +22,7 @@ from ....ext import BaseClient
class GetInlineBotResults(BaseClient):
def get_inline_bot_results(self,
async def get_inline_bot_results(self,
bot: int or str,
query: str,
offset: str = "",
@ -60,9 +60,9 @@ class GetInlineBotResults(BaseClient):
# TODO: Don't return the raw type
try:
return self.send(
return await self.send(
functions.messages.GetInlineBotResults(
bot=self.resolve_peer(bot),
bot=await self.resolve_peer(bot),
peer=types.InputPeerSelf(),
query=query,
offset=offset,

View File

@ -21,7 +21,7 @@ from ....ext import BaseClient
class SendInlineBotResult(BaseClient):
def send_inline_bot_result(self,
async def send_inline_bot_result(self,
chat_id: int or str,
query_id: int,
result_id: str,
@ -56,9 +56,9 @@ class SendInlineBotResult(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
return self.send(
return await self.send(
functions.messages.SendInlineBotResult(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
query_id=query_id,
id=result_id,
random_id=self.rnd_id(),

View File

@ -21,7 +21,7 @@ from ...ext import 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.
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:
:class:`Error <pyrogram.Error>`
"""
peer = self.resolve_peer(chat_id)
peer = await self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChat):
return self.send(
return await self.send(
functions.messages.ExportChatInvite(
chat_id=peer.chat_id
)
).link
elif isinstance(peer, types.InputPeerChannel):
return self.send(
return await self.send(
functions.channels.ExportInvite(
channel=peer
)

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient, utils
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
one-on-one conversations, current username of a user, group or channel, etc.)
@ -31,13 +31,13 @@ class GetChat(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
peer = self.resolve_peer(chat_id)
peer = await self.resolve_peer(chat_id)
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)):
r = self.send(functions.users.GetFullUser(peer))
r = await self.send(functions.users.GetFullUser(peer))
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):
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.
Args:
@ -35,13 +35,13 @@ class JoinChat(BaseClient):
match = self.INVITE_LINK_RE.match(chat_id)
if match:
return self.send(
return await self.send(
functions.messages.ImportChatInvite(
hash=match.group(1)
)
)
else:
resolved_peer = self.send(
resolved_peer = await self.send(
functions.contacts.ResolveUsername(
username=chat_id.lower().strip("@")
)
@ -52,7 +52,7 @@ class JoinChat(BaseClient):
access_hash=resolved_peer.chats[0].access_hash
)
return self.send(
return await self.send(
functions.channels.JoinChannel(
channel=channel
)

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class KickChatMember(BaseClient):
def kick_chat_member(self,
async def kick_chat_member(self,
chat_id: int or str,
user_id: int or str,
until_date: int = 0):
@ -55,11 +55,11 @@ class KickChatMember(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
chat_peer = self.resolve_peer(chat_id)
user_peer = self.resolve_peer(user_id)
chat_peer = await self.resolve_peer(chat_id)
user_peer = await self.resolve_peer(user_id)
if isinstance(chat_peer, types.InputPeerChannel):
self.send(
await self.send(
functions.channels.EditBanned(
channel=chat_peer,
user_id=user_peer,
@ -77,7 +77,7 @@ class KickChatMember(BaseClient):
)
)
else:
self.send(
await self.send(
functions.messages.DeleteChatUser(
chat_id=abs(chat_id),
user_id=user_peer

View File

@ -21,7 +21,7 @@ from ...ext import 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.
Args:
@ -35,16 +35,16 @@ class LeaveChat(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
peer = self.resolve_peer(chat_id)
peer = await self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel):
return self.send(
return await self.send(
functions.channels.LeaveChannel(
channel=self.resolve_peer(chat_id)
channel=await self.resolve_peer(chat_id)
)
)
elif isinstance(peer, types.InputPeerChat):
r = self.send(
r = await self.send(
functions.messages.DeleteChatUser(
chat_id=peer.chat_id,
user_id=types.InputPeerSelf()
@ -52,7 +52,7 @@ class LeaveChat(BaseClient):
)
if delete:
self.send(
await self.send(
functions.messages.DeleteHistory(
peer=peer,
max_id=0

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class PromoteChatMember(BaseClient):
def promote_chat_member(self,
async def promote_chat_member(self,
chat_id: int or str,
user_id: int or str,
can_change_info: bool = True,
@ -77,10 +77,10 @@ class PromoteChatMember(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
self.send(
await self.send(
functions.channels.EditAdmin(
channel=self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id),
channel=await self.resolve_peer(chat_id),
user_id=await self.resolve_peer(user_id),
admin_rights=types.ChannelAdminRights(
change_info=can_change_info or None,
post_messages=can_post_messages or None,

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class RestrictChatMember(BaseClient):
def restrict_chat_member(self,
async def restrict_chat_member(self,
chat_id: int or str,
user_id: int or str,
until_date: int = 0,
@ -93,10 +93,10 @@ class RestrictChatMember(BaseClient):
send_media = None
embed_links = None
self.send(
await self.send(
functions.channels.EditBanned(
channel=self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id),
channel=await self.resolve_peer(chat_id),
user_id=await self.resolve_peer(user_id),
banned_rights=types.ChannelBannedRights(
until_date=until_date,
send_messages=send_messages,

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class UnbanChatMember(BaseClient):
def unban_chat_member(self,
async def unban_chat_member(self,
chat_id: int or str,
user_id: int or str):
"""Use this method to unban a previously kicked user in a supergroup or channel.
@ -43,10 +43,10 @@ class UnbanChatMember(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
self.send(
await self.send(
functions.channels.EditBanned(
channel=self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id),
channel=await self.resolve_peer(chat_id),
user_id=await self.resolve_peer(user_id),
banned_rights=types.ChannelBannedRights(
until_date=0
)

View File

@ -21,7 +21,7 @@ from ...ext import 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.
Args:
@ -34,7 +34,7 @@ class AddContacts(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
imported_contacts = self.send(
imported_contacts = await self.send(
functions.contacts.ImportContacts(
contacts=contacts
)

View File

@ -22,7 +22,7 @@ from ...ext import 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
Args:
@ -40,14 +40,14 @@ class DeleteContacts(BaseClient):
for i in ids:
try:
input_user = self.resolve_peer(i)
input_user = await self.resolve_peer(i)
except PeerIdInvalid:
continue
else:
if isinstance(input_user, types.InputPeerUser):
contacts.append(input_user)
return self.send(
return await self.send(
functions.contacts.DeleteContacts(
id=contacts
)

View File

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

View File

@ -16,14 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# 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 ..ext import BaseClient
class DownloadMedia(BaseClient):
def download_media(self,
async def download_media(self,
message: pyrogram_types.Message or str,
file_name: str = "",
block: bool = True,
@ -114,12 +114,12 @@ class DownloadMedia(BaseClient):
else:
return
done = Event()
done = asyncio.Event()
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:
done.wait()
await done.wait()
return path[0]

View File

@ -21,7 +21,7 @@ from ....ext import BaseClient, ChatAction
class SendChatAction(BaseClient):
def send_chat_action(self,
async def send_chat_action(self,
chat_id: int or str,
action: ChatAction or str,
progress: int = 0):
@ -63,9 +63,9 @@ class SendChatAction(BaseClient):
else:
action = action()
return self.send(
return await self.send(
functions.messages.SetTyping(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
action=action
)
)

View File

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

View File

@ -22,7 +22,7 @@ from ...ext import BaseClient, utils
class GetHistory(BaseClient):
def get_history(self,
async def get_history(self,
chat_id: int or str,
offset: int = 0,
limit: int = 100,
@ -60,9 +60,9 @@ class GetHistory(BaseClient):
:class:`Error <pyrogram.Error>`
"""
r = self.send(
r = await self.send(
functions.messages.GetHistory(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
offset_id=offset_id,
offset_date=offset_date,
add_offset=offset,
@ -83,7 +83,7 @@ class GetHistory(BaseClient):
}
if reply_to_messages:
temp = self.get_messages(
temp = await self.get_messages(
chat_id, reply_to_messages,
replies=0
)
@ -93,7 +93,7 @@ class GetHistory(BaseClient):
for i in range(len(temp)):
reply_to_messages[temp[i].message_id] = temp[i]
messages = utils.parse_messages(
messages = await utils.parse_messages(
self, r.messages,
users, chats,
replies=0

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient, utils
class GetMessages(BaseClient):
def get_messages(self,
async def get_messages(self,
chat_id: int or str,
message_ids,
replies: int = 1):
@ -51,7 +51,7 @@ class GetMessages(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
peer = self.resolve_peer(chat_id)
peer = await self.resolve_peer(chat_id)
is_iterable = not isinstance(message_ids, int)
message_ids = list(message_ids) if is_iterable else [message_ids]
message_ids = [types.InputMessageID(i) for i in message_ids]
@ -66,9 +66,9 @@ class GetMessages(BaseClient):
id=message_ids
)
r = self.send(rpc)
r = await self.send(rpc)
messages = utils.parse_messages(
messages = await utils.parse_messages(
self, r.messages,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},

View File

@ -27,7 +27,7 @@ from ....ext import BaseClient, utils
class SendAudio(BaseClient):
def send_audio(self,
async def send_audio(self,
chat_id: int or str,
audio: str,
caption: str = "",
@ -118,7 +118,7 @@ class SendAudio(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown
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(
mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"),
file=file,
@ -160,9 +160,9 @@ class SendAudio(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -172,11 +172,11 @@ class SendAudio(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

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

View File

@ -27,7 +27,7 @@ from ....ext import BaseClient, utils
class SendDocument(BaseClient):
def send_document(self,
async def send_document(self,
chat_id: int or str,
document: str,
caption: str = "",
@ -104,7 +104,7 @@ class SendDocument(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown
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(
mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"),
file=file,
@ -141,9 +141,9 @@ class SendDocument(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -153,11 +153,11 @@ class SendDocument(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

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

View File

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

View File

@ -31,7 +31,7 @@ class SendMediaGroup(BaseClient):
# TODO: Add progress parameter
# TODO: Return new Message object
# 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,
media: list,
disable_notification: bool = None,
@ -65,11 +65,11 @@ class SendMediaGroup(BaseClient):
if isinstance(i, pyrogram_types.InputMediaPhoto):
if os.path.exists(i.media):
media = self.send(
media = await self.send(
functions.messages.UploadMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
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):
if os.path.exists(i.media):
media = self.send(
media = await self.send(
functions.messages.UploadMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
file=self.save_file(i.media),
file=await self.save_file(i.media),
mime_type=mimetypes.types_map[".mp4"],
attributes=[
types.DocumentAttributeVideo(
@ -160,9 +160,9 @@ class SendMediaGroup(BaseClient):
)
)
return self.send(
return await self.send(
functions.messages.SendMultiMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
multi_media=multi_media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id

View File

@ -26,7 +26,7 @@ from ....ext import BaseClient, utils
class SendPhoto(BaseClient):
def send_photo(self,
async def send_photo(self,
chat_id: int or str,
photo: str,
caption: str = "",
@ -109,7 +109,7 @@ class SendPhoto(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown
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(
file=file,
ttl_seconds=ttl_seconds
@ -145,9 +145,9 @@ class SendPhoto(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -157,11 +157,11 @@ class SendPhoto(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -26,7 +26,7 @@ from ....ext import BaseClient, utils
class SendSticker(BaseClient):
def send_sticker(self,
async def send_sticker(self,
chat_id: int or str,
sticker: str,
disable_notification: bool = None,
@ -92,7 +92,7 @@ class SendSticker(BaseClient):
file = None
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(
mime_type="image/webp",
file=file,
@ -129,9 +129,9 @@ class SendSticker(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -141,11 +141,11 @@ class SendSticker(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -21,7 +21,7 @@ from ....ext import BaseClient, utils
class SendVenue(BaseClient):
def send_venue(self,
async def send_venue(self,
chat_id: int or str,
latitude: float,
longitude: float,
@ -72,9 +72,9 @@ class SendVenue(BaseClient):
Raises:
:class:`Error <pyrogram.Error>`
"""
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=types.InputMediaVenue(
geo_point=types.InputGeoPoint(
lat=latitude,
@ -96,7 +96,7 @@ class SendVenue(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -27,7 +27,7 @@ from ....ext import BaseClient, utils
class SendVideo(BaseClient):
def send_video(self,
async def send_video(self,
chat_id: int or str,
video: str,
caption: str = "",
@ -127,7 +127,7 @@ class SendVideo(BaseClient):
if os.path.exists(video):
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(
mime_type=mimetypes.types_map[".mp4"],
file=file,
@ -171,9 +171,9 @@ class SendVideo(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -183,11 +183,11 @@ class SendVideo(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -27,7 +27,7 @@ from ....ext import BaseClient, utils
class SendVideoNote(BaseClient):
def send_video_note(self,
async def send_video_note(self,
chat_id: int or str,
video_note: str,
duration: int = 0,
@ -101,7 +101,7 @@ class SendVideoNote(BaseClient):
file = None
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(
mime_type=mimetypes.types_map[".mp4"],
file=file,
@ -139,9 +139,9 @@ class SendVideoNote(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -151,11 +151,11 @@ class SendVideoNote(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -27,7 +27,7 @@ from ....ext import BaseClient, utils
class SendVoice(BaseClient):
def send_voice(self,
async def send_voice(self,
chat_id: int or str,
voice: str,
caption: str = "",
@ -108,7 +108,7 @@ class SendVoice(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown
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(
mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"),
file=file,
@ -148,9 +148,9 @@ class SendVoice(BaseClient):
while True:
try:
r = self.send(
r = await self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
@ -160,11 +160,11 @@ class SendVoice(BaseClient):
)
)
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:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

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

View File

@ -21,7 +21,7 @@ from ....ext import BaseClient
class DeleteMessages(BaseClient):
def delete_messages(self,
async def delete_messages(self,
chat_id: int or str,
message_ids,
revoke: bool = True):
@ -56,18 +56,18 @@ class DeleteMessages(BaseClient):
Raises:
: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]
if isinstance(peer, types.InputPeerChannel):
self.send(
await self.send(
functions.channels.DeleteMessages(
channel=peer,
id=message_ids
)
)
else:
self.send(
await self.send(
functions.messages.DeleteMessages(
id=message_ids,
revoke=revoke or None

View File

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

View File

@ -21,7 +21,7 @@ from ....ext import BaseClient, utils
class EditMessageReplyMarkup(BaseClient):
def edit_message_reply_markup(self,
async def edit_message_reply_markup(self,
chat_id: int or str,
message_id: int,
reply_markup=None):
@ -48,9 +48,9 @@ class EditMessageReplyMarkup(BaseClient):
:class:`Error <pyrogram.Error>`
"""
r = self.send(
r = await self.send(
functions.messages.EditMessage(
peer=self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id),
id=message_id,
reply_markup=reply_markup.write() if reply_markup else None
)
@ -58,7 +58,7 @@ class EditMessageReplyMarkup(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return utils.parse_messages(
return await utils.parse_messages(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

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