feat(emoji): 增强消息上下文下的表情选择并修复存储用户信息的问题

该提交对表情操作及相关消息发送 API 进行了重大改进。

现在,表情选择逻辑更加具备上下文感知能力。LLM 提示现在包括机器人的待发送回复内容,使其能够根据对话历史和自身回复选择更合适的表情。用于上下文的近期聊天记录也有所增加。

此外,修复了插件发送 API (`send_api`) 中的一个错误。之前,当机器人发送消息时,消息在数据库中存储的是接收者的用户信息,而非机器人的信息。本次提交通过显式传递并使用机器人的用户信息进行存储,确保消息历史准确反映发送者。

其他更改包括:
- 重构表情操作的激活逻辑以提高清晰度。
- 改进 LLM 选择的表情描述匹配算法。- 为配置访问添加必要的类型安全检查。
This commit is contained in:
tt-P607
2025-11-28 15:24:08 +08:00
parent 876f20e847
commit 103a6edaf3
3 changed files with 72 additions and 59 deletions

View File

@@ -192,6 +192,7 @@ def _build_message_envelope(
timestamp: float,
) -> MessageEnvelope:
"""构建发送的 MessageEnvelope 数据结构"""
# 这里的 user_info 决定了消息要发给谁,所以在私聊场景下必须是目标用户
target_user_info = target_stream.user_info or bot_user_info
message_info: dict[str, Any] = {
"message_id": message_id,
@@ -212,7 +213,7 @@ def _build_message_envelope(
"platform": target_stream.group_info.platform,
}
return {
return { # type: ignore
"id": str(uuid.uuid4()),
"direction": "outgoing",
"platform": target_stream.platform,
@@ -257,9 +258,14 @@ async def _send_to_target(
current_time = time.time()
message_id = f"send_api_{int(current_time * 1000)}"
bot_config = global_config.bot
if not bot_config:
logger.error("机器人配置丢失,无法构建机器人用户信息")
return False
bot_user_info = DatabaseUserInfo(
user_id=str(global_config.bot.qq_account),
user_nickname=global_config.bot.nickname,
user_id=str(bot_config.qq_account),
user_nickname=bot_config.nickname,
platform=target_stream.platform,
)
@@ -328,6 +334,7 @@ async def _send_to_target(
show_log=show_log,
thinking_start_time=current_time,
display_message=display_message_for_db,
storage_user_info=bot_user_info,
)
if sent_msg: