mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: Add media_areas parameter to {send,edit}_story methods
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
838480e5b8
commit
b85382706d
9 changed files with 160 additions and 22 deletions
|
|
@ -497,6 +497,8 @@ def pyrogram_api():
|
|||
MediaArea
|
||||
MediaAreaChannelPost
|
||||
MediaAreaCoordinates
|
||||
InputMediaArea
|
||||
InputMediaAreaChannelPost
|
||||
""",
|
||||
pyromod="""
|
||||
Pyromod
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
]
|
||||
|
|
|
|||
40
pyrogram/types/input_media/input_media_area.py
Normal file
40
pyrogram/types/input_media/input_media_area.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# 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/>.
|
||||
|
||||
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
|
||||
58
pyrogram/types/input_media/input_media_area_channel_post.py
Normal file
58
pyrogram/types/input_media/input_media_area_channel_post.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# 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
|
||||
):
|
||||
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
|
||||
)
|
||||
|
|
@ -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__(
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue