mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: Add forward_from field to Story
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
97d5354ad2
commit
33d9fef0fb
4 changed files with 96 additions and 2 deletions
|
|
@ -473,6 +473,7 @@ def pyrogram_api():
|
|||
Stories
|
||||
Story
|
||||
StoryDeleted
|
||||
StoryForwardHeader
|
||||
StorySkipped
|
||||
StoriesPrivacyRules
|
||||
StoryViews
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ from .message_reactions import MessageReactions
|
|||
from .message_story import MessageStory
|
||||
from .story import Story
|
||||
from .story_deleted import StoryDeleted
|
||||
from .story_forward_header import StoryForwardHeader
|
||||
from .story_skipped import StorySkipped
|
||||
from .story_views import StoryViews
|
||||
from .exported_story_link import ExportedStoryLink
|
||||
|
|
@ -54,5 +55,5 @@ from .exported_story_link import ExportedStoryLink
|
|||
__all__ = [
|
||||
"Animation", "Audio", "Contact", "Document", "Game", "Giveaway", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -87,6 +87,10 @@ class Story(Object, Update):
|
|||
views (:obj:`~pyrogram.types.StoryViews`, *optional*):
|
||||
Stories views.
|
||||
|
||||
forward_from (:obj:`~pyrogram.types.StoryForwardHeader`, *optional*):
|
||||
Story is a forwarded story.
|
||||
Information about the original story.
|
||||
|
||||
privacy (:obj:`~pyrogram.enums.StoryPrivacy`, *optional*):
|
||||
Story privacy.
|
||||
|
||||
|
|
@ -123,6 +127,7 @@ class Story(Object, Update):
|
|||
caption_entities: List["types.MessageEntity"] = None,
|
||||
views: "types.StoryViews" = None,
|
||||
privacy: "enums.StoryPrivacy" = None,
|
||||
forward_from: "types.StoryForwardHeader" = None,
|
||||
allowed_users: List[int] = None,
|
||||
denied_users: List[int] = None,
|
||||
#allowed_chats: List[int] = None,
|
||||
|
|
@ -150,6 +155,7 @@ class Story(Object, Update):
|
|||
self.caption_entities = caption_entities
|
||||
self.views = views
|
||||
self.privay = privacy
|
||||
self.forward_from = forward_from
|
||||
self.allowed_users = allowed_users
|
||||
self.denied_users = denied_users
|
||||
#self.allowed_chats = allowed_chats
|
||||
|
|
@ -173,6 +179,7 @@ class Story(Object, Update):
|
|||
from_user = None
|
||||
sender_chat = None
|
||||
privacy = None
|
||||
forward_from = None
|
||||
#allowed_chats = None
|
||||
allowed_users = None
|
||||
#denied_chats = None
|
||||
|
|
@ -205,7 +212,7 @@ 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
|
||||
|
|
@ -231,6 +238,9 @@ class Story(Object, Update):
|
|||
if isinstance(priv, raw.types.PrivacyValueDisallowUsers):
|
||||
denied_users = priv.users
|
||||
|
||||
if stories.fwd_from is not None:
|
||||
forward_from = await types.StoryForwardHeader._parse(client, stories.fwd_from)
|
||||
|
||||
return Story(
|
||||
id=stories.id,
|
||||
from_user=from_user,
|
||||
|
|
@ -252,6 +262,7 @@ class Story(Object, Update):
|
|||
caption_entities=entities or None,
|
||||
views=types.StoryViews._parse(stories.views),
|
||||
privacy=privacy,
|
||||
forward_from=forward_from,
|
||||
#allowed_chats=allowed_chats,
|
||||
#denied_chats=denied_chats,
|
||||
allowed_users=allowed_users,
|
||||
|
|
|
|||
81
pyrogram/types/messages_and_media/story_forward_header.py
Normal file
81
pyrogram/types/messages_and_media/story_forward_header.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# 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/>.
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class StoryForwardHeader(Object):
|
||||
"""Contains information about origin of forwarded story.
|
||||
|
||||
|
||||
Parameters:
|
||||
user (:obj:`~pyrogram.types.User`, *optional*):
|
||||
Sender of the story.
|
||||
|
||||
sender_name (``str``, *optional*):
|
||||
For stories forwarded from users who have hidden their accounts, name of the user.
|
||||
|
||||
chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
||||
Sender of the story. If the story is from channel.
|
||||
|
||||
story_id (``int``):
|
||||
Unique identifier for the original story.
|
||||
|
||||
is_modified (``bool``):
|
||||
True, if the story is modified.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, *,
|
||||
user: "types.User" = None,
|
||||
sender_name: str = None,
|
||||
chat: "types.Chat" = None,
|
||||
story_id: int = None,
|
||||
is_modified: bool = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.user = user
|
||||
self.sender_name = sender_name
|
||||
self.chat = chat
|
||||
self.story_id = story_id
|
||||
self.is_modified = is_modified
|
||||
|
||||
async def _parse(
|
||||
client: "pyrogram.Client",
|
||||
fwd_header: "raw.types.StoryFwdHeader"
|
||||
) -> "StoryForwardHeader":
|
||||
user = None
|
||||
chat = None
|
||||
if fwd_header.from_peer is not None:
|
||||
if isinstance(fwd_header.from_peer, raw.types.PeerChannel):
|
||||
chat = await client.get_chat(utils.get_channel_id(fwd_header.from_peer.channel_id))
|
||||
elif isinstance(fwd_header.from_peer, raw.types.InputPeerSelf):
|
||||
user = client.me
|
||||
else:
|
||||
user = await client.get_users(fwd_header.from_peer.user_id)
|
||||
|
||||
return StoryForwardHeader(
|
||||
user=user,
|
||||
sender_name=fwd_header.from_name,
|
||||
chat=chat,
|
||||
story_id=fwd_header.story_id,
|
||||
is_modified=fwd_header.modified
|
||||
)
|
||||
Loading…
Reference in a new issue