diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index b3489f62..b8c144f5 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -497,6 +497,8 @@ def pyrogram_api(): MediaArea MediaAreaChannelPost MediaAreaCoordinates + InputMediaArea + InputMediaAreaChannelPost """, pyromod=""" Pyromod diff --git a/pyrogram/methods/users/edit_story.py b/pyrogram/methods/users/edit_story.py index 8d845f2a..079d7a54 100644 --- a/pyrogram/methods/users/edit_story.py +++ b/pyrogram/methods/users/edit_story.py @@ -42,7 +42,8 @@ class EditStory: video: str = None, caption: str = None, parse_mode: "enums.ParseMode" = None, - caption_entities: List["types.MessageEntity"] = None + caption_entities: List["types.MessageEntity"] = None, + media_areas: List["types.InputMediaArea"] = None ) -> "types.Story": """Edit story. @@ -95,6 +96,9 @@ class EditStory: caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + media_areas (List of :obj:`~pyrogram.types.InputMediaArea`): + List of media area object to be included in story. + Returns: :obj:`~pyrogram.types.Story` a single story is returned. @@ -109,8 +113,6 @@ class EditStory: ValueError: In case of invalid arguments. """ - # TODO: MediaArea - if channel_id: peer = await self.resolve_peer(channel_id) else: @@ -241,7 +243,11 @@ class EditStory: media=media, privacy_rules=privacy_rules, caption=text, - entities=entities + entities=entities, + media_areas=[ + await media_area.write(self) + for media_area in media_areas + ] ) ) return await types.Story._parse(self, r.updates[0].story, r.updates[0].peer) diff --git a/pyrogram/methods/users/send_story.py b/pyrogram/methods/users/send_story.py index 4b6ea9b1..f53b735e 100644 --- a/pyrogram/methods/users/send_story.py +++ b/pyrogram/methods/users/send_story.py @@ -46,7 +46,8 @@ class SendStory: caption_entities: List["types.MessageEntity"] = None, period: int = None, forward_from_chat_id: Union[int, str] = None, - forward_from_story_id: int = None + forward_from_story_id: int = None, + media_areas: List["types.InputMediaArea"] = None ) -> "types.Story": """Send new story. @@ -111,6 +112,17 @@ class SendStory: How long the story will posted, in secs. only for premium users. + media_areas (List of :obj:`~pyrogram.types.InputMediaArea`): + List of media area object to be included in story. + + forward_from_chat_id (``int`` | ``str``, *optional): + Unique identifier (int) or username (str) of the source chat where the original story was sent. + For your personal story you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + + forward_from_story_id (``int``, *optional*): + Single story id. + Returns: :obj:`~pyrogram.types.Story` a single story is returned. @@ -124,7 +136,6 @@ class SendStory: Raises: ValueError: In case of invalid arguments. """ - # TODO: media_areas if channel_id: peer = await self.resolve_peer(channel_id) @@ -249,6 +260,7 @@ class SendStory: users = [await self.resolve_peer(user_id) for user_id in denied_users] privacy_rules.append(raw.types.InputPrivacyValueDisallowUsers(users=users)) + forward_from_chat = None if forward_from_chat_id is not None: forward_from_chat = await self.resolve_peer(forward_from_chat_id) media = raw.types.InputMediaEmpty() @@ -268,7 +280,11 @@ class SendStory: period=period, fwd_from_id=forward_from_chat, fwd_from_story=forward_from_story_id if forward_from_chat_id is not None else None, - fwd_modified=True if forward_from_chat_id is not None and caption is not None else False + fwd_modified=True if forward_from_chat_id is not None and caption is not None else False, + media_areas=[ + await media_area.write(self) + for media_area in media_areas + ] ) ) return await types.Story._parse(self, r.updates[0].story, r.updates[0].peer) diff --git a/pyrogram/types/input_media/__init__.py b/pyrogram/types/input_media/__init__.py index a03d1e21..6f7447db 100644 --- a/pyrogram/types/input_media/__init__.py +++ b/pyrogram/types/input_media/__init__.py @@ -23,8 +23,10 @@ from .input_media_document import InputMediaDocument from .input_media_photo import InputMediaPhoto from .input_media_video import InputMediaVideo from .input_phone_contact import InputPhoneContact +from .input_media_area import InputMediaArea +from .input_media_area_channel_post import InputMediaAreaChannelPost __all__ = [ "InputMedia", "InputMediaAnimation", "InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo", - "InputPhoneContact" + "InputPhoneContact", "InputMediaArea", "InputMediaAreaChannelPost" ] diff --git a/pyrogram/types/input_media/input_media_area.py b/pyrogram/types/input_media/input_media_area.py new file mode 100644 index 00000000..48f5f963 --- /dev/null +++ b/pyrogram/types/input_media/input_media_area.py @@ -0,0 +1,40 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +from pyrogram import types + +from ..object import Object + + +class InputMediaArea(Object): + """Content of a media area to be included in story. + + Pyrofork currently supports the following types: + + - :obj:`~pyrogram.types.InputMediaAreaChannelPost` + """ + + # TODO: InputMediaAreaVenue + + def __init__( + self, + coordinates: "types.MediaAreaCoordinates" + ): + super().__init__() + + self.coordinates = coordinates diff --git a/pyrogram/types/input_media/input_media_area_channel_post.py b/pyrogram/types/input_media/input_media_area_channel_post.py new file mode 100644 index 00000000..64eed277 --- /dev/null +++ b/pyrogram/types/input_media/input_media_area_channel_post.py @@ -0,0 +1,58 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +import pyrogram + +from pyrogram import raw, types + +from .input_media_area import InputMediaArea + +from typing import Union + +class InputMediaAreaChannelPost(InputMediaArea): + """A channel post media area. + + Parameters: + coordinates (:obj:`~pyrogram.types.MediaAreaCoordinates`): + Media area coordinates. + + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target channel. + + message_id (``int``): + A single message id. + """ + + def __init__( + self, + coordinates: "types.MediaAreaCoordinates", + chat_id: Union[int, str], + message_id: int + ): + super().__init__(coordinates=coordinates) + + self.coordinates = coordinates + self.chat_id = chat_id + self.message_id = message_id + + async def write(self, client: "pyrogram.Client"): + return raw.types.InputMediaAreaChannelPost( + coordinates=self.coordinates, + channel=await client.resolve_peer(self.chat_id), + msg_id=self.message_id + ) diff --git a/pyrogram/types/messages_and_media/media_area_channel_post.py b/pyrogram/types/messages_and_media/media_area_channel_post.py index 0699bf0a..82ad9a7c 100644 --- a/pyrogram/types/messages_and_media/media_area_channel_post.py +++ b/pyrogram/types/messages_and_media/media_area_channel_post.py @@ -30,10 +30,10 @@ class MediaAreaChannelPost(MediaArea): Media area coordinates. chat (:obj:`~pyrogram.types.Chat`): - Media area width. + Information about origin channel. message_id (``int``): - Media area height. + The channel post message id. """ def __init__( diff --git a/pyrogram/types/messages_and_media/media_area_coordinates.py b/pyrogram/types/messages_and_media/media_area_coordinates.py index 54643521..c20935ef 100644 --- a/pyrogram/types/messages_and_media/media_area_coordinates.py +++ b/pyrogram/types/messages_and_media/media_area_coordinates.py @@ -24,29 +24,29 @@ class MediaAreaCoordinates(Object): """A coordinates of media area. Parameters: - x (``float``): + x (``float``, *optional*): X position of media area. - y (``float``): + y (``float``, *optional*): Y position of media area. - width (``float``): + width (``float``, *optional*): Media area width. - height (``float``): + height (``float``, *optional*): Media area height. - rotation (``float``): + rotation (``float``, *optional*): Media area rotation. """ def __init__( self, - x: float, - y: float, - width: float, - height: float, - rotation: float + x: float = None, + y: float = None, + width: float = None, + height: float = None, + rotation: float = None ): super().__init__() @@ -66,3 +66,12 @@ class MediaAreaCoordinates(Object): height=media_area_cordinates.h, rotation=media_area_cordinates.rotation ) + + def write(self): + return raw.types.MediaAreaCoordinates( + x=self.x or 51.596797943115, # value from official android apps + y=self.y or 51.580257415771, # value from official android apps + w=self.width or 69.867012023926, # value from official android apps + h=self.height or 75.783416748047, # value from official android apps + rotation=self.rotation or 0.0 # value from official android apps + ).write() diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index a41f8497..97e8796f 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -1451,7 +1451,8 @@ class Story(Object, Update): video: str = None, caption: str = None, parse_mode: "enums.ParseMode" = None, - caption_entities: List["types.MessageEntity"] = None + caption_entities: List["types.MessageEntity"] = None, + media_areas: List["types.InputMediaArea"] = None ) -> "types.Story": """Bound method *edit* of :obj:`~pyrogram.types.Story`. @@ -1513,6 +1514,9 @@ class Story(Object, Update): caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + media_areas (List of :obj:`~pyrogram.types.InputMediaArea`): + List of media area object to be included in story. + Returns: On success, the edited :obj:`~pyrogram.types.Story` is returned. @@ -1532,7 +1536,8 @@ class Story(Object, Update): video=video, caption=caption, parse_mode=parse_mode, - caption_entities=caption_entities + caption_entities=caption_entities, + media_areas=media_areas ) async def edit_caption(