Skip to content

Commit

Permalink
Fix: 多个消息段转图片后显示异常 (#6)
Browse files Browse the repository at this point in the history
* 🐛 修复多个消息段转图片后显示异常的问题

* 🍻 apply suggestions from code review
  • Loading branch information
KomoriDev authored Jan 15, 2025
1 parent 45f2a8c commit cbef2e1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions marisa/extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nonebot_plugin_htmlrender import text_to_pic
from nonebot_plugin_alconna.uniseg import UniMessage
from nonebot.internal.adapter import Bot, Event, Message
from nonebot_plugin_alconna.uniseg import Text, UniMessage
from nonebot_plugin_alconna.extension import Extension, add_global_extension

from .configs import TEMPLATE_DIR, config
Expand All @@ -17,12 +17,21 @@ def id(self) -> str:

async def send_wrapper(
self, bot: Bot, event: Event, send: str | Message | UniMessage
):
if config.basic.send_with_image:
return UniMessage.image(
raw=await text_to_pic(
str(send), css_path=str(TEMPLATE_DIR / "message.css")
) -> str | Message | UniMessage:
plain_text = (
send.extract_plain_text()
if isinstance(send, Message | UniMessage)
else send
)
extra_segment = send.exclude(Text) if isinstance(send, UniMessage) else send
if config.basic.send_with_image and plain_text:
return (
UniMessage.image(
raw=await text_to_pic(
plain_text, css_path=str(TEMPLATE_DIR / "message.css")
)
)
+ extra_segment
)
return send

Expand Down

0 comments on commit cbef2e1

Please sign in to comment.