Skip to content

Commit

Permalink
Add missing invert_media parameter to 'some' of the edit_media methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe authored Nov 11, 2024
1 parent f0ab18f commit 9c0209a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 16 additions & 1 deletion pyrogram/methods/messages/edit_inline_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# 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 typing import Optional, List

import pyrogram
from pyrogram import types, enums
Expand All @@ -28,6 +28,8 @@ async def edit_inline_caption(
inline_message_id: str,
caption: str,
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None,
show_caption_above_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None
) -> bool:
"""Edit the caption of inline media messages.
Expand All @@ -45,6 +47,12 @@ async def edit_inline_caption(
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
show_caption_above_media (``bool``, *optional*):
Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
Expand All @@ -57,9 +65,16 @@ async def edit_inline_caption(
# Bots only
await app.edit_inline_caption(inline_message_id, "new media caption")
"""
link_preview_options = None
if show_caption_above_media:
link_preview_options = types.LinkPreviewOptions(
show_above_text=show_caption_above_media
)
return await self.edit_inline_text(
inline_message_id=inline_message_id,
text=caption,
parse_mode=parse_mode,
entities=caption_entities,
link_preview_options=link_preview_options,
reply_markup=reply_markup
)
6 changes: 6 additions & 0 deletions pyrogram/methods/messages/edit_inline_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ async def edit_inline_media(
parse_mode = media.parse_mode
caption_entities = media.caption_entities

show_caption_above_media = []

is_bytes_io = isinstance(media.media, io.BytesIO)
is_uploaded_file = is_bytes_io or os.path.isfile(media.media)

Expand Down Expand Up @@ -109,6 +111,7 @@ async def edit_inline_media(
)
else:
media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO, has_spoiler=media.has_spoiler)
show_caption_above_media.append(media.show_caption_above_media)
elif isinstance(media, types.InputMediaVideo):
if is_uploaded_file:
media = raw.types.InputMediaUploadedDocument(
Expand All @@ -132,6 +135,7 @@ async def edit_inline_media(
)
else:
media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO, has_spoiler=media.has_spoiler)
show_caption_above_media.append(media.show_caption_above_media)
elif isinstance(media, types.InputMediaAudio):
if is_uploaded_file:
media = raw.types.InputMediaUploadedDocument(
Expand Down Expand Up @@ -178,6 +182,7 @@ async def edit_inline_media(
)
else:
media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION)
show_caption_above_media.append(media.show_caption_above_media)
elif isinstance(media, types.InputMediaDocument):
if is_uploaded_file:
media = raw.types.InputMediaUploadedDocument(
Expand Down Expand Up @@ -232,6 +237,7 @@ async def edit_inline_media(
raw.functions.messages.EditInlineBotMessage(
id=unpacked,
media=actual_media,
invert_media=any(show_caption_above_media),
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
),
Expand Down
7 changes: 6 additions & 1 deletion pyrogram/methods/messages/edit_message_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ async def edit_message_media(
parse_mode = media.parse_mode
caption_entities = media.caption_entities

show_caption_above_media = []

message, entities = None, None

if caption is not None:
Expand Down Expand Up @@ -148,6 +150,7 @@ async def edit_message_media(
)
else:
media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO, has_spoiler=media.has_spoiler)
show_caption_above_media.append(media.show_caption_above_media)
elif isinstance(media, types.InputMediaVideo):
if is_uploaded_file:
uploaded_media = await self.invoke(
Expand Down Expand Up @@ -188,6 +191,7 @@ async def edit_message_media(
)
else:
media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO, has_spoiler=media.has_spoiler)
show_caption_above_media.append(media.show_caption_above_media)
elif isinstance(media, types.InputMediaAudio):
if is_uploaded_file:
media = await self.invoke(
Expand Down Expand Up @@ -261,6 +265,7 @@ async def edit_message_media(
)
else:
media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION, has_spoiler=media.has_spoiler)
show_caption_above_media.append(media.show_caption_above_media)
elif isinstance(media, types.InputMediaDocument):
if is_uploaded_file:
media = await self.invoke(
Expand Down Expand Up @@ -298,7 +303,7 @@ async def edit_message_media(
reply_markup=await reply_markup.write(self) if reply_markup else None,
message=message,
entities=entities,
# TODO
invert_media=any(show_caption_above_media),
schedule_date=utils.datetime_to_timestamp(schedule_date)
)
session = None
Expand Down

0 comments on commit 9c0209a

Please sign in to comment.