feat: 添加转发消息配置,支持图片数量阈值设置

pull/76/head
墨梓柒 2026-01-03 14:03:14 +08:00
parent efd98b022f
commit 3ec1499324
No known key found for this signature in database
GPG Key ID: 4A65B9DBA35F7635
4 changed files with 21 additions and 5 deletions

View File

@ -14,6 +14,7 @@ from src.config.config_base import ConfigBase
from src.config.official_configs import (
ChatConfig,
DebugConfig,
ForwardConfig,
MaiBotServerConfig,
NapcatServerConfig,
NicknameConfig,
@ -117,6 +118,7 @@ class Config(ConfigBase):
maibot_server: MaiBotServerConfig
chat: ChatConfig
voice: VoiceConfig
forward: ForwardConfig
debug: DebugConfig

View File

@ -77,6 +77,14 @@ class VoiceConfig(ConfigBase):
"""是否启用TTS功能"""
@dataclass
class ForwardConfig(ConfigBase):
"""转发消息相关配置"""
image_threshold: int = 3
"""图片数量阈值转发消息中图片数量超过此值时使用占位符代替base64发送避免麦麦VLM处理卡死"""
@dataclass
class DebugConfig(ConfigBase):
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"

View File

@ -662,14 +662,17 @@ class MessageHandler:
forward_header = Seg(type="text", data="========== 转发消息开始 ==========\n")
forward_footer = Seg(type="text", data="========== 转发消息结束 ==========")
if image_count < 5 and image_count > 0:
# 处理图片数量小于5的情况此时解析图片为base64
logger.trace("图片数量小于5开始解析图片为base64")
# 图片阈值超过此数量使用占位符避免麦麦VLM处理卡死
image_threshold = global_config.forward.image_threshold
if image_count < image_threshold and image_count > 0:
# 处理图片数量小于阈值的情况此时解析图片为base64
logger.trace(f"图片数量({image_count})小于{image_threshold}开始解析图片为base64")
parsed_message = await self._recursive_parse_image_seg(handled_message, True)
return Seg(type="seglist", data=[forward_header, parsed_message, forward_footer])
elif image_count > 0:
logger.trace("图片数量大于等于5,开始解析图片为占位符")
# 处理图片数量大于等于5的情况,此时解析图片为占位符
logger.trace(f"图片数量({image_count})大于等于{image_threshold},开始解析图片为占位符")
# 处理图片数量大于等于阈值的情况,此时解析图片为占位符
parsed_message = await self._recursive_parse_image_seg(handled_message, False)
return Seg(type="seglist", data=[forward_header, parsed_message, forward_footer])
else:

View File

@ -31,5 +31,8 @@ enable_poke = true # 是否启用戳一戳功能
[voice] # 发送语音设置
use_tts = false # 是否使用tts语音请确保你配置了tts并有对应的adapter
[forward] # 转发消息处理设置
image_threshold = 3 # 图片数量阈值:转发消息中图片数量超过此值时使用占位符(避免麦麦VLM处理卡死)
[debug]
level = "INFO" # 日志等级DEBUG, INFO, WARNING, ERROR, CRITICAL