diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 1f08612ce..b3489f627 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -494,6 +494,9 @@ def get_title_list(s: str) -> list: StorySkipped StoriesPrivacyRules StoryViews + MediaArea + MediaAreaChannelPost + MediaAreaCoordinates """, pyromod=""" Pyromod diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index c265d3bbd..47ab06a2f 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -24,6 +24,9 @@ from .game import Game from .giveaway import Giveaway from .location import Location +from .media_area import MediaArea +from .media_area_channel_post import MediaAreaChannelPost +from .media_area_coordinates import MediaAreaCoordinates from .message import Message from .message_entity import MessageEntity from .photo import Photo @@ -53,7 +56,7 @@ from .exported_story_link import ExportedStoryLink __all__ = [ - "Animation", "Audio", "Contact", "Document", "Game", "Giveaway", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", + "Animation", "Audio", "Contact", "Document", "Game", "Giveaway", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "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", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink" ] diff --git a/pyrogram/types/messages_and_media/media_area.py b/pyrogram/types/messages_and_media/media_area.py new file mode 100644 index 000000000..40fb2fd76 --- /dev/null +++ b/pyrogram/types/messages_and_media/media_area.py @@ -0,0 +1,46 @@ +# 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 +from ..object import Object + + +class MediaArea(Object): + """Content of a media areas in story. + + It should be one of: + + - :obj:`~pyrogram.types.MediaAreaChannelPost` + """ + + def __init__( + self, + coordinates: "types.MediaAreaCoordinates" + ): + super().__init__() + + self.coordinates = coordinates + + async def _parse( + client: "pyrogram.Client", + media_area: "raw.base.MediaArea" + ): + if isinstance(media_area, raw.types.MediaAreaChannelPost): + return await types.MediaAreaChannelPost._parse(client, media_area) diff --git a/pyrogram/types/messages_and_media/media_area_channel_post.py b/pyrogram/types/messages_and_media/media_area_channel_post.py new file mode 100644 index 000000000..31c24b0bb --- /dev/null +++ b/pyrogram/types/messages_and_media/media_area_channel_post.py @@ -0,0 +1,70 @@ +# 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 .media_area import MediaArea + +class MediaAreaChannelPost(MediaArea): + """A channel post media area. + + Parameters: + coordinates (:obj:`~pyrogram.types.MediaAreaCoordinates`): + Media area coordinates. + + chat (:obj:`~pyrogram.types.Chat`): + Media area width. + + message_id (``int``): + Media area height. + """ + + def __init__( + self, + coordinates: "types.MediaAreaCoordinates", + chat: "types.Chat", + message_id: int + ): + super().__init__(coordinates=coordinates) + + self.coordinates = coordinates + self.chat = chat + self.message_id = message_id + + async def _parse( + client: "pyrogram.Client", + media_area: "raw.types.MediaAreaChannelPost" + ): + channel_id = utils.get_channel_id(media_area.channel_id) + chat = types.Chat._parse_chat( + client, + ( + await client.invoke( + raw.functions.channels.GetChannels( + id=[await client.resolve_peer(channel_id)] + ) + ) + )[0] + ) + return MediaAreaChannelPost( + coordinates=types.MediaAreaCoordinates._parse(media_area.coordinates), + chat=chat, + message_id=media_area.msg_id + ) diff --git a/pyrogram/types/messages_and_media/media_area_coordinates.py b/pyrogram/types/messages_and_media/media_area_coordinates.py new file mode 100644 index 000000000..d5257bf4a --- /dev/null +++ b/pyrogram/types/messages_and_media/media_area_coordinates.py @@ -0,0 +1,68 @@ +# 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 . + +from pyrogram import types, raw +from ..object import Object + + +class MediaAreaCoordinates(Object): + """A coordinates of media area. + + Parameters: + x (``float``): + X position of media area. + + y (``float``): + Y position of media area. + + width (``float``): + Media area width. + + height (``float``): + Media area height. + + rotation (``float``): + Media area rotation. + """ + + def __init__( + self, + x: float, + y: float, + width: float, + height: float, + rotation: float + ): + super().__init__() + + self.x = x + self.y = y + self.width = width + self.height = height + self.rotation = rotation + + def _parse( + media_area_cordinates: "raw.types.MediaAreaCoordinates" + ) -> "MediaAreaCoordinates": + return MediaAreaCoordinates( + x=media_area_cordinates.x, + y=media_area_cordinates.y, + width=media_area_cordinates.w, + height=media_area_cordinates.h, + rotation=media_area_cordinates.rotation + ) diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index e64ae91ee..a41f84976 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -99,9 +99,12 @@ class Story(Object, Update): denied_users (List of ``int``, *optional*): List of user_id whos denied to view the story. + + media_areas (List of :obj:`~pyrogram.types.MediaArea`, *optional*): + List of :obj:`~pyrogram.types.MediaArea` object in story. """ - # TODO: Add Media Areas, fix Allowed Chats + # TODO: fix Allowed Chats def __init__( self, @@ -130,6 +133,7 @@ def __init__( forward_from: "types.StoryForwardHeader" = None, allowed_users: List[int] = None, denied_users: List[int] = None, + media_areas: List["types.MediaArea"] = None #allowed_chats: List[int] = None, #denied_chats: List[int] = None ): @@ -158,6 +162,7 @@ def __init__( self.forward_from = forward_from self.allowed_users = allowed_users self.denied_users = denied_users + self.media_areas = media_areas #self.allowed_chats = allowed_chats #self.denied_chats = denied_chats @@ -241,6 +246,12 @@ async def _parse( if stories.fwd_from is not None: forward_from = await types.StoryForwardHeader._parse(client, stories.fwd_from) + if stories.media_areas is not None and len(stories.media_areas) > 0: + media_areas = [ + await types.MediaArea._parse(client, media_area) + for media_area in stories.media_areas + ] + return Story( id=stories.id, from_user=from_user, @@ -267,6 +278,7 @@ async def _parse( #denied_chats=denied_chats, allowed_users=allowed_users, denied_users=denied_users, + media_areas=media_areas, client=client )