Compare commits

..

8 commits

Author SHA1 Message Date
wulan17
2343c68264
pyrofork: Refactor GiveawayResult
Some checks are pending
Build-docs / build (push) Waiting to run
Pyrofork / build (macos-latest, 3.10) (push) Waiting to run
Pyrofork / build (macos-latest, 3.11) (push) Waiting to run
Pyrofork / build (macos-latest, 3.12) (push) Waiting to run
Pyrofork / build (macos-latest, 3.13) (push) Waiting to run
Pyrofork / build (macos-latest, 3.9) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.10) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.11) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.12) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.13) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.9) (push) Waiting to run
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 23:06:03 +07:00
wulan17
af228e50c7
pyrofork: Refactor ShippingQuery
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 23:00:28 +07:00
wulan17
bf3dba50ee
pyrofork: Refactor Giveaway
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 23:00:27 +07:00
wulan17
3622b13a9f
pyrofork: utils: Don't append message to messages_with_replies if reply_to_msg_id is None
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 23:00:07 +07:00
wulan17
00fed09311
Revert "Pyrofork: types: message: Fix cross chat reply parsing"
This reverts commit b4cb8ff17c.

Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 23:00:07 +07:00
KurimuzonAkuma
e5c8f25a71
Add ExternalReplyInfo
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 23:00:06 +07:00
KurimuzonAkuma
749fad58b6
Add MessageOriginImport
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 21:18:08 +07:00
KurimuzonAkuma
132b63eeaf
Refactor Message
- Refactor Message.quote
- Add forward_origin

Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-26 21:17:20 +07:00
24 changed files with 93 additions and 252 deletions

View file

@ -531,7 +531,6 @@ def pyrogram_api():
Voice
VideoNote
Contact
LinkPreviewOptions
Location
Venue
Sticker

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -17,15 +17,14 @@
# 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 logging
from typing import Optional
import pyrogram
from pyrogram import enums, raw, types, utils
from pyrogram import raw, enums
from pyrogram import types
from pyrogram import utils
from .inline_session import get_session
log = logging.getLogger(__name__)
class EditInlineText:
async def edit_inline_text(
@ -33,7 +32,6 @@ class EditInlineText:
inline_message_id: str,
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None,
invert_media: bool = None
@ -53,9 +51,6 @@ class EditInlineText:
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -82,11 +77,6 @@ class EditInlineText:
inline_message_id, message.text,
disable_web_page_preview=True)
"""
if disable_web_page_preview is not None:
log.warning(
"`disable_web_page_preview` is deprecated and will be removed in future updates. Use `link_preview_options` instead."
)
link_preview_options = types.LinkPreviewOptions(is_disabled=disable_web_page_preview)
unpacked = utils.unpack_inline_message_id(inline_message_id)
dc_id = unpacked.dc_id
@ -96,7 +86,7 @@ class EditInlineText:
return await session.invoke(
raw.functions.messages.EditInlineBotMessage(
id=unpacked,
no_webpage=getattr(link_preview_options, "is_disabled", None) or None,
no_webpage=disable_web_page_preview or None,
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await self.parser.parse(text, parse_mode),
invert_media=invert_media

View file

@ -17,13 +17,12 @@
# 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 logging
from typing import Union, List, Optional
import pyrogram
from pyrogram import enums, raw, types, utils
log = logging.getLogger(__name__)
from pyrogram import raw, enums
from pyrogram import types
from pyrogram import utils
class EditMessageText:
@ -34,7 +33,6 @@ class EditMessageText:
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None,
invert_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None,
@ -64,8 +62,8 @@ class EditMessageText:
entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
invert_media (``bool``, *optional*):
Inverts the position of the media and caption.
@ -91,16 +89,11 @@ class EditMessageText:
chat_id, message_id, message.text,
disable_web_page_preview=True)
"""
if disable_web_page_preview is not None:
log.warning(
"`disable_web_page_preview` is deprecated and will be removed in future updates. Use `link_preview_options` instead."
)
link_preview_options = types.LinkPreviewOptions(is_disabled=disable_web_page_preview)
rpc = raw.functions.messages.EditMessage(
peer=await self.resolve_peer(chat_id),
id=message_id,
no_webpage=getattr(link_preview_options, "is_disabled", None) or None,
no_webpage=disable_web_page_preview or None,
invert_media=invert_media,
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await utils.parse_text_entities(self, text, parse_mode, entities)

View file

@ -17,14 +17,12 @@
# 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 logging
from datetime import datetime
from typing import List, Optional, Union
from typing import Union, List, Optional
import pyrogram
from pyrogram import enums, raw, types, utils
log = logging.getLogger(__name__)
from pyrogram import raw, utils, enums
from pyrogram import types
class SendMessage:
@ -34,7 +32,7 @@ class SendMessage:
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None,
disable_notification: bool = None,
message_thread_id: int = None,
business_connection_id: str = None,
@ -53,8 +51,7 @@ class SendMessage:
"types.ReplyKeyboardMarkup",
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None,
disable_web_page_preview: bool = None, # TODO: Remove later
] = None
) -> "types.Message":
"""Send text messages.
@ -77,8 +74,8 @@ class SendMessage:
entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
disable_notification (``bool``, *optional*):
Sends the message silently.
@ -169,16 +166,6 @@ class SendMessage:
"""
message, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values()
if disable_web_page_preview is not None or invert_media is not None:
if disable_web_page_preview is not None:
log.warning(
"`disable_web_page_preview` is deprecated and will be removed in future updates. Use `link_preview_options` instead."
)
link_preview_options = types.LinkPreviewOptions(
is_disabled=disable_web_page_preview,
invert_media=invert_media
)
reply_to = await utils.get_reply_to(
client=self,
@ -194,7 +181,7 @@ class SendMessage:
rpc = raw.functions.messages.SendMessage(
peer=await self.resolve_peer(chat_id),
no_webpage=getattr(link_preview_options, "is_disabled", None) or None,
no_webpage=disable_web_page_preview or None,
silent=disable_notification or None,
reply_to=reply_to,
random_id=self.rnd_id(),
@ -204,7 +191,7 @@ class SendMessage:
entities=entities,
noforwards=protect_content,
allow_paid_floodskip=allow_paid_broadcast,
invert_media=getattr(link_preview_options, "invert_media", None) or None,
invert_media=invert_media,
effect=message_effect_id,
)
if business_connection_id is not None:

View file

@ -17,18 +17,15 @@
# 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 logging
from typing import List, Match, Optional, Union
from typing import Union, List, Match, Optional
import pyrogram
from pyrogram import raw, enums
from pyrogram import types
from ... import utils
from ..object import Object
from ..update import Update
from ... import utils
log = logging.getLogger(__name__)
class CallbackQuery(Object, Update):
"""An incoming callback query from a callback button in an inline keyboard.
@ -183,9 +180,8 @@ class CallbackQuery(Object, Update):
self,
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
reply_markup: "types.InlineKeyboardMarkup" = None,
disable_web_page_preview: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]:
"""Edit the text of messages attached to callback queries.
@ -200,8 +196,8 @@ class CallbackQuery(Object, Update):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
@ -217,12 +213,6 @@ class CallbackQuery(Object, Update):
Raises:
RPCError: In case of a Telegram RPC error.
"""
if disable_web_page_preview is not None:
log.warning(
"`disable_web_page_preview` is deprecated and will be removed in future updates. Use `link_preview_options` instead."
)
link_preview_options = types.LinkPreviewOptions(is_disabled=disable_web_page_preview)
if self.inline_message_id is None:
return await self._client.edit_message_text(
chat_id=self.message.chat.id,
@ -230,7 +220,6 @@ class CallbackQuery(Object, Update):
text=text,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
link_preview_options=link_preview_options,
reply_markup=reply_markup,
business_connection_id=getattr(self.message, "business_connection_id", None)
)
@ -239,7 +228,7 @@ class CallbackQuery(Object, Update):
inline_message_id=self.inline_message_id,
text=text,
parse_mode=parse_mode,
link_preview_options=link_preview_options,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup
)

View file

@ -17,14 +17,11 @@
# 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 typing import Union, List, Match, Optional
import pyrogram
from pyrogram import raw, enums
from pyrogram import types
from pyrogram import raw, types
from ..object import Object
from ..update import Update
from ... import utils
class PreCheckoutQuery(Object, Update):
@ -76,7 +73,11 @@ class PreCheckoutQuery(Object, Update):
self.payment_info = payment_info
@staticmethod
async def _parse(client: "pyrogram.Client", pre_checkout_query, users) -> "PreCheckoutQuery":
async def _parse(
client: "pyrogram.Client",
pre_checkout_query: "raw.types.UpdateBotPrecheckoutQuery",
users
) -> "PreCheckoutQuery":
# Try to decode pre-checkout query payload into string. If that fails, fallback to bytes instead of decoding by
# ignoring/replacing errors, this way, button clicks will still work.
try:

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#
@ -16,8 +17,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, Optional
import pyrogram
from pyrogram import raw, types
@ -49,14 +48,14 @@ class ShippingQuery(Object, Update):
client: "pyrogram.Client" = None,
id: str,
from_user: "types.User",
invoice_payload: str,
payload: str,
shipping_address: "types.ShippingAddress" = None
):
super().__init__(client)
self.id = id
self.from_user = from_user
self.invoice_payload = invoice_payload
self.payload = payload
self.shipping_address = shipping_address
@staticmethod
@ -72,19 +71,12 @@ class ShippingQuery(Object, Update):
except (UnicodeDecodeError, AttributeError):
payload = shipping_query.payload
return types.PreCheckoutQuery(
id=str(shipping_query.query_id),
from_user=types.User._parse(client, users[shipping_query.user_id]),
invoice_payload=payload,
shipping_address=types.ShippingAddress(
country_code=shipping_query.shipping_address.country_iso2,
state=shipping_query.shipping_address.state,
city=shipping_query.shipping_address.city,
street_line1=shipping_query.shipping_address.street_line1,
street_line2=shipping_query.shipping_address.street_line2,
post_code=shipping_query.shipping_address.post_code
),
client=client
return ShippingQuery(
client=client,
id=shipping_query.query_id,
from_user=types.User._parse(client, shipping_query.user_id, users),
payload=payload,
shipping_address=types.ShippingAddress._parse(client, shipping_query.shipping_address)
)
async def answer(

View file

@ -17,15 +17,12 @@
# 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 logging
from typing import List, Optional
from typing import Optional, List
import pyrogram
from pyrogram import enums, raw, types, utils
from pyrogram import raw, types, utils, enums
from .input_message_content import InputMessageContent
log = logging.getLogger(__name__)
class InputTextMessageContent(InputMessageContent):
"""Content of a text message to be sent as the result of an inline query.
@ -41,8 +38,8 @@ class InputTextMessageContent(InputMessageContent):
entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
"""
def __init__(
@ -50,21 +47,13 @@ class InputTextMessageContent(InputMessageContent):
message_text: str,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None
):
super().__init__()
if disable_web_page_preview is not None:
log.warning(
"`disable_web_page_preview` is deprecated and will be removed in future updates. Use `link_preview_options` instead."
)
link_preview_options = types.LinkPreviewOptions(is_disabled=disable_web_page_preview)
self.message_text = message_text
self.parse_mode = parse_mode
self.entities = entities
self.link_preview_options = link_preview_options
self.disable_web_page_preview = disable_web_page_preview
async def write(self, client: "pyrogram.Client", reply_markup):
@ -73,7 +62,7 @@ class InputTextMessageContent(InputMessageContent):
)).values()
return raw.types.InputBotInlineMessageText(
no_webpage=getattr(self.link_preview_options, "is_disabled", None) or None,
no_webpage=self.disable_web_page_preview or None,
reply_markup=await reply_markup.write(client) if reply_markup else None,
message=message,
entities=entities

View file

@ -32,7 +32,6 @@ from .game import Game
from .giveaway import Giveaway
from .giveaway_launched import GiveawayLaunched
from .giveaway_result import GiveawayResult
from .link_preview_options import LinkPreviewOptions
from .location import Location
from .media_area import MediaArea
from .media_area_channel_post import MediaAreaChannelPost
@ -96,7 +95,6 @@ __all__ = [
"Giveaway",
"GiveawayLaunched",
"GiveawayResult",
"LinkPreviewOptions",
"Location",
"MediaArea",
"MediaAreaChannelPost",

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#
@ -39,9 +40,6 @@ class ExternalReplyInfo(Object):
Unique message identifier inside the original chat.
Available only if the original chat is a supergroup or a channel.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the original message, if it is a text message.
media (:obj:`~pyrogram.enums.MessageMediaType`, *optional*):
The message is a media message.
This field will contain the enumeration type of the media message.
@ -116,7 +114,6 @@ class ExternalReplyInfo(Object):
origin: "types.MessageOrigin" = None,
chat: "types.Chat" = None,
message_id: int,
link_preview_options: Optional["types.LinkPreviewOptions"] = None,
media: Optional["enums.MessageMediaType"] = None,
animation: Optional["types.Animation"] = None,
audio: Optional["types.Audio"] = None,
@ -144,7 +141,6 @@ class ExternalReplyInfo(Object):
self.origin = origin
self.chat = chat
self.message_id = message_id
self.link_preview_options = link_preview_options
self.media = media
self.animation = animation
self.audio = audio
@ -222,16 +218,16 @@ class ExternalReplyInfo(Object):
game = types.Game._parse(client, media)
media_type = enums.MessageMediaType.GAME
elif isinstance(media, raw.types.MessageMediaGiveaway):
giveaway = types.Giveaway._parse(client, media, chats)
giveaway = types.Giveaway._parse(client, reply, chats)
media_type = enums.MessageMediaType.GIVEAWAY
elif isinstance(media, raw.types.MessageMediaGiveawayResults):
giveaway_winners = await types.GiveawayWinners._parse(client, media, users, chats)
media_type = enums.MessageMediaType.GIVEAWAY_WINNERS
giveaway_winners = await types.GiveawayResult._parse(client, media, users, chats)
media_type = enums.MessageMediaType.GIVEAWAY_RESULT
elif isinstance(media, raw.types.MessageMediaInvoice):
invoice = types.Invoice._parse(client, media)
invoice = types.Invoice._parse(media)
media_type = enums.MessageMediaType.INVOICE
elif isinstance(media, raw.types.MessageMediaStory):
story = await types.Story._parse(client, media, media.peer, users, chats)
story = await types.Story._parse(client, media, media.peer)
media_type = enums.MessageMediaType.STORY
elif isinstance(media, raw.types.MessageMediaDocument):
doc = media.document
@ -257,17 +253,25 @@ class ExternalReplyInfo(Object):
video_attributes = attributes[raw.types.DocumentAttributeVideo]
if video_attributes.round_message:
video_note = types.VideoNote._parse(client, doc, video_attributes, media.ttl_seconds)
video_note = types.VideoNote._parse(client, doc, video_attributes)
media_type = enums.MessageMediaType.VIDEO_NOTE
else:
video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds, media.video_cover, media.video_timestamp, media.alt_documents)
video = types.Video._parse(
client,
doc,
video_attributes,
file_name,
media.ttl_seconds,
media.video_cover,
media.video_timestamp
)
media_type = enums.MessageMediaType.VIDEO
has_media_spoiler = media.spoiler
elif raw.types.DocumentAttributeAudio in attributes:
audio_attributes = attributes[raw.types.DocumentAttributeAudio]
if audio_attributes.voice:
voice = types.Voice._parse(client, doc, audio_attributes, media.ttl_seconds)
voice = types.Voice._parse(client, doc, audio_attributes)
media_type = enums.MessageMediaType.VOICE
else:
audio = types.Audio._parse(client, doc, audio_attributes, file_name)
@ -276,13 +280,13 @@ class ExternalReplyInfo(Object):
document = types.Document._parse(client, doc, file_name)
media_type = enums.MessageMediaType.DOCUMENT
elif isinstance(media, raw.types.MessageMediaPoll):
poll = types.Poll._parse(client, media)
poll = types.Poll._parse(client, media, users)
media_type = enums.MessageMediaType.POLL
elif isinstance(media, raw.types.MessageMediaDice):
dice = types.Dice._parse(client, media)
media_type = enums.MessageMediaType.DICE
elif isinstance(media, raw.types.MessageMediaPaidMedia):
paid_media = types.PaidMediaInfo._parse(client, media)
paid_media = types.PaidMedia._parse(client, media)
media_type = enums.MessageMediaType.PAID_MEDIA
else:
media = None
@ -299,7 +303,6 @@ class ExternalReplyInfo(Object):
chats.get(utils.get_raw_peer_id(reply.reply_to_peer_id)),
),
message_id=reply.reply_to_msg_id,
link_preview_options=types.LinkPreviewOptions._parse(reply.reply_media),
media=media_type,
animation=animation,
audio=audio,

View file

@ -104,7 +104,9 @@ class GiveawayResult(Object):
"raw.types.MessageActionGiveawayResults",
"raw.types.MessageMediaGiveawayResults"
],
hide_winners: bool = False
hide_winners: bool = False,
users: dict = None,
chats: dict = None
) -> "GiveawayResult":
chat = None
giveaway_message = None
@ -112,17 +114,12 @@ class GiveawayResult(Object):
winners = None
if not hide_winners:
chat_id = utils.get_channel_id(giveaway_result.channel_id)
chat = await client.invoke(
raw.functions.channels.GetChannels(
id=[await client.resolve_peer(chat_id)]
)
)
chat = types.Chat._parse_chat(client, chat.chats[0])
chat = types.Chat._parse_channel_chat(client, chats.get(giveaway_result.channel_id))
giveaway_message = await client.get_messages(chat_id, giveaway_result.launch_msg_id)
expired_date = utils.timestamp_to_datetime(giveaway_result.until_date)
winners = []
for winner in giveaway_result.winners:
winners.append(await client.get_users(winner))
winners.append(types.User._parse(client, users.get(winner, None)))
stars = getattr(giveaway_result, "stars", None)

View file

@ -1,87 +0,0 @@
# 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/>.
from typing import Optional
from pyrogram import raw
from ..object import Object
class LinkPreviewOptions(Object):
"""Describes the options used for link preview generation.
Parameters:
is_disabled (``bool``, *optional*):
True, if the link preview is disabled.
url (``str``, *optional*):
URL to use for the link preview.
If empty, then the first URL found in the message text will be used.
prefer_small_media (``bool``, *optional*):
True, if the media in the link preview is suppposed to be shrunk.
Ignored if the URL isn't explicitly specified or media size change isn't supported for the preview.
prefer_large_media (``bool``, *optional*):
True, if the media in the link preview is suppposed to be enlarged.
Ignored if the URL isn't explicitly specified or media size change isn't supported for the preview.
invert_media (``bool``, *optional*):
True, if the link preview must be shown above the message text.
Otherwise, the link preview will be shown below the message text.
"""
def __init__(
self,
*,
is_disabled: bool = None,
url: str = None,
prefer_small_media: bool = None,
prefer_large_media: bool = None,
invert_media: bool = None
):
super().__init__()
self.is_disabled = is_disabled
self.url = url
self.prefer_small_media = prefer_small_media
self.prefer_large_media = prefer_large_media
self.invert_media = invert_media
@staticmethod
def _parse(
media: "raw.types.MessageMediaWebPage",
url: str = None,
invert_media: bool = None
) -> Optional["LinkPreviewOptions"]:
if isinstance(media, raw.types.MessageMediaWebPage) and not isinstance(media.webpage, raw.types.WebPageNotModified):
return LinkPreviewOptions(
is_disabled=False,
url=media.webpage.url,
prefer_small_media=media.force_small_media,
prefer_large_media=media.force_large_media,
invert_media=invert_media,
)
if url:
return LinkPreviewOptions(
is_disabled=True,
url=url,
invert_media=invert_media,
)

View file

@ -242,9 +242,6 @@ class Message(Object, Update):
venue (:obj:`~pyrogram.types.Venue`, *optional*):
Message is a venue, information about the venue.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
poll (:obj:`~pyrogram.types.Poll`, *optional*):
Message is a native poll, information about the poll.
@ -494,7 +491,6 @@ class Message(Object, Update):
contact: "types.Contact" = None,
location: "types.Location" = None,
venue: "types.Venue" = None,
link_preview_options: "types.LinkPreviewOptions" = None,
poll: "types.Poll" = None,
dice: "types.Dice" = None,
new_chat_members: List["types.User"] = None,
@ -611,7 +607,6 @@ class Message(Object, Update):
self.contact = contact
self.location = location
self.venue = venue
self.link_preview_options = link_preview_options
self.poll = poll
self.dice = dice
self.new_chat_members = new_chat_members
@ -1019,7 +1014,6 @@ class Message(Object, Update):
web_page_preview = None
sticker = None
document = None
link_preview_options = None
poll = None
dice = None
@ -1048,7 +1042,7 @@ class Message(Object, Update):
giveaway = await types.Giveaway._parse(client, message, chats)
media_type = enums.MessageMediaType.GIVEAWAY
elif isinstance(media, raw.types.MessageMediaGiveawayResults):
giveaway_result = await types.GiveawayResult._parse(client, message.media)
giveaway_result = await types.GiveawayResult._parse(client, message.media, users, chats)
media_type = enums.MessageMediaType.GIVEAWAY_RESULT
elif isinstance(media, raw.types.MessageMediaStory):
story = await types.MessageStory._parse(client, media)
@ -1132,12 +1126,6 @@ class Message(Object, Update):
else:
media = None
link_preview_options = types.LinkPreviewOptions._parse(
media,
getattr(getattr(media, "webpage", None), "url", utils.get_first_url(message.message)),
message.invert_media
)
reply_markup = message.reply_markup
if reply_markup:
@ -1221,7 +1209,6 @@ class Message(Object, Update):
web_page_preview=web_page_preview,
sticker=sticker,
document=document,
link_preview_options=link_preview_options,
poll=poll,
dice=dice,
views=message.views,
@ -1424,7 +1411,7 @@ class Message(Object, Update):
quote: bool = None,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
business_connection_id: str = None,
@ -1436,8 +1423,7 @@ class Message(Object, Update):
allow_paid_broadcast: bool = None,
message_effect_id: int = None,
invert_media: bool = None,
reply_markup=None,
disable_web_page_preview: bool = None
reply_markup=None
) -> "Message":
"""Bound method *reply_text* of :obj:`~pyrogram.types.Message`.
@ -1477,8 +1463,9 @@ class Message(Object, Update):
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_notification (``bool``, *optional*):
Sends the message silently.
Users will receive a notification with no sound.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
@ -1551,7 +1538,6 @@ class Message(Object, Update):
parse_mode=parse_mode,
entities=entities,
disable_web_page_preview=disable_web_page_preview,
link_preview_options=link_preview_options,
disable_notification=disable_notification,
message_thread_id=message_thread_id,
reply_to_message_id=reply_to_message_id,
@ -4339,11 +4325,10 @@ class Message(Object, Update):
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None,
invert_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: str = None,
disable_web_page_preview: bool = None
business_connection_id: str = None
) -> "Message":
"""Bound method *edit_text* of :obj:`~pyrogram.types.Message`.
@ -4375,8 +4360,8 @@ class Message(Object, Update):
entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
invert_media (``bool``, *optional*):
Inverts the position of the media and caption.
@ -4401,7 +4386,6 @@ class Message(Object, Update):
parse_mode=parse_mode,
entities=entities,
disable_web_page_preview=disable_web_page_preview,
link_preview_options=link_preview_options,
invert_media=invert_media,
reply_markup=reply_markup,
business_connection_id=self.business_connection_id if business_connection_id is None else business_connection_id
@ -4776,7 +4760,7 @@ class Message(Object, Update):
text=self.text,
entities=self.entities,
parse_mode=enums.ParseMode.DISABLED,
link_preview_options=types.LinkPreviewOptions(is_disabled=not self.web_page),
disable_web_page_preview=not self.web_page_preview,
disable_notification=disable_notification,
message_thread_id=message_thread_id,
reply_to_message_id=reply_to_message_id,

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -327,13 +327,12 @@ class Story(Object, Update):
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
link_preview_options: "types.LinkPreviewOptions" = None,
disable_web_page_preview: bool = None,
disable_notification: bool = None,
reply_to_story_id: int = None,
schedule_date: datetime = None,
protect_content: bool = None,
reply_markup=None,
disable_web_page_preview: bool = None
reply_markup=None
) -> "types.Message":
"""Bound method *reply_text* of :obj:`~pyrogram.types.Story`.
@ -365,8 +364,8 @@ class Story(Object, Update):
entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
Options used for link preview generation for the message.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
disable_notification (``bool``, *optional*):
Sends the message silently.
@ -401,7 +400,6 @@ class Story(Object, Update):
parse_mode=parse_mode,
entities=entities,
disable_web_page_preview=disable_web_page_preview,
link_preview_options=link_preview_options,
disable_notification=disable_notification,
reply_to_story_id=reply_to_story_id,
schedule_date=schedule_date,

View file

@ -1,5 +1,6 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrogram.
#

View file

@ -22,7 +22,6 @@ from pyrogram import raw
from pyrogram import types
from ..object import Object
from typing import Optional
class WebPage(Object):
# TODO: hash, cached_page