mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: Add web_page_preview field to Message
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
7cb00fa10d
commit
5c358e0c92
6 changed files with 133 additions and 1 deletions
|
|
@ -448,6 +448,8 @@ def pyrogram_api():
|
|||
Game
|
||||
MessageStory
|
||||
WebPage
|
||||
WebPageEmpty
|
||||
WebPagePreview
|
||||
Poll
|
||||
PollOption
|
||||
Dice
|
||||
|
|
|
|||
|
|
@ -63,6 +63,9 @@ class MessageMediaType(AutoName):
|
|||
WEB_PAGE = auto()
|
||||
"Web page media"
|
||||
|
||||
WEB_PAGE_PREVIEW = auto()
|
||||
"Web page preview media"
|
||||
|
||||
DICE = auto()
|
||||
"Dice media"
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ from .video_note import VideoNote
|
|||
from .voice import Voice
|
||||
from .web_app_data import WebAppData
|
||||
from .web_page import WebPage
|
||||
from .web_page_empty import WebPageEmpty
|
||||
from .web_page_preview import WebPagePreview
|
||||
from .message_reactions import MessageReactions
|
||||
from .message_story import MessageStory
|
||||
from .story import Story
|
||||
|
|
@ -50,6 +52,6 @@ from .exported_story_link import ExportedStoryLink
|
|||
|
||||
__all__ = [
|
||||
"Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice",
|
||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -203,6 +203,9 @@ class Message(Object, Update):
|
|||
video_note (:obj:`~pyrogram.types.VideoNote`, *optional*):
|
||||
Message is a video note, information about the video message.
|
||||
|
||||
web_page_preview (:obj:`pyrogram.types.WebPagePreview`, *optional*):
|
||||
Message is a web page preview, information about the web page preview message.
|
||||
|
||||
caption (``str``, *optional*):
|
||||
Caption for the audio, document, photo, video or voice, 0-1024 characters.
|
||||
If the message contains caption entities (bold, italic, ...) you can access *caption.markdown* or
|
||||
|
|
@ -406,6 +409,7 @@ class Message(Object, Update):
|
|||
video: "types.Video" = None,
|
||||
voice: "types.Voice" = None,
|
||||
video_note: "types.VideoNote" = None,
|
||||
web_page_preview: "types.WebPagePreview" = None,
|
||||
caption: Str = None,
|
||||
contact: "types.Contact" = None,
|
||||
location: "types.Location" = None,
|
||||
|
|
@ -499,6 +503,7 @@ class Message(Object, Update):
|
|||
self.video = video
|
||||
self.voice = voice
|
||||
self.video_note = video_note
|
||||
self.web_page_preview = web_page_preview
|
||||
self.caption = caption
|
||||
self.contact = contact
|
||||
self.location = location
|
||||
|
|
@ -806,6 +811,7 @@ class Message(Object, Update):
|
|||
animation = None
|
||||
video = None
|
||||
video_note = None
|
||||
web_page_preview = None
|
||||
sticker = None
|
||||
document = None
|
||||
web_page = None
|
||||
|
|
@ -882,6 +888,9 @@ class Message(Object, Update):
|
|||
if isinstance(media.webpage, raw.types.WebPage):
|
||||
web_page = types.WebPage._parse(client, media.webpage)
|
||||
media_type = enums.MessageMediaType.WEB_PAGE
|
||||
elif isinstance(media.webpage, raw.types.WebPageEmpty):
|
||||
web_page_preview = types.WebPagePreview._parse(media, message.invert_media)
|
||||
media_type = enums.MessageMediaType.WEB_PAGE_PREVIEW
|
||||
else:
|
||||
media = None
|
||||
elif isinstance(media, raw.types.MessageMediaPoll):
|
||||
|
|
@ -967,6 +976,7 @@ class Message(Object, Update):
|
|||
story=story,
|
||||
video=video,
|
||||
video_note=video_note,
|
||||
web_page_preview=web_page_preview,
|
||||
sticker=sticker,
|
||||
document=document,
|
||||
web_page=web_page,
|
||||
|
|
|
|||
54
pyrogram/types/messages_and_media/web_page_empty.py
Normal file
54
pyrogram/types/messages_and_media/web_page_empty.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# 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
|
||||
from pyrogram import types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class WebPageEmpty(Object):
|
||||
# TODO: hash, cached_page
|
||||
"""A webpage preview
|
||||
|
||||
Parameters:
|
||||
id (``str``):
|
||||
Unique identifier for this webpage.
|
||||
|
||||
url (``str``):
|
||||
Full URL for this webpage.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
id: str,
|
||||
url: str
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.id = id
|
||||
self.url = url
|
||||
|
||||
@staticmethod
|
||||
def _parse(webpage: "raw.types.WebPageEmpty") -> "WebPageEmpty":
|
||||
|
||||
return WebPageEmpty(
|
||||
id=str(webpage.id),
|
||||
url=webpage.url
|
||||
)
|
||||
61
pyrogram/types/messages_and_media/web_page_preview.py
Normal file
61
pyrogram/types/messages_and_media/web_page_preview.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# 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
|
||||
from pyrogram import types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class WebPagePreview(Object):
|
||||
"""A web page preview.
|
||||
|
||||
Parameters:
|
||||
webpage (:obj:`~pyrogram.types.WebPage`):
|
||||
Web Page Information.
|
||||
|
||||
force_large_media (``bool``, *optional*):
|
||||
True, If the preview media size is forced to large.
|
||||
|
||||
force_small_media (``bool``, *optional*):
|
||||
True, If the preview media size is forced to small.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
webpage: "types.WebPage",
|
||||
force_large_media: bool = None,
|
||||
force_small_media: bool = None,
|
||||
invert_media: bool = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.webpage = webpage
|
||||
self.force_large_media = force_large_media
|
||||
self.force_small_media = force_small_media
|
||||
self.invert_media = invert_media
|
||||
|
||||
@staticmethod
|
||||
def _parse(web_page_preview: "raw.types.MessageMediaVenue", invert_media: bool = None):
|
||||
return WebPagePreview(
|
||||
webpage=types.WebPageEmpty._parse(web_page_preview.webpage),
|
||||
force_large_media=web_page_preview.force_large_media,
|
||||
force_small_media=web_page_preview.force_small_media,
|
||||
invert_media=invert_media
|
||||
)
|
||||
Loading…
Reference in a new issue