From 93018a7f6cea7ef099cb0d1ee3957b5cf3c1c458 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 11:03:07 +0200 Subject: [PATCH 1/5] Add set_profile_photo method --- pyrogram/client/methods/users/__init__.py | 2 + .../client/methods/users/set_profile_photo.py | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 pyrogram/client/methods/users/set_profile_photo.py diff --git a/pyrogram/client/methods/users/__init__.py b/pyrogram/client/methods/users/__init__.py index f7c32b3b..9813b744 100644 --- a/pyrogram/client/methods/users/__init__.py +++ b/pyrogram/client/methods/users/__init__.py @@ -20,10 +20,12 @@ from .delete_profile_photos import DeleteProfilePhotos from .get_me import GetMe from .get_user_profile_photos import GetUserProfilePhotos from .get_users import GetUsers +from .set_profile_photo import SetProfilePhoto class Users( GetUserProfilePhotos, + SetProfilePhoto, DeleteProfilePhotos, GetUsers, GetMe diff --git a/pyrogram/client/methods/users/set_profile_photo.py b/pyrogram/client/methods/users/set_profile_photo.py new file mode 100644 index 00000000..8ed9dc7b --- /dev/null +++ b/pyrogram/client/methods/users/set_profile_photo.py @@ -0,0 +1,47 @@ +# 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 import functions +from ...ext import BaseClient + + +class SetProfilePhoto(BaseClient): + def set_profile_photo(self, photo: str): + """Use this method to set a new profile photo. + + This method only works for Users. Bots profile photos must be set using BotFather. + + Args: + photo (``str``): + Profile photo to set. + Pass a file path as string to upload a new photo that exists on your local machine. + + Returns: + True on success. + + Raises: + :class:`Error ` + """ + + return bool( + self.send( + functions.photos.UploadProfilePhoto( + self.save_file(photo) + ) + ) + ) From 8fc5b8a545df80cf1097f676282e51bbee4d15ee Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:43:54 +0200 Subject: [PATCH 2/5] Rename set_profile_photo to set_user_profile_photo --- pyrogram/client/methods/users/__init__.py | 4 ++-- .../{set_profile_photo.py => set_user_profile_photo.py} | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) rename pyrogram/client/methods/users/{set_profile_photo.py => set_user_profile_photo.py} (84%) diff --git a/pyrogram/client/methods/users/__init__.py b/pyrogram/client/methods/users/__init__.py index 9813b744..ed6f1a83 100644 --- a/pyrogram/client/methods/users/__init__.py +++ b/pyrogram/client/methods/users/__init__.py @@ -20,12 +20,12 @@ from .delete_profile_photos import DeleteProfilePhotos from .get_me import GetMe from .get_user_profile_photos import GetUserProfilePhotos from .get_users import GetUsers -from .set_profile_photo import SetProfilePhoto +from .set_user_profile_photo import SetUserProfilePhoto class Users( GetUserProfilePhotos, - SetProfilePhoto, + SetUserProfilePhoto, DeleteProfilePhotos, GetUsers, GetMe diff --git a/pyrogram/client/methods/users/set_profile_photo.py b/pyrogram/client/methods/users/set_user_profile_photo.py similarity index 84% rename from pyrogram/client/methods/users/set_profile_photo.py rename to pyrogram/client/methods/users/set_user_profile_photo.py index 8ed9dc7b..5167348f 100644 --- a/pyrogram/client/methods/users/set_profile_photo.py +++ b/pyrogram/client/methods/users/set_user_profile_photo.py @@ -20,11 +20,12 @@ from pyrogram.api import functions from ...ext import BaseClient -class SetProfilePhoto(BaseClient): - def set_profile_photo(self, photo: str): - """Use this method to set a new profile photo. +class SetUserProfilePhoto(BaseClient): + def set_user_profile_photo(self, photo: str): + """Use this method to set a new user profile photo. - This method only works for Users. Bots profile photos must be set using BotFather. + This method only works for Users. + Bots profile photos must be set using BotFather. Args: photo (``str``): From 29201674ef03cc3c2bdab28d1e34171e5d5cca4f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:45:20 +0200 Subject: [PATCH 3/5] Rename delete_profile_photos to delete_user_profile_photos For consistency with other method names --- pyrogram/client/methods/users/__init__.py | 4 ++-- ...delete_profile_photos.py => delete_user_profile_photos.py} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename pyrogram/client/methods/users/{delete_profile_photos.py => delete_user_profile_photos.py} (94%) diff --git a/pyrogram/client/methods/users/__init__.py b/pyrogram/client/methods/users/__init__.py index ed6f1a83..11f51d19 100644 --- a/pyrogram/client/methods/users/__init__.py +++ b/pyrogram/client/methods/users/__init__.py @@ -16,7 +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 .delete_user_profile_photos import DeleteUserProfilePhotos from .get_me import GetMe from .get_user_profile_photos import GetUserProfilePhotos from .get_users import GetUsers @@ -26,7 +26,7 @@ from .set_user_profile_photo import SetUserProfilePhoto class Users( GetUserProfilePhotos, SetUserProfilePhoto, - DeleteProfilePhotos, + DeleteUserProfilePhotos, GetUsers, GetMe ): diff --git a/pyrogram/client/methods/users/delete_profile_photos.py b/pyrogram/client/methods/users/delete_user_profile_photos.py similarity index 94% rename from pyrogram/client/methods/users/delete_profile_photos.py rename to pyrogram/client/methods/users/delete_user_profile_photos.py index 47a6682a..58c2deb4 100644 --- a/pyrogram/client/methods/users/delete_profile_photos.py +++ b/pyrogram/client/methods/users/delete_user_profile_photos.py @@ -23,8 +23,8 @@ from pyrogram.api import functions, types from ...ext import BaseClient -class DeleteProfilePhotos(BaseClient): - def delete_profile_photos(self, id: str or list): +class DeleteUserProfilePhotos(BaseClient): + def delete_user_profile_photos(self, id: str or list): """Use this method to delete your own profile photos Args: From 22998af784a7d2cb6db0b0a423d492488e529da1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:45:39 +0200 Subject: [PATCH 4/5] Fix docstrings --- pyrogram/client/methods/users/set_user_profile_photo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/users/set_user_profile_photo.py b/pyrogram/client/methods/users/set_user_profile_photo.py index 5167348f..b107a968 100644 --- a/pyrogram/client/methods/users/set_user_profile_photo.py +++ b/pyrogram/client/methods/users/set_user_profile_photo.py @@ -22,7 +22,7 @@ from ...ext import BaseClient class SetUserProfilePhoto(BaseClient): def set_user_profile_photo(self, photo: str): - """Use this method to set a new user profile photo. + """Use this method to set a new profile photo. This method only works for Users. Bots profile photos must be set using BotFather. From 1f5f339f6f9e04f75309a3fcd99f8f0b08380598 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:49:12 +0200 Subject: [PATCH 5/5] Reflect changes to docs --- docs/source/pyrogram/Client.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 1cd1a072..72844987 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -96,7 +96,8 @@ Users get_me get_users get_user_profile_photos - delete_profile_photos + set_user_profile_photos + delete_userprofile_photos Contacts --------