From 0935c4837f2c9cf9f66b69c48ddea81f0d1a6d53 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 18:41:16 +0200 Subject: [PATCH 01/17] Fix ReplyKeyboardRemove id --- pyrogram/client/types/reply_markup/reply_keyboard_remove.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py b/pyrogram/client/types/reply_markup/reply_keyboard_remove.py index de32f740..3e2aebf5 100644 --- a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py +++ b/pyrogram/client/types/reply_markup/reply_keyboard_remove.py @@ -35,7 +35,7 @@ class ReplyKeyboardRemove(Object): keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. """ - ID = 0xb0700002 + ID = 0xb0700023 def __init__(self, selective: bool = None): self.selective = selective From be451a3bb2d055101c5440786ae1680fb30bf307 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 18:49:09 +0200 Subject: [PATCH 02/17] Rename parse_photos to parse_profile_photos --- pyrogram/client/ext/utils.py | 2 +- pyrogram/client/methods/users/get_user_profile_photos.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 2913c38b..3d2f88c1 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -757,7 +757,7 @@ def get_offset_date(dialogs): return 0 -def parse_photos(photos): +def parse_profile_photos(photos): if isinstance(photos, types.photos.Photos): total_count = len(photos.photos) else: diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 42fb84bb..5613c21d 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -48,7 +48,7 @@ class GetUserProfilePhotos(BaseClient): Raises: :class:`Error ` """ - return utils.parse_photos( + return utils.parse_profile_photos( self.send( functions.photos.GetUserPhotos( user_id=self.resolve_peer(user_id), From 5f87bbc962d35e33e0faeba5c06a3c0f2bc6e916 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:04:45 +0200 Subject: [PATCH 03/17] Add the new Photo type --- compiler/api/compiler.py | 9 +++---- pyrogram/client/types/__init__.py | 1 + pyrogram/client/types/photo.py | 41 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 pyrogram/client/types/photo.py diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index d1bf8cfa..7c1412d1 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,17 +494,16 @@ def start(): f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",") f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",") - f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") - f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") - f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",") f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",") f.write("\n 0xb0700020: \"pyrogram.client.types.reply_markup.InlineKeyboardMarkup\",") f.write("\n 0xb0700021: \"pyrogram.client.types.reply_markup.KeyboardButton\",") f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",") f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",") - - f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\"") + f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",") + f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") + f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") + f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") f.write("\n}\n") diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index acd001dd..84c12a44 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -31,6 +31,7 @@ from .location import Location from .message import Message from .message_entity import MessageEntity from .messages import Messages +from .photo import Photo from .photo_size import PhotoSize from .reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/photo.py new file mode 100644 index 00000000..39fb8d94 --- /dev/null +++ b/pyrogram/client/types/photo.py @@ -0,0 +1,41 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class Photo(Object): + """This object represents a Photo + + Args: + id (``str``): + Unique identifier for this photo. + + date (``int``): + Date the photo was sent in Unix time + + sizes (List of :obj:`PhotoSize ): + Available sizes of this photo + """ + + ID = 0xb0700027 + + def __init__(self, id: str, date: int, sizes: list): + self.id = id + self.date = date + self.sizes = sizes From 971299f59283278d296d365e2f125c5a9f97f58a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:05:08 +0200 Subject: [PATCH 04/17] PhotoSize won't store date info anymore --- pyrogram/client/types/photo_size.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/types/photo_size.py b/pyrogram/client/types/photo_size.py index 7e9b3cba..65691de0 100644 --- a/pyrogram/client/types/photo_size.py +++ b/pyrogram/client/types/photo_size.py @@ -32,18 +32,14 @@ class PhotoSize(Object): height (``int``): Photo height. - file_size (``int``, *optional*): + file_size (``int``): File size. - - date (``int``, *optional*): - Date the photo was sent in Unix time """ ID = 0xb0700005 - def __init__(self, file_id, width, height, file_size=None, date=None): - self.file_id = file_id # string - self.width = width # int - self.height = height # int - self.file_size = file_size # flags.0?int - self.date = date + def __init__(self, file_id: str, width: int, height: int, file_size: int): + self.file_id = file_id + self.width = width + self.height = height + self.file_size = file_size From fb10b3b0e7e767610a7774a7e933185c9046151e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:05:47 +0200 Subject: [PATCH 05/17] UserProfilePhoto.photos is now a list of Photo objects --- pyrogram/client/types/user_profile_photos.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/user_profile_photos.py b/pyrogram/client/types/user_profile_photos.py index 1b7ecbb4..c8ca9e39 100644 --- a/pyrogram/client/types/user_profile_photos.py +++ b/pyrogram/client/types/user_profile_photos.py @@ -26,12 +26,12 @@ class UserProfilePhotos(Object): total_count (``int``): Total number of profile pictures the target user has. - photos (List of List of :obj:`PhotoSize `): - Requested profile pictures (in up to 4 sizes each). + photos (List of :obj:`Photo `): + Requested profile pictures. """ ID = 0xb0700014 def __init__(self, total_count: int, photos: list): - self.total_count = total_count # int - self.photos = photos # Vector> + self.total_count = total_count + self.photos = photos From a3761144b37e24a0d1f956ea1d29e42c936f053a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:07:02 +0200 Subject: [PATCH 06/17] Use Photo as type for media messages --- pyrogram/client/ext/utils.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 3d2f88c1..105d0f0c 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -329,13 +329,23 @@ def parse_messages( ), width=size.w, height=size.h, - file_size=file_size, - date=photo.date + file_size=file_size ) photo_sizes.append(photo_size) - photo = photo_sizes + photo = pyrogram_types.Photo( + id=b64encode( + pack( + " Date: Thu, 28 Jun 2018 19:14:29 +0200 Subject: [PATCH 11/17] Add Photo type to docs --- docs/source/pyrogram/types/Photo.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/source/pyrogram/types/Photo.rst diff --git a/docs/source/pyrogram/types/Photo.rst b/docs/source/pyrogram/types/Photo.rst new file mode 100644 index 00000000..78fe13f4 --- /dev/null +++ b/docs/source/pyrogram/types/Photo.rst @@ -0,0 +1,5 @@ +Photo +===== + +.. autoclass:: pyrogram.Photo + :members: From 30497b0e91635a9808904aeb846a14b70fa6e289 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:59:26 +0200 Subject: [PATCH 12/17] Add delete_profile_photos method --- pyrogram/client/methods/users/__init__.py | 2 + .../methods/users/delete_profile_photos.py | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 pyrogram/client/methods/users/delete_profile_photos.py diff --git a/pyrogram/client/methods/users/__init__.py b/pyrogram/client/methods/users/__init__.py index 7a82667d..f7c32b3b 100644 --- a/pyrogram/client/methods/users/__init__.py +++ b/pyrogram/client/methods/users/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .delete_profile_photos import DeleteProfilePhotos from .get_me import GetMe from .get_user_profile_photos import GetUserProfilePhotos from .get_users import GetUsers @@ -23,6 +24,7 @@ from .get_users import GetUsers class Users( GetUserProfilePhotos, + DeleteProfilePhotos, GetUsers, GetMe ): diff --git a/pyrogram/client/methods/users/delete_profile_photos.py b/pyrogram/client/methods/users/delete_profile_photos.py new file mode 100644 index 00000000..47a6682a --- /dev/null +++ b/pyrogram/client/methods/users/delete_profile_photos.py @@ -0,0 +1,58 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from base64 import b64decode +from struct import unpack + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class DeleteProfilePhotos(BaseClient): + def delete_profile_photos(self, id: str or list): + """Use this method to delete your own profile photos + + Args: + id (``str`` | ``list``): + A single :obj:`Photo ` id as string or multiple ids as list of strings for deleting + more than one photos at once. + + Returns: + True on success. + + Raises: + :class:`Error ` + """ + id = id if isinstance(id, list) else [id] + input_photos = [] + + for i in id: + s = unpack(" Date: Thu, 28 Jun 2018 19:59:53 +0200 Subject: [PATCH 13/17] Add delete_profile_photos method to docs --- docs/source/pyrogram/Client.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 0000b35f..2fbd5879 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -42,6 +42,7 @@ Client send_chat_action download_media get_user_profile_photos + delete_profile_photos edit_message_text edit_message_caption edit_message_reply_markup From 29d45be0a5681445c42b34bb264f2f11ea24f10d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:00:48 +0200 Subject: [PATCH 14/17] Add Photo to types list --- docs/source/pyrogram/types/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index 2fc74e49..ff3de94e 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -9,6 +9,7 @@ Types Message MessageEntity Messages + Photo PhotoSize Audio Document From bae7b4c85127a6d8d0caf963c441912d1140cdd8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:02:31 +0200 Subject: [PATCH 15/17] Make Photo importable from the top level package --- pyrogram/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 96fb4a76..16204830 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,8 +29,8 @@ from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video, - VideoNote, Voice, CallbackQuery, Messages + Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, + Video, VideoNote, Voice, CallbackQuery, Messages ) from .client.types.reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, From b6206b7938431a24ed81aff35eced0643a44c26e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:03:50 +0200 Subject: [PATCH 16/17] Fix small docstring issue --- pyrogram/client/types/photo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/photo.py index 39fb8d94..f5494f13 100644 --- a/pyrogram/client/types/photo.py +++ b/pyrogram/client/types/photo.py @@ -29,7 +29,7 @@ class Photo(Object): date (``int``): Date the photo was sent in Unix time - sizes (List of :obj:`PhotoSize ): + sizes (List of :obj:`PhotoSize `): Available sizes of this photo """ From 6943e16636c04c0a31f1418caa7396a3a4b9a0d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:04:46 +0200 Subject: [PATCH 17/17] Change new_chat_photo type. It is now Photo --- pyrogram/client/types/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index b9048f1e..112bc0bf 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -132,7 +132,7 @@ class Message(Object): new_chat_title (``str``, *optional*): A chat title was changed to this value. - new_chat_photo (List of :obj:`PhotoSize `, *optional*): + new_chat_photo (:obj:`Photo `, *optional*): A chat photo was change to this value. delete_chat_photo (``bool``, *optional*):