From 54c8e24f483ea905d97161a6994c83aadfd0ac43 Mon Sep 17 00:00:00 2001 From: Mendel E Date: Fri, 28 Jun 2019 13:45:03 -0400 Subject: [PATCH] Add .set_ bound methods to Chat --- docs/source/api/bound-methods.rst | 6 ++ pyrogram/client/types/user_and_chats/chat.py | 107 +++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/docs/source/api/bound-methods.rst b/docs/source/api/bound-methods.rst index 83b3dbbe..d129ad16 100644 --- a/docs/source/api/bound-methods.rst +++ b/docs/source/api/bound-methods.rst @@ -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() diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 2d88d3ed..e99bccea 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -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 + )