Skip to content

Commit

Permalink
Pyrofork: Add media_areas parameter to {send,edit}_story methods
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Dec 25, 2023
1 parent 85553e7 commit c0d8f5d
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 22 deletions.
2 changes: 2 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ def get_title_list(s: str) -> list:
MediaArea
MediaAreaChannelPost
MediaAreaCoordinates
InputMediaArea
InputMediaAreaChannelPost
""",
pyromod="""
Pyromod
Expand Down
11 changes: 7 additions & 4 deletions pyrogram/methods/users/edit_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ async def edit_story(
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.
Expand Down Expand Up @@ -95,6 +96,9 @@ async def edit_story(
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.
Expand All @@ -109,8 +113,6 @@ async def edit_story(
ValueError: In case of invalid arguments.
"""

# TODO: MediaArea

if channel_id:
peer = await self.resolve_peer(channel_id)
else:
Expand Down Expand Up @@ -241,7 +243,8 @@ async def edit_story(
media=media,
privacy_rules=privacy_rules,
caption=text,
entities=entities
entities=entities,
media_areas=media_areas
)
)
return await types.Story._parse(self, r.updates[0].story, r.updates[0].peer)
10 changes: 7 additions & 3 deletions pyrogram/methods/users/send_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ async def send_story(
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.
Expand Down Expand Up @@ -111,6 +112,9 @@ async def send_story(
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.
Returns:
:obj:`~pyrogram.types.Story` a single story is returned.
Expand All @@ -124,7 +128,6 @@ async def send_story(
Raises:
ValueError: In case of invalid arguments.
"""
# TODO: media_areas

if channel_id:
peer = await self.resolve_peer(channel_id)
Expand Down Expand Up @@ -268,7 +271,8 @@ async def send_story(
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=media_areas
)
)
return await types.Story._parse(self, r.updates[0].story, r.updates[0].peer)
4 changes: 3 additions & 1 deletion pyrogram/types/input_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
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"
]
41 changes: 41 additions & 0 deletions pyrogram/types/input_media/input_media_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.

import pyrogram

from pyrogram import types

from ..object import Object


class InputMediaArea(Object):
"""Content of a media message to be sent.
It should be one of:
- :obj:`~pyrogram.types.InputMediaAnimation`
"""

def __init__(
self,
coordinates: "types.MediaAreaCoordinates",
client: "pyrogram.Client" = None
):
super().__init__(client)

self.coordinates = coordinates
59 changes: 59 additions & 0 deletions pyrogram/types/input_media/input_media_area_channel_post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.

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,
client: "pyrogram.Client" = None
):
super().__init__(client=client,coordinates=coordinates)

self.coordinates = coordinates
self.chat_id = chat_id
self.message_id = message_id

def write(self):
return raw.types.InputMediaAreaChannelPost(
coordinates=self.coordinates,
channel=self._client.resolve_peer(self.chat_id),
msg_id=self.message_id
)
4 changes: 2 additions & 2 deletions pyrogram/types/messages_and_media/media_area_channel_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
29 changes: 19 additions & 10 deletions pyrogram/types/messages_and_media/media_area_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 0.0,
y: float = 0.0,
width: float = 0.0,
height: float = 0.0,
rotation: float = 0.0
):
super().__init__()

Expand All @@ -66,3 +66,12 @@ def _parse(
height=media_area_cordinates.h,
rotation=media_area_cordinates.rotation
)

def write(self):
return raw.types.MediaAreaCoordinates(
x=self.x,
y=self.y,
w=self.width,
h=self.height,
rotation=self.rotation
)
9 changes: 7 additions & 2 deletions pyrogram/types/messages_and_media/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,8 @@ async def edit(
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`.
Expand Down Expand Up @@ -1513,6 +1514,9 @@ async def edit(
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.
Expand All @@ -1532,7 +1536,8 @@ async def edit(
video=video,
caption=caption,
parse_mode=parse_mode,
caption_entities=caption_entities
caption_entities=caption_entities,
media_areas=media_areas
)

async def edit_caption(
Expand Down

0 comments on commit c0d8f5d

Please sign in to comment.