diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index df1ca8b1..71728676 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -16,9 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api import functions, types -from ...ext import BaseClient, utils import pyrogram +from pyrogram.api import functions, types +from ...ext import BaseClient class Filters: diff --git a/pyrogram/client/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index 5bac80b8..292fdfd6 100644 --- a/pyrogram/client/methods/chats/kick_chat_member.py +++ b/pyrogram/client/methods/chats/kick_chat_member.py @@ -16,8 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client.ext import utils from ...ext import BaseClient @@ -86,7 +86,7 @@ class KickChatMember(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py index 0e12f72b..a79c21f4 100644 --- a/pyrogram/client/methods/messages/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -16,8 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram + from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils +from pyrogram.client.ext import BaseClient class EditMessageCaption(BaseClient): @@ -68,7 +70,7 @@ class EditMessageCaption(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index ccbacac7..5d06c31b 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils @@ -333,7 +334,7 @@ class EditMessageMedia(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py index 72796306..3b301dcb 100644 --- a/pyrogram/client/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils +from pyrogram.client.ext import BaseClient class EditMessageReplyMarkup(BaseClient): @@ -57,7 +58,7 @@ class EditMessageReplyMarkup(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py index 144f5413..991ff049 100644 --- a/pyrogram/client/methods/messages/edit_message_text.py +++ b/pyrogram/client/methods/messages/edit_message_text.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils +from pyrogram.client.ext import BaseClient class EditMessageText(BaseClient): @@ -73,7 +74,7 @@ class EditMessageText(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/forward_messages.py b/pyrogram/client/methods/messages/forward_messages.py index a8783044..e2e10c93 100644 --- a/pyrogram/client/methods/messages/forward_messages.py +++ b/pyrogram/client/methods/messages/forward_messages.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from ...ext import BaseClient, utils +from ...ext import BaseClient class ForwardMessages(BaseClient): @@ -77,7 +78,7 @@ class ForwardMessages(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): messages.append( - utils.parse_messages( + pyrogram.Message.parse( self, i.message, users, chats ) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 7411e22f..2e3930ae 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from ...ext import BaseClient, utils +from ...ext import BaseClient class GetMessages(BaseClient): @@ -48,10 +49,9 @@ class GetMessages(BaseClient): The number of subsequent replies to get for each message. Defaults to 1. Returns: - On success and in case *message_ids* or *reply_to_message_ids* was a list, the returned value will be a - list of the requested :obj:`Messages ` even if a list contains just one element, - otherwise if *message_ids* or *reply_to_message_ids* was an integer, the single requested - :obj:`Message ` is returned. + On success and in case *message_ids* or *reply_to_message_ids* was an iterable, the returned value will be a + :obj:`Messages ` even if a list contains just one element. Otherwise, if *message_ids* or + *reply_to_message_ids* was an integer, the single requested :obj:`Message ` is returned. Raises: :class:`Error ` in case of a Telegram RPC error. @@ -76,13 +76,6 @@ class GetMessages(BaseClient): else: rpc = functions.messages.GetMessages(id=ids) - r = self.send(rpc) + messages = pyrogram.Messages.parse(self, self.send(rpc)) - messages = utils.parse_messages( - self, r.messages, - {i.id: i for i in r.users}, - {i.id: i for i in r.chats}, - replies=replies - ) - - return messages if is_iterable else messages[0] + return messages if is_iterable else messages.messages[0] diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index dbd29575..c86fb867 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -184,7 +185,7 @@ class SendAnimation(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 613ec90c..12c65dec 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -184,7 +185,7 @@ class SendAudio(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index b40321be..a5d88f97 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils +from pyrogram.client.ext import BaseClient class SendContact(BaseClient): @@ -86,7 +87,7 @@ class SendContact(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index f3f52178..66a65e9d 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -165,7 +166,7 @@ class SendDocument(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index 2bd3eff3..baa84966 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils +from pyrogram.client.ext import BaseClient class SendLocation(BaseClient): @@ -78,7 +79,7 @@ class SendLocation(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index 78ce27e5..77af4db8 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -16,9 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client import types as pyrogram_types -from ...ext import utils, BaseClient +from ...ext import BaseClient class SendMessage(BaseClient): @@ -83,9 +83,13 @@ class SendMessage(BaseClient): ) if isinstance(r, types.UpdateShortSentMessage): - return pyrogram_types.Message( + return pyrogram.Message( message_id=r.id, - chat=pyrogram_types.Chat(id=list(self.resolve_peer(chat_id).__dict__.values())[0], type="private"), + chat=pyrogram.Chat( + id=list(self.resolve_peer(chat_id).__dict__.values())[0], + type="private", + client=self + ), text=message, date=r.date, outgoing=r.out, @@ -95,7 +99,7 @@ class SendMessage(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index 7f0c2d07..323c2fa5 100644 --- a/pyrogram/client/methods/messages/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -20,6 +20,7 @@ import binascii import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -160,7 +161,7 @@ class SendPhoto(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index 0b8f8073..fccfb0b5 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -20,6 +20,7 @@ import binascii import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -144,7 +145,7 @@ class SendSticker(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 30b848ea..1155ca79 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils +from pyrogram.client.ext import BaseClient class SendVenue(BaseClient): @@ -100,7 +101,7 @@ class SendVenue(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index e8e4627a..47b15d59 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -187,7 +188,7 @@ class SendVideo(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index de539a81..61ae0017 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -163,7 +164,7 @@ class SendVideoNote(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index 4be702d0..4882a87f 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -21,6 +21,7 @@ import mimetypes import os import struct +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils @@ -163,7 +164,7 @@ class SendVoice(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return utils.parse_messages( + return pyrogram.Message.parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/users/get_me.py b/pyrogram/client/methods/users/get_me.py index 009ef71e..c7d32968 100644 --- a/pyrogram/client/methods/users/get_me.py +++ b/pyrogram/client/methods/users/get_me.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import pyrogram from pyrogram.api import functions, types -from ...ext import BaseClient, utils +from ...ext import BaseClient class GetMe(BaseClient): @@ -30,7 +31,8 @@ class GetMe(BaseClient): Raises: :class:`Error ` in case of a Telegram RPC error. """ - return utils.parse_user( + return pyrogram.User.parse( + self, self.send( functions.users.GetFullUser( types.InputPeerSelf() diff --git a/pyrogram/client/methods/utilities/download_media.py b/pyrogram/client/methods/utilities/download_media.py index 9b6c554a..f0ad0396 100644 --- a/pyrogram/client/methods/utilities/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -84,7 +84,8 @@ class DownloadMedia(BaseClient): file_id=message.photo.sizes[-1].file_id, file_size=message.photo.sizes[-1].file_size, mime_type="", - date=message.photo.date + date=message.photo.date, + client=self ) elif message.audio: media = message.audio @@ -118,7 +119,8 @@ class DownloadMedia(BaseClient): file_id=message.sizes[-1].file_id, file_size=message.sizes[-1].file_size, mime_type="", - date=message.date + date=message.date, + client=self ) else: media = message @@ -126,7 +128,8 @@ class DownloadMedia(BaseClient): media = pyrogram_types.Document( file_id=message, file_size=0, - mime_type="" + mime_type="", + client=self ) else: raise ValueError(error_message)