From 8036da6e3252b9a5ad5a65d2879a22f5075ed4fa Mon Sep 17 00:00:00 2001 From: wulan17 Date: Thu, 5 Oct 2023 19:44:57 +0700 Subject: [PATCH] Pyrofork: Add StoryPrivacy Signed-off-by: wulan17 --- docs/source/api/enums/index.rst | 2 + pyrogram/enums/__init__.py | 2 + pyrogram/enums/story_privacy.py | 40 ++++++++++++++ pyrogram/types/messages_and_media/story.py | 63 +++++++++++++++++++++- 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 pyrogram/enums/story_privacy.py diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst index 8b685dd37..d7e1401b6 100644 --- a/docs/source/api/enums/index.rst +++ b/docs/source/api/enums/index.rst @@ -28,6 +28,7 @@ to apply only a valid value among the expected ones. NextCodeType UserStatus StoriesPrivacyRules + StoryPrivacy .. toctree:: :hidden: @@ -47,3 +48,4 @@ to apply only a valid value among the expected ones. NextCodeType UserStatus StoriesPrivacyRules + StoryPrivacy diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py index fcdeff5c5..76a13db6e 100644 --- a/pyrogram/enums/__init__.py +++ b/pyrogram/enums/__init__.py @@ -30,6 +30,7 @@ from .poll_type import PollType from .sent_code_type import SentCodeType from .stories_privacy_rules import StoriesPrivacyRules +from .story_privacy import StoryPrivacy from .user_status import UserStatus __all__ = [ @@ -47,5 +48,6 @@ 'PollType', 'SentCodeType', "StoriesPrivacyRules", + "StoryPrivacy", 'UserStatus' ] diff --git a/pyrogram/enums/story_privacy.py b/pyrogram/enums/story_privacy.py new file mode 100644 index 000000000..33200bae0 --- /dev/null +++ b/pyrogram/enums/story_privacy.py @@ -0,0 +1,40 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from enum import auto + +from .auto_name import AutoName + + +class StoryPrivacy(AutoName): + """Story peivacy type enumeration used in :obj:`~pyrogram.types.Story`.""" + + PUBLIC = auto() + "Public stories" + + CLOSE_FRIENDS = auto() + "Close_Friends stories" + + CONTACTS = auto() + "Contacts only stories" + + PRIVATE = auto() + "Private stories" + + NO_CONTACTS = auto() + "Hide stories from contacts" diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index 5d508c5f6..77e995058 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -86,9 +86,24 @@ class Story(Object, Update): views (:obj:`~pyrogram.types.StoryViews`, *optional*): Stories views. + + privacy (:obj:`~pyrogram.enums.StoryPrivacy`, *optional*): + Story privacy. + + allowed_chats (List of ``int``, *optional*): + List of chat_id which participant allowed to view the story. + + denied_chats (List of ``int``, *optional*): + List of chat_id which participant denied to view the story. + + allowed_users (List of ``int``, *optional*): + List of user_id whos allowed to view the story. + + denied_users (List of ``int``, *optional*): + List of user_id whos denied to view the story. """ - # TODO: Add Privacy + # TODO: Add Media Areas def __init__( self, @@ -112,7 +127,12 @@ def __init__( selected_contacts: bool = None, caption: str = None, caption_entities: List["types.MessageEntity"] = None, - views: "types.StoryViews" = None + views: "types.StoryViews" = None, + privacy: "enums.StoryPrivacy" = None, + allowed_users: List[int] = None, + denied_users: List[int] = None, + allowed_chats: List[int] = None, + denied_chats: List[int] = None ): super().__init__(client) @@ -135,6 +155,11 @@ def __init__( self.caption = caption self.caption_entities = caption_entities self.views = views + self.privay = privacy + self.allowed_users = allowed_users + self.denied_users = denied_users + self.allowed_chats = allowed_chats + self.denied_chats = denied_chats @staticmethod async def _parse( @@ -153,6 +178,11 @@ async def _parse( video = None from_user = None sender_chat = None + privacy = None + allowed_chats = None + allowed_users = None + denied_chats = None + denied_users = None if stories.media: if isinstance(stories.media, raw.types.MessageMediaPhoto): photo = types.Photo._parse(client, stories.media.photo, stories.media.ttl_seconds) @@ -181,6 +211,30 @@ async def _parse( from_user = client.me else: from_user = await client.get_users(peer.user_id) + + for priv in stories.privacy: + if isinstance(priv, raw.types.PrivacyValueAllowAll): + privacy = enums.StoryPrivacy.PUBLIC + elif isinstance(priv, raw.types.PrivacyValueAllowCloseFriends): + privacy = enums.StoryPrivacy.CLOSE_FRIENDS + elif isinstance(priv, raw.types.PrivacyValueAllowContacts): + privacy = enums.StoryPrivacy.CONTACTS + elif isinstance(priv, raw.types.PrivacyValueDisallowAll): + privacy = enums.StoryPrivacy.PRIVATE + elif isinstance(priv, raw.types.PrivacyValueDisallowContacts): + privacy = enums.StoryPrivacy.NO_CONTACTS + if isinstance(priv, raw.types.PrivacyValueAllowChatParticipants): + allowed_chats = [] + for chat in priv.chats: + allowed_chats.append(f"-100{chat}") + if isinstance(priv, raw.types.PrivacyValueDisallowChatParticipants): + denied_chats = [] + for chat in priv.chats: + denied_chats.append(f"-100{chat}") + if isinstance(priv, raw.types.PrivacyValueAllowUsers): + allowed_users = priv.users + if isinstance(priv, raw.types.PrivacyValueDisallowUsers): + denied_users = priv.users return Story( id=stories.id, @@ -202,6 +256,11 @@ async def _parse( caption=stories.caption, caption_entities=entities or None, views=types.StoryViews._parse(stories.views), + privacy=privacy, + allowed_chats=allowed_chats, + denied_chats=denied_chats, + allowed_users=allowed_users, + denied_users=denied_users, client=client )