From 73983c7198d0c00d4a931df39848447dba562edf Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Mon, 27 Oct 2025 00:38:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(file):=20=E4=BF=AE=E5=A4=8D=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA=E5=AF=B9=E8=87=AA=E8=BA=AB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84=E5=93=8D=E5=BA=94=E5=B9=B6=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E7=A1=AC=E7=BC=96=E7=A0=81=E8=B7=AF=E5=BE=84=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在群文件上传通知中,增加对`self_id`的判断,使机器人忽略自身上传文件的事件,防止不必要的响应。 - 移除 `send_api` 与 `send_handler` 中硬编码的WSL路径转换逻辑,以实现更通用的路径处理。 - 增强文件发送逻辑,使其能处理路径数据为字典的情况并检查空路径。 --- src/plugin_system/apis/send_api.py | 6 ------ .../src/recv_handler/notice_handler.py | 8 ++++++-- .../napcat_adapter_plugin/src/send_handler.py | 11 ++++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/plugin_system/apis/send_api.py b/src/plugin_system/apis/send_api.py index eae512dfb..feb18848b 100644 --- a/src/plugin_system/apis/send_api.py +++ b/src/plugin_system/apis/send_api.py @@ -56,12 +56,6 @@ async def file_to_stream( if not file_name: file_name = Path(file_path).name - # 临时的WSL路径转换方案 - if file_path.startswith("E:"): - original_path = file_path - file_path = "/mnt/e/" + file_path[3:].replace("\\", "/") - logger.info(f"WSL路径转换: {original_path} -> {file_path}") - params = { "file": file_path, "name": file_name, diff --git a/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/notice_handler.py b/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/notice_handler.py index 0f08b32f9..6bc473621 100644 --- a/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/notice_handler.py +++ b/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/notice_handler.py @@ -100,6 +100,7 @@ class NoticeHandler: # message_time: int = raw_message.get("time") message_time: float = time.time() # 应可乐要求,现在是float了 + self_id = raw_message.get("self_id") group_id = raw_message.get("group_id") user_id = raw_message.get("user_id") target_id = raw_message.get("target_id") @@ -161,9 +162,12 @@ class NoticeHandler: logger.warning(f"不支持的group_ban类型: {notice_type}.{sub_type}") case NoticeType.group_upload: logger.info("群文件上传") + if user_id == self_id: + logger.info("检测到机器人自己上传文件,忽略此通知") + return None if not await message_handler.check_allow_to_chat(user_id, group_id, False, False): return None - handled_message, user_info = await self.handle_group_upload_notify(raw_message, group_id, user_id) + handled_message, user_info = await self.handle_group_upload_notify(raw_message, group_id, user_id, self_id) case _: logger.warning(f"不支持的notice类型: {notice_type}") return None @@ -382,7 +386,7 @@ class NoticeHandler: seg_data = Seg(type="text",data=f"{user_name}使用Emoji表情{QQ_FACE.get(like_emoji_id,"")}回复了你的消息[{target_message_text}]") return seg_data, user_info - async def handle_group_upload_notify(self, raw_message: dict, group_id: int, user_id: int): + async def handle_group_upload_notify(self, raw_message: dict, group_id: int, user_id: int, self_id: int): if not group_id: logger.error("群ID不能为空,无法处理群文件上传通知") return None, None diff --git a/src/plugins/built_in/napcat_adapter_plugin/src/send_handler.py b/src/plugins/built_in/napcat_adapter_plugin/src/send_handler.py index 8426147d8..f586ae0da 100644 --- a/src/plugins/built_in/napcat_adapter_plugin/src/send_handler.py +++ b/src/plugins/built_in/napcat_adapter_plugin/src/send_handler.py @@ -274,6 +274,9 @@ class SendHandler: new_payload = self.build_payload(payload, self.handle_videourl_message(video_url), False) elif seg.type == "file": file_path = seg.data + file_path = seg.data + if isinstance(file_path, dict): + file_path = file_path.get("file", "") new_payload = self.build_payload(payload, self.handle_file_message(file_path), False) return new_payload @@ -411,11 +414,9 @@ class SendHandler: def handle_file_message(self, file_path: str) -> dict: """处理文件消息""" - # 临时的WSL路径转换方案 - if file_path.startswith("E:"): - original_path = file_path - file_path = "/mnt/e/" + file_path[3:].replace("\\", "/") - logger.info(f"WSL路径转换: {original_path} -> {file_path}") + if not file_path: + logger.error("文件路径为空") + return {} return { "type": "file",