From 8b4dd1fa4a59af3ce16b20f827e02cf2129d3c2d Mon Sep 17 00:00:00 2001 From: ColinShark Date: Fri, 4 Oct 2019 13:57:40 +0200 Subject: [PATCH 1/7] Add USER_ID_INVALID error message (#313) --- compiler/error/source/400_BAD_REQUEST.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index 77531e9b..82726bd3 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -125,6 +125,7 @@ WEBDOCUMENT_URL_INVALID The web document URL is invalid WEBDOCUMENT_MIME_INVALID The web document mime type is invalid BUTTON_URL_INVALID The button url is invalid AUTH_BYTES_INVALID The authorization bytes are invalid +USER_ID_INVALID The user ID is invalid CHANNELS_TOO_MUCH You have joined too many channels or supergroups ADMIN_RANK_INVALID The custom administrator title is invalid or is longer than 16 characters ADMIN_RANK_EMOJI_NOT_ALLOWED Emojis are not allowed in custom administrator titles From 51cd186559b47aeecf29f99530e6b9e905754d25 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 19 Oct 2019 16:24:23 +0200 Subject: [PATCH 2/7] Fix group, channel and supergroup ChatPhoto downloads Closes #326 --- pyrogram/client/client.py | 20 ++++++++++++++++--- pyrogram/client/ext/file_data.py | 7 ++++--- .../client/methods/messages/download_media.py | 12 ++++++++++- .../client/types/user_and_chats/chat_photo.py | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 880d3c49..fcb17289 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1221,6 +1221,7 @@ class Client(Methods, BaseClient): access_hash=data.access_hash, thumb_size=data.thumb_size, peer_id=data.peer_id, + peer_type=data.peer_type, peer_access_hash=data.peer_access_hash, volume_id=data.volume_id, local_id=data.local_id, @@ -1866,6 +1867,7 @@ class Client(Methods, BaseClient): access_hash: int, thumb_size: str, peer_id: int, + peer_type: str, peer_access_hash: int, volume_id: int, local_id: int, @@ -1913,11 +1915,23 @@ class Client(Methods, BaseClient): file_ref = utils.decode_file_ref(file_ref) if media_type == 1: - location = types.InputPeerPhotoFileLocation( - peer=types.InputPeerUser( + if peer_type == "user": + peer = types.InputPeerUser( user_id=peer_id, access_hash=peer_access_hash - ), + ) + elif peer_type == "chat": + peer = types.InputPeerChat( + chat_id=peer_id + ) + else: + peer = types.InputPeerChannel( + channel_id=peer_id, + access_hash=peer_access_hash + ) + + location = types.InputPeerPhotoFileLocation( + peer=peer, volume_id=volume_id, local_id=local_id, big=is_big or None diff --git a/pyrogram/client/ext/file_data.py b/pyrogram/client/ext/file_data.py index ae023d18..94c90329 100644 --- a/pyrogram/client/ext/file_data.py +++ b/pyrogram/client/ext/file_data.py @@ -20,9 +20,9 @@ class FileData: def __init__( self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None, - thumb_size: str = None, peer_id: int = None, peer_access_hash: int = None, volume_id: int = None, - local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, file_name: str = None, - date: int = None, file_ref: str = None + thumb_size: str = None, peer_id: int = None, peer_type: str = None, peer_access_hash: int = None, + volume_id: int = None, local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, + file_name: str = None, date: int = None, file_ref: str = None ): self.media_type = media_type self.dc_id = dc_id @@ -30,6 +30,7 @@ class FileData: self.access_hash = access_hash self.thumb_size = thumb_size self.peer_id = peer_id + self.peer_type = peer_type self.peer_access_hash = peer_access_hash self.volume_id = volume_id self.local_id = local_id diff --git a/pyrogram/client/methods/messages/download_media.py b/pyrogram/client/methods/messages/download_media.py index 053e0155..c0e48823 100644 --- a/pyrogram/client/methods/messages/download_media.py +++ b/pyrogram/client/methods/messages/download_media.py @@ -146,13 +146,23 @@ class DownloadMedia(BaseClient): if media_type == 1: unpacked = struct.unpack(" Date: Sat, 19 Oct 2019 16:25:32 +0200 Subject: [PATCH 3/7] Add sphinx_copybutton extension for easy copy pasting from snippets Thanks @ColinTheShark --- docs/source/conf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 2544800d..b3f72048 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -34,7 +34,8 @@ author = "Dan" extensions = [ "sphinx.ext.autodoc", "sphinx.ext.napoleon", - "sphinx.ext.autosummary" + "sphinx.ext.autosummary", + "sphinx_copybutton" ] master_doc = "index" From cedb87ef41105118006428966560b1668344df84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=BE=D1=88=D0=B0?= Date: Sat, 19 Oct 2019 18:35:26 +0400 Subject: [PATCH 4/7] Add is_creator field to Chat object (#306) * Add is_creator field to Chat object * Update chat.py --- pyrogram/client/types/user_and_chats/chat.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 80545446..15a4f8d6 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -44,6 +44,9 @@ class Chat(Object): True, if this chat has been restricted. Supergroups, channels and bots only. See *restriction_reason* for details. + is_creator (``bool``, *optional*): + True, if this chat owner is the current user. Supergroups, channels and groups only. + is_scam (``bool``, *optional*): True, if this chat has been flagged for scam. Supergroups, channels and bots only. @@ -108,6 +111,7 @@ class Chat(Object): type: str, is_verified: bool = None, is_restricted: bool = None, + is_creator: bool = None, is_scam: bool = None, is_support: bool = None, title: str = None, @@ -131,6 +135,7 @@ class Chat(Object): self.type = type self.is_verified = is_verified self.is_restricted = is_restricted + self.is_creator = is_creator self.is_scam = is_scam self.is_support = is_support self.title = title @@ -175,6 +180,7 @@ class Chat(Object): id=peer_id, type="group", title=chat.title, + is_creator=getattr(channel, "creator", None), photo=ChatPhoto._parse(client, getattr(chat, "photo", None), peer_id, 0), permissions=ChatPermissions._parse(getattr(chat, "default_banned_rights", None)), members_count=getattr(chat, "participants_count", None), @@ -191,6 +197,7 @@ class Chat(Object): type="supergroup" if channel.megagroup else "channel", is_verified=getattr(channel, "verified", None), is_restricted=getattr(channel, "restricted", None), + is_creator=getattr(channel, "creator", None), is_scam=getattr(channel, "scam", None), title=channel.title, username=getattr(channel, "username", None), From 87512e20c3bf0532950cfedc41c465a6e065467a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 19 Oct 2019 16:36:45 +0200 Subject: [PATCH 5/7] Tiny copy-paste fix --- pyrogram/client/types/user_and_chats/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 15a4f8d6..9c25980b 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -180,7 +180,7 @@ class Chat(Object): id=peer_id, type="group", title=chat.title, - is_creator=getattr(channel, "creator", None), + is_creator=getattr(chat, "creator", None), photo=ChatPhoto._parse(client, getattr(chat, "photo", None), peer_id, 0), permissions=ChatPermissions._parse(getattr(chat, "default_banned_rights", None)), members_count=getattr(chat, "participants_count", None), From 945bc61262f3cad9fa15a441a3834e1819cedd39 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 19 Oct 2019 16:40:13 +0200 Subject: [PATCH 6/7] Fix group, channel and supergroup ChatPhoto downloads (#327) Closes #326 --- pyrogram/client/client.py | 20 ++++++++++++++++--- pyrogram/client/ext/file_data.py | 7 ++++--- .../client/methods/messages/download_media.py | 12 ++++++++++- .../client/types/user_and_chats/chat_photo.py | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 880d3c49..fcb17289 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1221,6 +1221,7 @@ class Client(Methods, BaseClient): access_hash=data.access_hash, thumb_size=data.thumb_size, peer_id=data.peer_id, + peer_type=data.peer_type, peer_access_hash=data.peer_access_hash, volume_id=data.volume_id, local_id=data.local_id, @@ -1866,6 +1867,7 @@ class Client(Methods, BaseClient): access_hash: int, thumb_size: str, peer_id: int, + peer_type: str, peer_access_hash: int, volume_id: int, local_id: int, @@ -1913,11 +1915,23 @@ class Client(Methods, BaseClient): file_ref = utils.decode_file_ref(file_ref) if media_type == 1: - location = types.InputPeerPhotoFileLocation( - peer=types.InputPeerUser( + if peer_type == "user": + peer = types.InputPeerUser( user_id=peer_id, access_hash=peer_access_hash - ), + ) + elif peer_type == "chat": + peer = types.InputPeerChat( + chat_id=peer_id + ) + else: + peer = types.InputPeerChannel( + channel_id=peer_id, + access_hash=peer_access_hash + ) + + location = types.InputPeerPhotoFileLocation( + peer=peer, volume_id=volume_id, local_id=local_id, big=is_big or None diff --git a/pyrogram/client/ext/file_data.py b/pyrogram/client/ext/file_data.py index ae023d18..94c90329 100644 --- a/pyrogram/client/ext/file_data.py +++ b/pyrogram/client/ext/file_data.py @@ -20,9 +20,9 @@ class FileData: def __init__( self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None, - thumb_size: str = None, peer_id: int = None, peer_access_hash: int = None, volume_id: int = None, - local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, file_name: str = None, - date: int = None, file_ref: str = None + thumb_size: str = None, peer_id: int = None, peer_type: str = None, peer_access_hash: int = None, + volume_id: int = None, local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, + file_name: str = None, date: int = None, file_ref: str = None ): self.media_type = media_type self.dc_id = dc_id @@ -30,6 +30,7 @@ class FileData: self.access_hash = access_hash self.thumb_size = thumb_size self.peer_id = peer_id + self.peer_type = peer_type self.peer_access_hash = peer_access_hash self.volume_id = volume_id self.local_id = local_id diff --git a/pyrogram/client/methods/messages/download_media.py b/pyrogram/client/methods/messages/download_media.py index 053e0155..c0e48823 100644 --- a/pyrogram/client/methods/messages/download_media.py +++ b/pyrogram/client/methods/messages/download_media.py @@ -146,13 +146,23 @@ class DownloadMedia(BaseClient): if media_type == 1: unpacked = struct.unpack(" Date: Thu, 24 Oct 2019 15:09:20 +0200 Subject: [PATCH 7/7] Fix deserialization of pretty-printable lists --- pyrogram/client/types/list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/list.py b/pyrogram/client/types/list.py index cec2d8a2..f8a96205 100644 --- a/pyrogram/client/types/list.py +++ b/pyrogram/client/types/list.py @@ -27,6 +27,6 @@ class List(list): return Object.__str__(self) def __repr__(self): - return "pyrogram.client.types.pyrogram_list.PyrogramList([{}])".format( + return "pyrogram.client.types.list.List([{}])".format( ",".join(Object.__repr__(i) for i in self) )