✨ 提供全局图片统一bytes发送配置

This commit is contained in:
HibiKier
2024-08-10 02:38:41 +08:00
parent e0a3fe526e
commit d05b1fb9b2
2 changed files with 13 additions and 3 deletions
+9 -1
View File
@@ -1,6 +1,7 @@
from io import BytesIO
from pathlib import Path
import nonebot
from nonebot.adapters.onebot.v11 import Message, MessageSegment
from nonebot_plugin_alconna import At, Image, Text, UniMessage
@@ -8,6 +9,8 @@ from zhenxun.configs.config import NICKNAME
from zhenxun.services.log import logger
from zhenxun.utils._build_image import BuildImage
driver = nonebot.get_driver()
MESSAGE_TYPE = (
str | int | float | Path | bytes | BytesIO | BuildImage | At | Image | Text
)
@@ -25,6 +28,7 @@ class MessageUtils:
返回:
list[Text | Text]: 构造完成的消息列表
"""
is_bytes = driver.config.image_to_bytes == "True"
message_list = []
for msg in msg_list:
if isinstance(msg, (Image, Text, At)):
@@ -33,7 +37,11 @@ class MessageUtils:
message_list.append(Text(str(msg)))
elif isinstance(msg, Path):
if msg.exists():
message_list.append(Image(path=msg))
if is_bytes:
image = BuildImage.open(msg)
message_list.append(Image(raw=image.pic2bytes()))
else:
message_list.append(Image(path=msg))
else:
logger.warning(f"图片路径不存在: {msg}")
elif isinstance(msg, bytes):