mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added html/md_text properties to Message object and refactor I18n context
This commit is contained in:
parent
481aec2144
commit
c19cbc6a5f
10 changed files with 99 additions and 28 deletions
|
|
@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, List, Optional, Union
|
|||
from pydantic import Field
|
||||
|
||||
from aiogram.utils import helper
|
||||
from aiogram.utils.text_decorations import TextDecoration, html_decoration, markdown_decoration
|
||||
|
||||
from .base import UNSET, TelegramObject
|
||||
|
||||
|
|
@ -259,6 +260,22 @@ class Message(TelegramObject):
|
|||
|
||||
return ContentType.UNKNOWN
|
||||
|
||||
def _unparse_entities(self, text_decoration: TextDecoration) -> str:
|
||||
text = self.text or self.caption
|
||||
if text is None:
|
||||
raise TypeError("This message doesn't have any text.")
|
||||
|
||||
entities = self.entities or self.caption_entities
|
||||
return text_decoration.unparse(text=text, entities=entities)
|
||||
|
||||
@property
|
||||
def html_text(self) -> str:
|
||||
return self._unparse_entities(html_decoration)
|
||||
|
||||
@property
|
||||
def md_text(self) -> str:
|
||||
return self._unparse_entities(markdown_decoration)
|
||||
|
||||
def reply_animation(
|
||||
self,
|
||||
animation: Union[InputFile, str],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue