From 850b79315f12445e9f03db324cbdf9ed8fe859c7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 4 Apr 2020 23:47:09 +0200 Subject: [PATCH 1/2] Fix ttl_seconds not being parsed correctly --- pyrogram/client/types/messages_and_media/message.py | 2 +- pyrogram/client/types/messages_and_media/photo.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 451e8c25..7b99cbc5 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -523,7 +523,7 @@ class Message(Object, Update): if media: if isinstance(media, types.MessageMediaPhoto): - photo = Photo._parse(client, media) + photo = Photo._parse(client, media.photo, media.ttl_seconds) elif isinstance(media, types.MessageMediaGeo): location = Location._parse(client, media.geo) elif isinstance(media, types.MessageMediaContact): diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py index 1edfb4e2..235f4931 100644 --- a/pyrogram/client/types/messages_and_media/photo.py +++ b/pyrogram/client/types/messages_and_media/photo.py @@ -80,9 +80,7 @@ class Photo(Object): self.thumbs = thumbs @staticmethod - def _parse(client, media_photo: types.MessageMediaPhoto) -> "Photo": - photo = media_photo.photo - + def _parse(client, photo: types.Photo, ttl_seconds: int = None) -> "Photo": if isinstance(photo, types.Photo): big = photo.sizes[-1] @@ -98,7 +96,7 @@ class Photo(Object): file_ref=encode_file_ref(photo.file_reference), width=big.w, height=big.h, - ttl_seconds=media_photo.ttl_seconds, + ttl_seconds=ttl_seconds, file_size=big.size, date=photo.date, thumbs=Thumbnail._parse(client, photo), From 207d451a01ac59f24140add452915f478a307912 Mon Sep 17 00:00:00 2001 From: Real Phoenix <51527258+rsktg@users.noreply.github.com> Date: Mon, 6 Apr 2020 14:22:38 +0200 Subject: [PATCH 2/2] Add more Chat bound methods (#383) * Add more bound methods Bound methods for get_chat_member, get_chat_members, iter_chat_members, add_chat_members * Update compiler.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- compiler/docs/compiler.py | 4 + pyrogram/client/types/user_and_chats/chat.py | 133 +++++++++++++++++-- 2 files changed, 128 insertions(+), 9 deletions(-) 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 3829e303..5e1f18fa 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 @@ -566,15 +566,8 @@ class Chat(Object): return self._client.restrict_chat_member( chat_id=self.id, user_id=user_id, + permissions=permissions, until_date=until_date, - can_send_messages=permissions.can_send_messages, - can_send_media_messages=permissions.can_send_media_messages, - can_send_other_messages=permissions.can_send_other_messages, - can_add_web_page_previews=permissions.can_add_web_page_previews, - can_send_polls=permissions.can_send_polls, - can_change_info=permissions.can_change_info, - can_invite_users=permissions.can_invite_users, - can_pin_messages=permissions.can_pin_messages ) def promote_member( @@ -725,3 +718,125 @@ class Chat(Object): """ return self._client.export_chat_invite_link(self.id) + + 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 self._client.get_chat_member( + self.id, + user_id=user_id + ) + + def get_members( + self, + offset: int = 0, + limit: int = 200, + query: str = "", + filter: str = "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 self._client.get_chat_members( + self.id, + offset=offset, + limit=limit, + query=query, + filter=filter + ) + + def iter_members( + self, + limit: int = 0, + query: str = "", + filter: str = "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 + ) + + 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 self._client.add_chat_members( + self.id, + user_ids=user_ids, + forward_limit=forward_limit + )