Pyrofork: Add media_areas field to Story

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2023-12-24 18:54:38 +07:00
parent 1f288c2a0d
commit 838480e5b8
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
6 changed files with 204 additions and 2 deletions

View file

@ -494,6 +494,9 @@ def pyrogram_api():
StorySkipped
StoriesPrivacyRules
StoryViews
MediaArea
MediaAreaChannelPost
MediaAreaCoordinates
""",
pyromod="""
Pyromod

View file

@ -24,6 +24,9 @@ from .document import Document
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 .story_views import StoryViews
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"
]

View file

@ -0,0 +1,46 @@
# 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 ..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"
) -> "MediaArea":
if isinstance(media_area, raw.types.MediaAreaChannelPost):
return await types.MediaAreaChannelPost._parse(client, media_area)

View file

@ -0,0 +1,70 @@
# 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, 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"
) -> "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)]
)
)
).chats[0]
)
return MediaAreaChannelPost(
coordinates=types.MediaAreaCoordinates._parse(media_area.coordinates),
chat=chat,
message_id=media_area.msg_id
)

View file

@ -0,0 +1,68 @@
# 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, 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
)

View file

@ -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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
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 @@ class Story(Object, Update):
#denied_chats=denied_chats,
allowed_users=allowed_users,
denied_users=denied_users,
media_areas=media_areas,
client=client
)