Skip to content

Commit

Permalink
Pyrofork: Add web_page_preview field to Message
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <[email protected]>
  • Loading branch information
wulan17 committed Oct 31, 2023
1 parent 991ea86 commit 09afca1
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ def get_title_list(s: str) -> list:
Game
MessageStory
WebPage
WebPageEmpty
WebPagePreview
Poll
PollOption
Dice
Expand Down
3 changes: 3 additions & 0 deletions pyrogram/enums/message_media_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 3 additions & 1 deletion pyrogram/types/messages_and_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
]
10 changes: 10 additions & 0 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions pyrogram/types/messages_and_media/web_page_empty.py
Original file line number Diff line number Diff line change
@@ -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 changes: 61 additions & 0 deletions pyrogram/types/messages_and_media/web_page_preview.py
Original file line number Diff line number Diff line change
@@ -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__(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
)

0 comments on commit 09afca1

Please sign in to comment.