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] 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) + ) + ) + )