chore(napcat_adapter): 增加消息发送与回复处理的详细日志
为了方便排查消息发送失败或引用回复行为不符合预期的问题,在消息发送和回复处理的关键路径上增加了详细的日志输出。 - 在调用 NapCat 发送接口前,记录准备发送的完整消息体。 - 在 `handle_reply_message` 方法中,记录获取被引用消息详情、判断是否 @ 用户以及最终返回的消息段等步骤。
This commit is contained in:
committed by
Windpicker-owo
parent
9422d1d547
commit
6ecfd85617
908
app_20250924_114845.log.jsonl
Normal file
908
app_20250924_114845.log.jsonl
Normal file
File diff suppressed because one or more lines are too long
696
app_20250924_115355.log.jsonl
Normal file
696
app_20250924_115355.log.jsonl
Normal file
File diff suppressed because one or more lines are too long
@@ -96,6 +96,7 @@ class SendHandler:
|
|||||||
logger.error("无法识别的消息类型")
|
logger.error("无法识别的消息类型")
|
||||||
return None
|
return None
|
||||||
logger.info("尝试发送到napcat")
|
logger.info("尝试发送到napcat")
|
||||||
|
logger.info(f"准备发送到napcat的消息体: action='{action}', {id_name}='{target_id}', message='{processed_message}'")
|
||||||
response = await self.send_message_to_napcat(
|
response = await self.send_message_to_napcat(
|
||||||
action,
|
action,
|
||||||
{
|
{
|
||||||
@@ -294,14 +295,17 @@ class SendHandler:
|
|||||||
|
|
||||||
async def handle_reply_message(self, id: str, user_info: UserInfo) -> dict | list:
|
async def handle_reply_message(self, id: str, user_info: UserInfo) -> dict | list:
|
||||||
"""处理回复消息"""
|
"""处理回复消息"""
|
||||||
|
logger.info(f"开始处理回复消息,消息ID: {id}")
|
||||||
reply_seg = {"type": "reply", "data": {"id": id}}
|
reply_seg = {"type": "reply", "data": {"id": id}}
|
||||||
|
|
||||||
# 检查是否启用引用艾特功能
|
# 检查是否启用引用艾特功能
|
||||||
if not config_api.get_plugin_config(self.plugin_config, "features.enable_reply_at", False):
|
if not config_api.get_plugin_config(self.plugin_config, "features.enable_reply_at", False):
|
||||||
|
logger.info("引用艾特功能未启用,仅发送普通回复")
|
||||||
return reply_seg
|
return reply_seg
|
||||||
|
|
||||||
try:
|
try:
|
||||||
msg_info_response = await self.send_message_to_napcat("get_msg", {"message_id": id})
|
msg_info_response = await self.send_message_to_napcat("get_msg", {"message_id": id})
|
||||||
|
logger.info(f"获取消息 {id} 的详情响应: {msg_info_response}")
|
||||||
|
|
||||||
replied_user_id = None
|
replied_user_id = None
|
||||||
if msg_info_response and msg_info_response.get("status") == "ok":
|
if msg_info_response and msg_info_response.get("status") == "ok":
|
||||||
@@ -312,6 +316,7 @@ class SendHandler:
|
|||||||
# 如果没有获取到被回复者的ID,则直接返回,不进行@
|
# 如果没有获取到被回复者的ID,则直接返回,不进行@
|
||||||
if not replied_user_id:
|
if not replied_user_id:
|
||||||
logger.warning(f"无法获取消息 {id} 的发送者信息,跳过 @")
|
logger.warning(f"无法获取消息 {id} 的发送者信息,跳过 @")
|
||||||
|
logger.info(f"最终返回的回复段: {reply_seg}")
|
||||||
return reply_seg
|
return reply_seg
|
||||||
|
|
||||||
# 根据概率决定是否艾特用户
|
# 根据概率决定是否艾特用户
|
||||||
@@ -319,13 +324,17 @@ class SendHandler:
|
|||||||
at_seg = {"type": "at", "data": {"qq": str(replied_user_id)}}
|
at_seg = {"type": "at", "data": {"qq": str(replied_user_id)}}
|
||||||
# 在艾特后面添加一个空格
|
# 在艾特后面添加一个空格
|
||||||
text_seg = {"type": "text", "data": {"text": " "}}
|
text_seg = {"type": "text", "data": {"text": " "}}
|
||||||
return [reply_seg, at_seg, text_seg]
|
result_seg = [reply_seg, at_seg, text_seg]
|
||||||
|
logger.info(f"最终返回的回复段: {result_seg}")
|
||||||
|
return result_seg
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"处理引用回复并尝试@时出错: {e}")
|
logger.error(f"处理引用回复并尝试@时出错: {e}")
|
||||||
# 出现异常时,只发送普通的回复,避免程序崩溃
|
# 出现异常时,只发送普通的回复,避免程序崩溃
|
||||||
|
logger.info(f"最终返回的回复段: {reply_seg}")
|
||||||
return reply_seg
|
return reply_seg
|
||||||
|
|
||||||
|
logger.info(f"最终返回的回复段: {reply_seg}")
|
||||||
return reply_seg
|
return reply_seg
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user