Pyrofork: Add StoryPrivacy

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2023-10-05 19:44:57 +07:00
parent 55abd409f3
commit 8036da6e32
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
4 changed files with 105 additions and 2 deletions

View file

@ -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

View file

@ -30,6 +30,7 @@ from .parse_mode import ParseMode
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 @@ __all__ = [
'PollType',
'SentCodeType',
"StoriesPrivacyRules",
"StoryPrivacy",
'UserStatus'
]

View file

@ -0,0 +1,40 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
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"

View file

@ -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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
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
)