From dcf4912a7df5062d14e950db7efd5da6f2a6ad5f Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Thu, 6 Nov 2025 23:56:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(napcat):=20=E4=BF=AE=E5=A4=8DJSON=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=A4=84=E7=90=86=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - **修复(bug)**: 解决了在处理 `json` 类型的消息段时,因未导入 `json` 模块而导致的 `NameError` 运行时错误。 - **优化(refactor)**: 根据项目规范,将 `json` 模块的调用全部替换为性能更优的 `orjson`,并移除了多余的 `import` 语句,提升了代码质量和运行效率。 --- .../napcat_adapter_plugin/src/recv_handler/message_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py b/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py index 25219f7bc..c47ad46ad 100644 --- a/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py +++ b/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py @@ -786,7 +786,7 @@ class MessageHandler: try: # 尝试将json_data解析为Python对象 - nested_data = json.loads(json_data) + nested_data = orjson.loads(json_data) # 检查是否是机器人自己上传文件的回声 if self._is_file_upload_echo(nested_data): @@ -911,7 +911,7 @@ class MessageHandler: # 如果没有提取到关键信息,返回None return None - except json.JSONDecodeError: + except orjson.JSONDecodeError: # 如果解析失败,我们假设它不是我们关心的任何一种结构化JSON, # 而是普通的文本或者无法解析的格式。 logger.debug(f"无法将data字段解析为JSON: {json_data}")