Fix captions not being preserved when editing media

This commit is contained in:
Dan 2021-01-08 09:02:29 +01:00
parent 15f95a0706
commit 51f771457c
7 changed files with 23 additions and 12 deletions

View File

@ -80,6 +80,11 @@ class EditMessageMedia(Scaffold):
caption = media.caption
parse_mode = media.parse_mode
message, entities = None, None
if caption is not None:
message, entities = (await self.parser.parse(caption, parse_mode)).values()
if isinstance(media, types.InputMediaPhoto):
if os.path.isfile(media.media):
media = await self.send(
@ -253,7 +258,8 @@ class EditMessageMedia(Scaffold):
id=message_id,
media=media,
reply_markup=reply_markup.write() if reply_markup else None,
**await self.parser.parse(caption, parse_mode)
message=message,
entities=entities
)
)

View File

@ -265,7 +265,7 @@ class SendMediaGroup(Scaffold):
raw.types.InputSingleMedia(
media=media,
random_id=self.rnd_id(),
**await self.parser.parse(i.caption, i.parse_mode)
**await self.parser.parse(i.caption or "", i.parse_mode)
)
)

View File

@ -38,7 +38,8 @@ class InputMediaAnimation(InputMedia):
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the animation to be sent, 0-1024 characters
Caption of the animation to be sent, 0-1024 characters.
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
@ -64,7 +65,7 @@ class InputMediaAnimation(InputMedia):
self,
media: str,
thumb: str = None,
caption: str = "",
caption: str = None,
parse_mode: Optional[str] = object,
caption_entities: List[MessageEntity] = None,
width: int = 0,

View File

@ -40,7 +40,8 @@ class InputMediaAudio(InputMedia):
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the audio to be sent, 0-1024 characters
Caption of the audio to be sent, 0-1024 characters.
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
@ -66,7 +67,7 @@ class InputMediaAudio(InputMedia):
self,
media: str,
thumb: str = None,
caption: str = "",
caption: str = None,
parse_mode: Optional[str] = object,
caption_entities: List[MessageEntity] = None,
duration: int = 0,

View File

@ -38,7 +38,8 @@ class InputMediaDocument(InputMedia):
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the document to be sent, 0-1024 characters
Caption of the document to be sent, 0-1024 characters.
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
@ -55,7 +56,7 @@ class InputMediaDocument(InputMedia):
self,
media: str,
thumb: str = None,
caption: str = "",
caption: str = None,
parse_mode: Optional[str] = object,
caption_entities: List[MessageEntity] = None
):

View File

@ -34,7 +34,8 @@ class InputMediaPhoto(InputMedia):
Sending photo by a URL is currently unsupported.
caption (``str``, *optional*):
Caption of the photo to be sent, 0-1024 characters
Caption of the photo to be sent, 0-1024 characters.
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
@ -50,7 +51,7 @@ class InputMediaPhoto(InputMedia):
def __init__(
self,
media: str,
caption: str = "",
caption: str = None,
parse_mode: Optional[str] = object,
caption_entities: List[MessageEntity] = None
):

View File

@ -40,7 +40,8 @@ class InputMediaVideo(InputMedia):
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the video to be sent, 0-1024 characters
Caption of the video to be sent, 0-1024 characters.
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
@ -69,7 +70,7 @@ class InputMediaVideo(InputMedia):
self,
media: str,
thumb: str = None,
caption: str = "",
caption: str = None,
parse_mode: Optional[str] = object,
caption_entities: List[MessageEntity] = None,
width: int = 0,