Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyrogram/methods/chats/set_chat_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ async def set_chat_photo(
# Set chat photo using a local file
await app.set_chat_photo(chat_id, photo="photo.jpg")

# Set chat photo using an exiting Photo file_id
# Set chat photo using an existing Photo file_id
await app.set_chat_photo(chat_id, photo=photo.file_id)


# Set chat video using a local file
await app.set_chat_photo(chat_id, video="video.mp4")

# Set chat photo using an exiting Video file_id
# Set chat photo using an existing Video file_id
await app.set_chat_photo(chat_id, video=video.file_id)
"""
peer = await self.resolve_peer(chat_id)
Expand Down
41 changes: 35 additions & 6 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
from typing import Union, List, Optional, AsyncGenerator
from typing import Union, List, Optional, AsyncGenerator, BinaryIO

import pyrogram
from pyrogram import raw, enums
Expand Down Expand Up @@ -477,7 +477,13 @@ async def set_description(self, description: str) -> bool:
description=description
)

async def set_photo(self, photo: str) -> bool:
async def set_photo(
self,
*,
photo: Union[str, BinaryIO] = None,
video: Union[str, BinaryIO] = None,
video_start_ts: float = None,
) -> bool:
"""Bound method *set_photo* of :obj:`~pyrogram.types.Chat`.

Use as a shortcut for:
Expand All @@ -492,11 +498,32 @@ async def set_photo(self, photo: str) -> bool:
Example:
.. code-block:: python

await chat.set_photo("photo.png")
# Set chat photo using a local file
await chat.set_photo(photo="photo.jpg")

# Set chat photo using an existing Photo file_id
await chat.set_photo(photo=photo.file_id)


# Set chat video using a local file
await chat.set_photo(video="video.mp4")

# Set chat photo using an existing Video file_id
await chat.set_photo(video=video.file_id)

Parameters:
photo (``str``):
New chat photo. You can pass a :obj:`~pyrogram.types.Photo` id or a file path to upload a new photo.
photo (``str`` | ``BinaryIO``, *optional*):
New chat photo. You can pass a :obj:`~pyrogram.types.Photo` file_id, a file path to upload a new photo
from your local machine or a binary file-like object with its attribute
".name" set for in-memory uploads.

video (``str`` | ``BinaryIO``, *optional*):
New chat video. You can pass a :obj:`~pyrogram.types.Video` file_id, a file path to upload a new video
from your local machine or a binary file-like object with its attribute
".name" set for in-memory uploads.

video_start_ts (``float``, *optional*):
The timestamp in seconds of the video frame to use as photo profile preview.

Returns:
``bool``: True on success.
Expand All @@ -508,7 +535,9 @@ async def set_photo(self, photo: str) -> bool:

return await self._client.set_chat_photo(
chat_id=self.id,
photo=photo
photo=photo,
video=video,
video_start_ts=video_start_ts
)

async def ban_member(
Expand Down