mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
✨ 提供全局图片统一bytes发送配置
This commit is contained in:
parent
e0a3fe526e
commit
d05b1fb9b2
6
.env.dev
6
.env.dev
@ -10,6 +10,9 @@ NICKNAME=["真寻", "小真寻", "绪山真寻", "小寻子"]
|
||||
|
||||
SESSION_EXPIRE_TIMEOUT=30
|
||||
|
||||
# 全局图片统一使用bytes发送,当真寻与协议端不在同一服务器上时为True
|
||||
IMAGE_TO_BYTES = False
|
||||
|
||||
PLATFORM_SUPERUSERS = '
|
||||
{
|
||||
"qq": [""],
|
||||
@ -17,7 +20,6 @@ PLATFORM_SUPERUSERS = '
|
||||
}
|
||||
'
|
||||
|
||||
# DRIVER=~fastapi
|
||||
DRIVER=~fastapi+~httpx+~websockets
|
||||
|
||||
# kook adapter toekn
|
||||
@ -51,7 +53,7 @@ DRIVER=~fastapi+~httpx+~websockets
|
||||
# application_commands的{"*": ["*"]}代表将全部应用命令注册为全局应用命令
|
||||
# {"admin": ["123", "456"]}则代表将admin命令注册为id是123、456服务器的局部命令,其余命令不注册
|
||||
|
||||
LOG_LEVEL=DEBUG
|
||||
# LOG_LEVEL=DEBUG
|
||||
# 服务器和端口
|
||||
HOST = 127.0.0.1
|
||||
PORT = 8080
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user