Skip to content

Commit

Permalink
Add is_public parameter to set_profile_photo and minor fixes (Mayuri-…
Browse files Browse the repository at this point in the history
…Chan#35)

* Fix invalid usage of input_message_content.write method (without await).

Signed-off-by: Aliwoto <[email protected]>

* Fix promote_chat_member using can_post_stories for edit_story permission.

Signed-off-by: Aliwoto <[email protected]>

* Refactor get_forum_topics_by_id method and make sure to pass messages parameter to it (if it exists).

Signed-off-by: Aliwoto <[email protected]>

* Add fallback parameter to set_profile_photo method.

Signed-off-by: Aliwoto <[email protected]>

* Fix download_media method not checking for file_id.

Signed-off-by: Aliwoto <[email protected]>

* Rename fallback to is_public

* Revert get_forum_topics_by_id.py

---------

Signed-off-by: Aliwoto <[email protected]>
Co-authored-by: KurimuzonAkuma <[email protected]>
Signed-off-by: eyMarv <[email protected]>
  • Loading branch information
2 people authored and eyMarv committed Apr 5, 2024
1 parent 440ee82 commit d8d7946
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pyrogram/methods/messages/download_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ async def download_media(
# Download from file id
await app.download_media(message.photo.file_id)
# Download document of a message
await app.download_media(message.document)
# Keep track of the progress while downloading
async def progress(current, total):
print(f"{current * 100 / total:.1f}%")
Expand Down Expand Up @@ -141,6 +144,8 @@ async def progress(current, total):
raise ValueError("This message doesn't contain any downloadable media")
else:
media = message
elif hasattr(message, "file_id"):
media = getattr(message, "file_id")

if isinstance(media, str):
file_id_str = media
Expand Down
19 changes: 15 additions & 4 deletions pyrogram/methods/users/set_profile_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union, BinaryIO
from typing import Union, BinaryIO, Optional

import pyrogram
from pyrogram import raw
Expand All @@ -26,8 +26,9 @@ class SetProfilePhoto:
async def set_profile_photo(
self: "pyrogram.Client",
*,
photo: Union[str, BinaryIO] = None,
video: Union[str, BinaryIO] = None,
photo: Optional[Union[str, BinaryIO]] = None,
video: Optional[Union[str, BinaryIO]] = None,
is_public: Optional[bool] = None
) -> bool:
"""Set a new profile photo or video (H.264/MPEG-4 AVC video, max 5 seconds).
Expand All @@ -52,6 +53,11 @@ async def set_profile_photo(
Pass a file path as string to upload a new video that exists on your local machine or
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
is_public (``bool``, *optional*):
If set to True, the chosen profile photo will be shown to users that can't display
your main profile photo due to your privacy settings.
Defaults to None.
Returns:
``bool``: True on success.
Expand All @@ -63,12 +69,17 @@ async def set_profile_photo(
# Set a new profile video
await app.set_profile_photo(video="new_video.mp4")
# Set/update your account's public profile photo
await app.set_profile_photo(photo="new_photo.jpg", is_public=True)
"""

return bool(
await self.invoke(
raw.functions.photos.UploadProfilePhoto(
file=await self.save_file(photo), video=await self.save_file(video)
fallback=is_public,
file=await self.save_file(photo),
video=await self.save_file(video)
)
)
)

0 comments on commit d8d7946

Please sign in to comment.