fix(chat): 修复并优化消息回复与ID处理逻辑
先前的消息回复机制存在多个问题:回复行为随机且不可靠,临时消息ID生成逻辑过于复杂,且在规划和执行过程中ID转换容易出错,导致回复失败。 本次提交通过以下几点进行了全面的修复与优化: - **简化ID生成**:将临时的上下文消息ID生成逻辑从“索引+随机数”简化为纯索引(如 `m1`, `m2`),使其更可预测且易于调试。 - **修正ID替换**:在 `plan_filter` 中增加了关键逻辑,确保在执行 `reply` 动作前,将计划中使用的临时 `target_message_id` 替换为真实的数据库消息ID。 - **稳定回复行为**:移除了 `action_manager` 中的随机回复判断,现在只要存在上下文消息,就会触发引用回复。同时将各 `send_api` 的 `set_reply` 参数默认值改为 `True`,使回复成为默认行为。 - **增强ID兼容性**:修复了 `napcat_adapter` 中将消息ID强制转换为整数的问题,并为 `send_api` 增加了ID回退查找,提高了对不同平台消息ID格式的兼容性。
This commit is contained in:
@@ -80,7 +80,7 @@ def message_dict_to_message_recv(message_dict: Dict[str, Any]) -> Optional[Messa
|
||||
|
||||
message_info = {
|
||||
"platform": message_dict.get("chat_info_platform", ""),
|
||||
"message_id": message_dict.get("message_id"),
|
||||
"message_id": message_dict.get("message_id") or message_dict.get("chat_info_message_id"),
|
||||
"time": message_dict.get("time"),
|
||||
"group_info": group_info,
|
||||
"user_info": user_info,
|
||||
@@ -89,13 +89,13 @@ def message_dict_to_message_recv(message_dict: Dict[str, Any]) -> Optional[Messa
|
||||
"template_info": template_info,
|
||||
}
|
||||
|
||||
message_dict = {
|
||||
new_message_dict = {
|
||||
"message_info": message_info,
|
||||
"raw_message": message_dict.get("processed_plain_text"),
|
||||
"processed_plain_text": message_dict.get("processed_plain_text"),
|
||||
}
|
||||
|
||||
message_recv = MessageRecv(message_dict)
|
||||
message_recv = MessageRecv(new_message_dict)
|
||||
|
||||
logger.info(f"[SendAPI] 找到匹配的回复消息,发送者: {message_dict.get('user_nickname', '')}")
|
||||
return message_recv
|
||||
@@ -246,7 +246,7 @@ async def text_to_stream(
|
||||
typing: bool = False,
|
||||
reply_to: str = "",
|
||||
reply_to_message: Optional[Dict[str, Any]] = None,
|
||||
set_reply: bool = False,
|
||||
set_reply: bool = True,
|
||||
storage_message: bool = True,
|
||||
) -> bool:
|
||||
"""向指定流发送文本消息
|
||||
@@ -275,7 +275,7 @@ async def text_to_stream(
|
||||
|
||||
|
||||
async def emoji_to_stream(
|
||||
emoji_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False
|
||||
emoji_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = True
|
||||
) -> bool:
|
||||
"""向指定流发送表情包
|
||||
|
||||
@@ -293,7 +293,7 @@ async def emoji_to_stream(
|
||||
|
||||
|
||||
async def image_to_stream(
|
||||
image_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False
|
||||
image_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = True
|
||||
) -> bool:
|
||||
"""向指定流发送图片
|
||||
|
||||
@@ -315,7 +315,7 @@ async def command_to_stream(
|
||||
stream_id: str,
|
||||
storage_message: bool = True,
|
||||
display_message: str = "",
|
||||
set_reply: bool = False,
|
||||
set_reply: bool = True,
|
||||
) -> bool:
|
||||
"""向指定流发送命令
|
||||
|
||||
@@ -340,7 +340,7 @@ async def custom_to_stream(
|
||||
typing: bool = False,
|
||||
reply_to: str = "",
|
||||
reply_to_message: Optional[Dict[str, Any]] = None,
|
||||
set_reply: bool = False,
|
||||
set_reply: bool = True,
|
||||
storage_message: bool = True,
|
||||
show_log: bool = True,
|
||||
) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user