Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
✨ 支持更多文本样式 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
MingxuanGame authored Dec 16, 2023
1 parent 7a137a7 commit e203e85
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion hertavilla/message/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ def __init_subclass__(cls) -> None:


class Text(_TextEntity):
def __init__(self, text: str) -> None:
def __init__(
self,
text: str,
*styles: Literal["bold", "italic", "strikethrough", "underline"],
) -> None:
self.text = text
self.styles = styles

async def get_text(self, _: VillaBot) -> str:
return self.text
Expand Down Expand Up @@ -198,6 +203,16 @@ async def text_to_content(
if isinstance(entity, Text):
text = str(entity)
length = len(text)
entities.extend(
(
{
"entity": {"type": "style", "font_style": style},
"length": length,
"offset": offset,
}
for style in entity.styles
),
)
else:
text = f"{await entity.get_text(bot)}{space}"
length = _c(text)
Expand Down

0 comments on commit e203e85

Please sign in to comment.