From 6711e2378d3f8169982dedf24dc28e6c955a7edd Mon Sep 17 00:00:00 2001 From: shriMADhav U k Date: Thu, 22 Feb 2024 17:30:44 +0100 Subject: [PATCH] Added missing attributes to the class Story --- docs/source/releases/changes-in-this-fork.rst | 1 + pyrogram/types/messages_and_media/message.py | 2 +- pyrogram/types/messages_and_media/story.py | 79 ++++++++++++++++++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/docs/source/releases/changes-in-this-fork.rst b/docs/source/releases/changes-in-this-fork.rst index 14dd6556f..d5e40414c 100644 --- a/docs/source/releases/changes-in-this-fork.rst +++ b/docs/source/releases/changes-in-this-fork.rst @@ -12,6 +12,7 @@ it can take advantage of new goodies! | Leaked Scheme layer | +------------------------+ +- Added missing attributes to the class :obj:`~pyrogram.types.Story` when it is available. - Added the field ``reply_to_story`` to the class :obj:`~pyrogram.types.Message`. - Added the field ``user_chat_id`` to the class :obj:`~pyrogram.types.ChatJoinRequest`. - Added the field ``switch_inline_query_chosen_chat`` of the type :obj:`~pyrogram.types.SwitchInlineQueryChosenChat` to the class :obj:`~pyrogram.types.InlineKeyboardButton`, which allows bots to switch to inline mode in a chosen chat of the given type. diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 4563d7f11..ce604b403 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3461,7 +3461,7 @@ async def copy( if self.service: log.warning("Service messages cannot be copied. chat_id: %s, message_id: %s", self.chat.id, self.id) - elif self.game and not await self._client.storage.is_bot(): + elif self.game and not self._client.me.is_bot: log.warning("Users cannot send messages with Game media type. chat_id: %s, message_id: %s", self.chat.id, self.id) elif self.empty: diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index 7509a3190..dff25f05c 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -20,10 +20,11 @@ from typing import List import pyrogram -from pyrogram import raw, utils, types +from pyrogram import raw, utils, types, enums from ..object import Object from ..update import Update from .message import Str +from pyrogram.errors import RPCError class Story(Object, Update): @@ -140,6 +141,23 @@ async def _parse( ) -> "Video": story_id = None chat = None + + date = None + expire_date = None + media = None + has_protected_content = None + photo = None + video = None + edited = None + pinned = None + caption = None + caption_entities = None + views = None + forwards = None + reactions = None + skipped = None + deleted = None + if story_media: if story_media.peer: raw_peer_id = utils.get_peer_id(story_media.peer) @@ -150,9 +168,66 @@ async def _parse( raw_peer_id = utils.get_peer_id(reply_story.peer) chat = await client.get_chat(raw_peer_id) story_id = getattr(reply_story, "story_id", None) + if story_id and not client.me.is_bot: + try: + story_item = ( + await client.invoke( + raw.functions.stories.GetStoriesByID( + peer=await client.resolve_peer(raw_peer_id), + id=[story_id] + ) + ) + ).stories[0] + except (RPCError,IndexError): + pass + else: + if isinstance(story_item, raw.types.StoryItemDeleted): + deleted = True + elif isinstance(story_item, raw.types.StoryItemSkipped): + skipped = True + else: + date = utils.timestamp_to_datetime(story_item.date) + expire_date = utils.timestamp_to_datetime(story_item.expire_date) + if isinstance(story_item.media, raw.types.MessageMediaPhoto): + photo = types.Photo._parse(client, story_item.media.photo, story_item.media.ttl_seconds) + media = enums.MessageMediaType.PHOTO + elif isinstance(story_item.media, raw.types.MessageMediaDocument): + doc = story_item.media.document + attributes = {type(i): i for i in doc.attributes} + video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None) + video = types.Video._parse(client, doc, video_attributes, None) + media = enums.MessageMediaType.VIDEO + has_protected_content = story_item.noforwards + edited = story_item.edited + pinned = story_item.pinned + entities = [e for e in (types.MessageEntity._parse(client, entity, {}) for entity in story_item.entities) if e] + caption = Str(story_item.caption or "").init(entities) or None + caption_entities = entities or None + if story_item.views: + views = getattr(story_item.views, "views_count", None) + forwards = getattr(story_item.views, "forwards_count", None) + reactions = [ + types.Reaction._parse_count(client, reaction) + for reaction in getattr(story_item.views, "reactions", []) + ] or None return Story( client=client, _raw=story_media, id=story_id, - chat=chat + chat=chat, + date=date, + expire_date=expire_date, + media=media, + has_protected_content=has_protected_content, + photo=photo, + video=video, + edited=edited, + pinned=pinned, + caption=caption, + caption_entities=caption_entities, + views=views, + forwards=forwards, + reactions=reactions, + skipped=skipped, + deleted=deleted )