From 96093306e1899963675c6a545b7e6e832793206c Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Wed, 1 Oct 2025 23:49:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(plugin=5Fsystem):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=20send=5Fcommand=20=E4=BB=A5=E5=AF=B9=E6=8E=A5=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=99=A8=E4=B8=93=E7=94=A8=E5=91=BD=E4=BB=A4=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BaseAction 中的 send_command 方法已重构,从使用通用的 `command_to_stream` API 切换到新的 `adapter_command_to_stream` API。 这一变更带来了以下改进: - **接口统一**: 所有与平台适配器直接交互的命令现在都通过专用的接口,使得逻辑更清晰。 - **参数结构化**: 调用参数从旧的 `{"name": ..., "args": ...}` 格式更新为更明确的 `action`, `params` 和 `platform`。 - **健壮的响应处理**: 现在会解析 API 返回的结构化 JSON 响应(包含 status 和 message),以实现更精确的成功/失败判断和错误日志记录。 BREAKING CHANGE: `send_command` 调用的 `command_name` 现在需要与目标平台适配器定义的 `action` 名称完全匹配。例如,在 `social_toolkit_plugin` 中,`set_emoji_like` 已更新为 `set_msg_emoji_like`。所有使用此方法的插件可能需要更新其命令名称。 --- src/plugin_system/base/base_action.py | 22 +++++++++---------- .../built_in/social_toolkit_plugin/plugin.py | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/plugin_system/base/base_action.py b/src/plugin_system/base/base_action.py index 003d04f9b..a4d50631c 100644 --- a/src/plugin_system/base/base_action.py +++ b/src/plugin_system/base/base_action.py @@ -382,21 +382,21 @@ class BaseAction(ABC): # 构造命令数据 command_data = {"name": command_name, "args": args or {}} - success = await send_api.command_to_stream( - command=command_data, + response = await send_api.adapter_command_to_stream( + action=command_name, + params=args or {}, stream_id=self.chat_id, - storage_message=storage_message, - display_message=display_message, - set_reply=set_reply, - reply_message=reply_message, + platform=self.platform ) - if success: - logger.info(f"{self.log_prefix} 成功发送命令: {command_name}") + # 根据响应判断成功与否 + if response and response.get("status") == "ok": + logger.info(f"{self.log_prefix} 成功执行适配器命令: {command_name}, 响应: {response.get('data')}") + return True else: - logger.error(f"{self.log_prefix} 发送命令失败: {command_name}") - - return success + error_message = response.get('message', '未知错误') + logger.error(f"{self.log_prefix} 执行适配器命令失败: {command_name}, 错误: {error_message}") + return False except Exception as e: logger.error(f"{self.log_prefix} 发送命令时出错: {e}") diff --git a/src/plugins/built_in/social_toolkit_plugin/plugin.py b/src/plugins/built_in/social_toolkit_plugin/plugin.py index 98430bbf8..d31d34dee 100644 --- a/src/plugins/built_in/social_toolkit_plugin/plugin.py +++ b/src/plugins/built_in/social_toolkit_plugin/plugin.py @@ -316,7 +316,7 @@ class SetEmojiLikeAction(BaseAction): try: # 使用适配器API发送贴表情命令 success = await self.send_command( - command_name="set_emoji_like", + command_name="set_msg_emoji_like", args={"message_id": message_id, "emoji_id": emoji_id, "set": set_like}, storage_message=False, )