Add .set_ bound methods to Chat

This commit is contained in:
Mendel E 2019-06-28 13:45:03 -04:00
parent 46bf382480
commit 54c8e24f48
2 changed files with 113 additions and 0 deletions

View File

@ -67,6 +67,9 @@ Chat
- :meth:`~Chat.archive`
- :meth:`~Chat.unarchive`
- :meth:`~Chat.set_title`
- :meth:`~Chat.set_description`
- :meth:`~Chat.set_photo`
User
^^^^
@ -134,6 +137,9 @@ Details
.. Chat
.. automethod:: Chat.archive()
.. automethod:: Chat.unarchive()
.. automethod:: Chat.set_title()
.. automethod:: Chat.set_description)
.. automethod:: Chat.set_photo()
.. User
.. automethod:: User.archive()

View File

@ -312,3 +312,110 @@ class Chat(Object):
"""
return self._client.unarchive_chats(self.id)
def set_title(self, title: str) -> bool:
"""Bound method *set_title* of :obj:`Chat`.
Use as a shortcut for:
.. code-block:: python
client.set_chat_title(
chat_id=chat_id,
title=title
)
Example:
.. code-block:: python
chat.set_title("Lounge")
Note:
In regular groups (non-supergroups), this method will only work if the "All Members Are Admins"
setting is off.
Parameters:
title (``str``):
New chat title, 1-255 characters.
Returns:
``bool``: True on success.
Raises:
RPCError: In case of Telegram RPC error.
ValueError: In case a chat_id belongs to user.
"""
return self._client.set_chat_title(
chat_id=self.id,
title=title
)
def set_description(self, description: str) -> bool:
"""Bound method *set_description* of :obj:`Chat`.
Use as a shortcut for:
.. code-block:: python
client.set_chat_description(
chat_id=chat_id,
description=description
)
Example:
.. code-block:: python
chat.set_chat_description("Don't spam!")
Parameters:
description (``str``):
New chat description, 0-255 characters.
Returns:
``bool``: True on success.
Raises:
RPCError: In case of Telegram RPC error.
ValueError If a chat_id doesn't belong to a supergroup or a channel.
"""
return self._client.set_chat_description(
chat_id=self.id,
description=description
)
def set_photo(self, photo: str) -> bool:
"""Bound method *set_photo* of :obj:`Chat`.
Use as a shortcut for:
.. code-block:: python
client.set_chat_photo(
chat_id=chat_id,
photo=photo
)
Example:
.. code-block:: python
chat.set_photo("photo.png")
Parameters:
photo (``str``):
New chat photo. You can pass a :obj:`Photo` id or a file path to upload a new photo.
Returns:
``bool``: True on success.
Raises:
RPCError: In case of a Telegram RPC error.
ValueError: if a chat_id belongs to user.
"""
return self._client.set_chat_photo(
chat_id=self.id,
photo=photo
)