From 4bf52b8d03d611dce2a10f096be27cf4810f6c47 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Wed, 6 Dec 2023 11:53:26 +0300 Subject: [PATCH] Remove MessageStory type --- compiler/docs/compiler.py | 1 - pyrogram/types/messages_and_media/__init__.py | 3 +- pyrogram/types/messages_and_media/message.py | 27 ++++++++- .../types/messages_and_media/message_story.py | 59 ------------------- pyrogram/types/messages_and_media/story.py | 2 +- 5 files changed, 26 insertions(+), 66 deletions(-) delete mode 100644 pyrogram/types/messages_and_media/message_story.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index e03784a9488..ebf75959b31 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -457,7 +457,6 @@ def get_title_list(s: str) -> list: WebAppData MessageReactions ChatReactions - MessageStory Story StoryViews MyBoost diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 61658fa9588..4c8b5312dd4 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -51,7 +51,6 @@ from .web_app_data import WebAppData from .web_page import WebPage from .message_reactions import MessageReactions -from .message_story import MessageStory from .my_boost import MyBoost __all__ = [ @@ -60,5 +59,5 @@ "GeneralTopicUnhidden", "Game", "GiftCode", "Giveaway", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Story", "StoryViews", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", - "WebAppData", "MessageReactions", "MessageStory", "MyBoost" + "WebAppData", "MessageReactions", "MyBoost" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index fb54f5570ac..a6cd809589a 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -201,7 +201,7 @@ class Message(Object, Update): giveaway (:obj:`~pyrogram.types.Giveaway`, *optional*): Message is a giveaway, information about the giveaway. - story (:obj:`~pyrogram.types.MessageStory`, *optional*): + story (:obj:`~pyrogram.types.Story`, *optional*): Message is a story, information about the story. video (:obj:`~pyrogram.types.Video`, *optional*): @@ -415,7 +415,7 @@ def __init__( animation: "types.Animation" = None, game: "types.Game" = None, giveaway: "types.Giveaway" = None, - story: "types.MessageStory" = None, + story: "types.Story" = None, video: "types.Video" = None, voice: "types.Voice" = None, video_note: "types.VideoNote" = None, @@ -867,7 +867,28 @@ async def _parse( giveaway = types.Giveaway._parse(client, media, chats) media_type = enums.MessageMediaType.GIVEAWAY elif isinstance(media, raw.types.MessageMediaStory): - story = types.MessageStory._parse(client, media, users, chats) + if not media.story: + peer_id = utils.get_raw_peer_id(media.peer) + + if isinstance(media.peer, raw.types.PeerUser): + forward_from_chat = types.Chat._parse_user_chat(client, users[peer_id]) + else: + forward_from_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) + + forward_from_user = types.User._parse(client, users[peer_id]) + forward_sender_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) if not forward_from_user else None + forward_from_chat = forward_sender_chat if not forward_from_user else types.Chat._parse_user_chat(client, users[peer_id]) + + story = types.Story( + client=client, + id=media.id, + from_user=forward_from_user, + sender_chat=forward_sender_chat, + chat=forward_from_chat + ) + else: + await types.Story._parse(client, media.story, users, chats, media.peer) + media_type = enums.MessageMediaType.STORY elif isinstance(media, raw.types.MessageMediaDocument): doc = media.document diff --git a/pyrogram/types/messages_and_media/message_story.py b/pyrogram/types/messages_and_media/message_story.py deleted file mode 100644 index 11a6dad5d95..00000000000 --- a/pyrogram/types/messages_and_media/message_story.py +++ /dev/null @@ -1,59 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-present Dan -# -# This file is part of Pyrogram. -# -# Pyrogram 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. -# -# Pyrogram 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 Pyrogram. If not, see . - -import pyrogram -from pyrogram import raw, types, utils -from ..object import Object - - -class MessageStory(Object): - """Contains information about a forwarded story. - - Parameters: - chat (:obj:`~pyrogram.types.Chat`): - Conversation the story belongs to. - - story_id (``int``): - Unique story identifier. - - """ - - def __init__( - self, - *, - chat: "types.Chat", - story_id: int - ): - super().__init__() - - self.chat = chat - self.story_id = story_id - - @staticmethod - def _parse(client: "pyrogram.Client", message_story: "raw.types.MessageMediaStory", users, chats) -> "MessageStory": - peer_id = utils.get_raw_peer_id(message_story.peer) - - if isinstance(message_story.peer, raw.types.PeerChannel): - chat = types.Chat._parse_channel_chat(client, chats.get(peer_id, None)) - else: - chat = types.Chat._parse_user_chat(client, users.get(peer_id, None)) - - return MessageStory( - chat=chat, - story_id=message_story.id - ) diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index 86e53036992..afd66934983 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -135,7 +135,7 @@ def __init__( forward_from_chat: "types.Chat" = None, forward_from_story_id: int = None, expire_date: datetime = None, - media: "enums.MessageMediaType", + media: "enums.MessageMediaType" = None, has_protected_content: bool = None, photo: "types.Photo" = None, video: "types.Video" = None,