mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
Pyrofork: Add media_areas field to Story
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
1f288c2a0d
commit
838480e5b8
6 changed files with 204 additions and 2 deletions
|
|
@ -494,6 +494,9 @@ def pyrogram_api():
|
||||||
StorySkipped
|
StorySkipped
|
||||||
StoriesPrivacyRules
|
StoriesPrivacyRules
|
||||||
StoryViews
|
StoryViews
|
||||||
|
MediaArea
|
||||||
|
MediaAreaChannelPost
|
||||||
|
MediaAreaCoordinates
|
||||||
""",
|
""",
|
||||||
pyromod="""
|
pyromod="""
|
||||||
Pyromod
|
Pyromod
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ from .document import Document
|
||||||
from .game import Game
|
from .game import Game
|
||||||
from .giveaway import Giveaway
|
from .giveaway import Giveaway
|
||||||
from .location import Location
|
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 import Message
|
||||||
from .message_entity import MessageEntity
|
from .message_entity import MessageEntity
|
||||||
from .photo import Photo
|
from .photo import Photo
|
||||||
|
|
@ -53,7 +56,7 @@ from .story_views import StoryViews
|
||||||
from .exported_story_link import ExportedStoryLink
|
from .exported_story_link import ExportedStoryLink
|
||||||
|
|
||||||
__all__ = [
|
__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",
|
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||||
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
46
pyrogram/types/messages_and_media/media_area.py
Normal file
46
pyrogram/types/messages_and_media/media_area.py
Normal 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)
|
||||||
70
pyrogram/types/messages_and_media/media_area_channel_post.py
Normal file
70
pyrogram/types/messages_and_media/media_area_channel_post.py
Normal 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
|
||||||
|
)
|
||||||
68
pyrogram/types/messages_and_media/media_area_coordinates.py
Normal file
68
pyrogram/types/messages_and_media/media_area_coordinates.py
Normal 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
|
||||||
|
)
|
||||||
|
|
@ -99,9 +99,12 @@ class Story(Object, Update):
|
||||||
|
|
||||||
denied_users (List of ``int``, *optional*):
|
denied_users (List of ``int``, *optional*):
|
||||||
List of user_id whos denied to view the story.
|
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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
@ -130,6 +133,7 @@ class Story(Object, Update):
|
||||||
forward_from: "types.StoryForwardHeader" = None,
|
forward_from: "types.StoryForwardHeader" = None,
|
||||||
allowed_users: List[int] = None,
|
allowed_users: List[int] = None,
|
||||||
denied_users: List[int] = None,
|
denied_users: List[int] = None,
|
||||||
|
media_areas: List["types.MediaArea"] = None
|
||||||
#allowed_chats: List[int] = None,
|
#allowed_chats: List[int] = None,
|
||||||
#denied_chats: List[int] = None
|
#denied_chats: List[int] = None
|
||||||
):
|
):
|
||||||
|
|
@ -158,6 +162,7 @@ class Story(Object, Update):
|
||||||
self.forward_from = forward_from
|
self.forward_from = forward_from
|
||||||
self.allowed_users = allowed_users
|
self.allowed_users = allowed_users
|
||||||
self.denied_users = denied_users
|
self.denied_users = denied_users
|
||||||
|
self.media_areas = media_areas
|
||||||
#self.allowed_chats = allowed_chats
|
#self.allowed_chats = allowed_chats
|
||||||
#self.denied_chats = denied_chats
|
#self.denied_chats = denied_chats
|
||||||
|
|
||||||
|
|
@ -241,6 +246,12 @@ class Story(Object, Update):
|
||||||
if stories.fwd_from is not None:
|
if stories.fwd_from is not None:
|
||||||
forward_from = await types.StoryForwardHeader._parse(client, stories.fwd_from)
|
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(
|
return Story(
|
||||||
id=stories.id,
|
id=stories.id,
|
||||||
from_user=from_user,
|
from_user=from_user,
|
||||||
|
|
@ -267,6 +278,7 @@ class Story(Object, Update):
|
||||||
#denied_chats=denied_chats,
|
#denied_chats=denied_chats,
|
||||||
allowed_users=allowed_users,
|
allowed_users=allowed_users,
|
||||||
denied_users=denied_users,
|
denied_users=denied_users,
|
||||||
|
media_areas=media_areas,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue