diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c78a47ee..a707af07 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -450,6 +450,10 @@ def pyrogram_api(): Chat.unban_member Chat.restrict_member Chat.promote_member + Chat.get_member + Chat.get_members + Chat.iter_members + Chat.add_members Chat.join Chat.leave """, diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 46ff5662..914159e3 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union, List +from typing import Union, List, Generator, Optional import pyrogram from pyrogram.api import types @@ -725,3 +725,124 @@ class Chat(Object): """ return await self._client.export_chat_invite_link(self.id) + + async def get_member( + self, + user_id: Union[int, str], + ) -> "pyrogram.ChatMember": + """Bound method *get_member* of :obj:`Chat`. + + Use as a shortcut for: + + .. code-block:: python + + client.get_chat_member( + chat_id=chat_id, + user_id=user_id + ) + + Example: + .. code-block:: python + + chat.get_member(user_id) + + Returns: + :obj:`ChatMember`: On success, a chat member is returned. + """ + + return await self._client.get_chat_member( + self.id, + user_id=user_id + ) + + async def get_members( + self, + offset: int = 0, + limit: int = 200, + query: str = "", + filter: str = Filters.ALL + ) -> List["pyrogram.ChatMember"]: + """Bound method *get_members* of :obj:`Chat`. + + Use as a shortcut for: + + .. code-block:: python + + client.get_chat_members(chat_id) + + Example: + .. code-block:: python + # Get first 200 recent members + chat.get_members() + + Returns: + List of :obj:`ChatMember`: On success, a list of chat members is returned. + """ + + return await self._client.get_chat_members( + self.id, + offset=offset, + limit=limit, + query=query, + filter=filter + ) + + async def iter_members( + self, + limit: int = 0, + query: str = "", + filter: str = Filters.ALL + ) -> Optional[Generator["pyrogram.ChatMember", None, None]]: + """Bound method *iter_members* of :obj:`Chat`. + + Use as a shortcut for: + + .. code-block:: python + + for member in client.iter_chat_members(chat_id): + print(member.user.first_name) + + Example: + .. code-block:: python + + for member in chat.iter_members(): + print(member.user.first_name) + + Returns: + ``Generator``: A generator yielding :obj:`ChatMember` objects. + """ + + return self._client.iter_chat_members( + self.id, + limit=limit, + query=query, + filter=filter + ) + + async def add_members( + self, + user_ids: Union[Union[int, str], List[Union[int, str]]], + forward_limit: int = 100 + ) -> bool: + """Bound method *add_members* of :obj:`Chat`. + + Use as a shortcut for: + + .. code-block:: python + + client.add_chat_members(chat_id, user_id) + + Example: + .. code-block:: python + + chat.add_members(user_id) + + Returns: + ``bool``: On success, True is returned. + """ + + return await self._client.add_chat_members( + self.id, + user_ids=user_ids, + forward_limit=forward_limit + ) \ No newline at end of file