-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pyrofork: Add media_areas field to Story
Signed-off-by: wulan17 <wulan17@nusantararom.org>
- Loading branch information
Showing
6 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Pyrogram - Telegram MTProto API Client Library for Python | ||
# Copyright (C) 2017-present Dan <https://github.com/delivrance> | ||
# | ||
# 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 <http://www.gnu.org/licenses/>. | ||
|
||
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) |
70 changes: 70 additions & 0 deletions
70
pyrogram/types/messages_and_media/media_area_channel_post.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Pyrogram - Telegram MTProto API Client Library for Python | ||
# Copyright (C) 2017-present Dan <https://github.com/delivrance> | ||
# | ||
# 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 <http://www.gnu.org/licenses/>. | ||
|
||
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 | ||
) |
68 changes: 68 additions & 0 deletions
68
pyrogram/types/messages_and_media/media_area_coordinates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Pyrogram - Telegram MTProto API Client Library for Python | ||
# Copyright (C) 2017-present Dan <https://github.com/delivrance> | ||
# | ||
# 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 <http://www.gnu.org/licenses/>. | ||
|
||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters