From 09afca1614b2b1bfaaa0855649b106714c5d6886 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Tue, 31 Oct 2023 23:32:54 +0700 Subject: [PATCH] Pyrofork: Add web_page_preview field to Message Signed-off-by: wulan17 --- compiler/docs/compiler.py | 2 + pyrogram/enums/message_media_type.py | 3 + pyrogram/types/messages_and_media/__init__.py | 4 +- pyrogram/types/messages_and_media/message.py | 10 +++ .../messages_and_media/web_page_empty.py | 54 ++++++++++++++++ .../messages_and_media/web_page_preview.py | 61 +++++++++++++++++++ 6 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/messages_and_media/web_page_empty.py create mode 100644 pyrogram/types/messages_and_media/web_page_preview.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 3db5cd8ba..6a0397a50 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -448,6 +448,8 @@ def get_title_list(s: str) -> list: Game MessageStory WebPage + WebPageEmpty + WebPagePreview Poll PollOption Dice diff --git a/pyrogram/enums/message_media_type.py b/pyrogram/enums/message_media_type.py index 2b6c08aee..bd0ae527a 100644 --- a/pyrogram/enums/message_media_type.py +++ b/pyrogram/enums/message_media_type.py @@ -63,6 +63,9 @@ class MessageMediaType(AutoName): WEB_PAGE = auto() "Web page media" + WEB_PAGE_PEVIEW = auto() + "Web page preview media" + DICE = auto() "Dice media" diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index f839064af..b68de927d 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -40,6 +40,8 @@ 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 @@ __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" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index c9796bee9..01833473b 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -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 @@ def __init__( 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 @@ def __init__( 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 @@ async def _parse( animation = None video = None video_note = None + web_page_preview = None sticker = None document = None web_page = None @@ -882,6 +888,9 @@ async def _parse( 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 @@ async def _parse( story=story, video=video, video_note=video_note, + web_page_preview=web_page_preview, sticker=sticker, document=document, web_page=web_page, diff --git a/pyrogram/types/messages_and_media/web_page_empty.py b/pyrogram/types/messages_and_media/web_page_empty.py new file mode 100644 index 000000000..69ecb8ef5 --- /dev/null +++ b/pyrogram/types/messages_and_media/web_page_empty.py @@ -0,0 +1,54 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +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 + ) diff --git a/pyrogram/types/messages_and_media/web_page_preview.py b/pyrogram/types/messages_and_media/web_page_preview.py new file mode 100644 index 000000000..49d2c13af --- /dev/null +++ b/pyrogram/types/messages_and_media/web_page_preview.py @@ -0,0 +1,61 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +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__(client) + + 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 + )