Skip to content

Commit 54c8e24

Browse files
committed
Add .set_ bound methods to Chat
1 parent 46bf382 commit 54c8e24

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

docs/source/api/bound-methods.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Chat
6767

6868
- :meth:`~Chat.archive`
6969
- :meth:`~Chat.unarchive`
70+
- :meth:`~Chat.set_title`
71+
- :meth:`~Chat.set_description`
72+
- :meth:`~Chat.set_photo`
7073

7174
User
7275
^^^^
@@ -134,6 +137,9 @@ Details
134137
.. Chat
135138
.. automethod:: Chat.archive()
136139
.. automethod:: Chat.unarchive()
140+
.. automethod:: Chat.set_title()
141+
.. automethod:: Chat.set_description)
142+
.. automethod:: Chat.set_photo()
137143

138144
.. User
139145
.. automethod:: User.archive()

pyrogram/client/types/user_and_chats/chat.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,110 @@ def unarchive(self):
312312
"""
313313

314314
return self._client.unarchive_chats(self.id)
315+
316+
def set_title(self, title: str) -> bool:
317+
"""Bound method *set_title* of :obj:`Chat`.
318+
319+
Use as a shortcut for:
320+
321+
.. code-block:: python
322+
323+
client.set_chat_title(
324+
chat_id=chat_id,
325+
title=title
326+
)
327+
328+
Example:
329+
.. code-block:: python
330+
331+
chat.set_title("Lounge")
332+
333+
Note:
334+
In regular groups (non-supergroups), this method will only work if the "All Members Are Admins"
335+
setting is off.
336+
337+
Parameters:
338+
title (``str``):
339+
New chat title, 1-255 characters.
340+
341+
Returns:
342+
``bool``: True on success.
343+
344+
Raises:
345+
RPCError: In case of Telegram RPC error.
346+
ValueError: In case a chat_id belongs to user.
347+
"""
348+
349+
return self._client.set_chat_title(
350+
chat_id=self.id,
351+
title=title
352+
)
353+
354+
def set_description(self, description: str) -> bool:
355+
"""Bound method *set_description* of :obj:`Chat`.
356+
357+
Use as a shortcut for:
358+
359+
.. code-block:: python
360+
361+
client.set_chat_description(
362+
chat_id=chat_id,
363+
description=description
364+
)
365+
366+
Example:
367+
.. code-block:: python
368+
369+
chat.set_chat_description("Don't spam!")
370+
371+
Parameters:
372+
description (``str``):
373+
New chat description, 0-255 characters.
374+
375+
Returns:
376+
``bool``: True on success.
377+
378+
Raises:
379+
RPCError: In case of Telegram RPC error.
380+
ValueError If a chat_id doesn't belong to a supergroup or a channel.
381+
"""
382+
383+
return self._client.set_chat_description(
384+
chat_id=self.id,
385+
description=description
386+
)
387+
388+
389+
def set_photo(self, photo: str) -> bool:
390+
"""Bound method *set_photo* of :obj:`Chat`.
391+
392+
Use as a shortcut for:
393+
394+
.. code-block:: python
395+
396+
client.set_chat_photo(
397+
chat_id=chat_id,
398+
photo=photo
399+
)
400+
401+
Example:
402+
.. code-block:: python
403+
404+
chat.set_photo("photo.png")
405+
406+
Parameters:
407+
photo (``str``):
408+
New chat photo. You can pass a :obj:`Photo` id or a file path to upload a new photo.
409+
410+
Returns:
411+
``bool``: True on success.
412+
413+
Raises:
414+
RPCError: In case of a Telegram RPC error.
415+
ValueError: if a chat_id belongs to user.
416+
"""
417+
418+
return self._client.set_chat_photo(
419+
chat_id=self.id,
420+
photo=photo
421+
)

0 commit comments

Comments
 (0)