From d99c3f511cc3dfeb27dd75098436639a512b03b1 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Wed, 6 Dec 2023 12:42:39 +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 | 12 +++- .../types/messages_and_media/message_story.py | 59 ------------------- pyrogram/types/messages_and_media/story.py | 4 +- 5 files changed, 13 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 e03784a9..ebf75959 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -457,7 +457,6 @@ def pyrogram_api(): 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 61658fa9..4c8b5312 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -51,7 +51,6 @@ from .voice import Voice 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 @@ __all__ = [ "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 fb54f557..abb2ec42 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 @@ class Message(Object, Update): 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,13 @@ class Message(Object, Update): 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: + story = await client.get_stories(utils.get_peer_id(media.peer), media.id) + if not story: + story = await types.Story._parse(client, media, users, chats, media.peer) + else: + story = 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 11a6dad5..00000000 --- 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 86e53036..d7b38a0a 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -135,7 +135,7 @@ class Story(Object, Update): 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, @@ -239,6 +239,8 @@ class Story(Object, Update): return Story(client=client, id=story.id, deleted=True, from_user=from_user, sender_chat=sender_chat, chat=chat) if isinstance(story, raw.types.StoryItemSkipped): return Story(client=client, id=story.id, skipped=True, from_user=from_user, sender_chat=sender_chat, chat=chat) + if isinstance(story, raw.types.MessageMediaStory): + return Story(client=client, id=story.id, from_user=from_user, sender_chat=sender_chat, chat=chat) forward_from = None forward_sender_name = None