From e3b08b29820a0a3e612e9a1bd5d0bf63202d3506 Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Wed, 24 Sep 2025 18:58:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(set=5Femoji=5Flike):=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20send=5Fcommand=20=E6=96=B9=E6=B3=95=E5=8F=91?= =?UTF-8?q?=E9=80=81=E8=A1=A8=E6=83=85=E5=9B=9E=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原先直接调用底层 `adapter_command_to_stream` 的方式重构为使用封装好的 `self.send_command` 辅助方法。 此次重构简化了动作实现代码,提高了可读性,并更好地封装了命令发送的逻辑。 --- plugins/set_emoji_like/plugin.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/plugins/set_emoji_like/plugin.py b/plugins/set_emoji_like/plugin.py index d7a42ae23..ac7c8106a 100644 --- a/plugins/set_emoji_like/plugin.py +++ b/plugins/set_emoji_like/plugin.py @@ -125,31 +125,25 @@ class SetEmojiLikeAction(BaseAction): try: # 使用适配器API发送贴表情命令 - response = await send_api.adapter_command_to_stream( - action="set_msg_emoji_like", - params={"message_id": message_id, "emoji_id": emoji_id, "set": set_like}, - stream_id=self.chat_stream.stream_id if self.chat_stream else None, - timeout=30.0, - storage_message=False, + success = await self.send_command( + command_name="set_emoji_like", args={"message_id": message_id, "emoji_id": emoji_id, "set": set_like}, storage_message=False ) - - if response["status"] == "ok": - logger.info(f"设置表情回应成功: {response}") + if success: + logger.info("设置表情回应成功") await self.store_action_info( action_build_into_prompt=True, action_prompt_display=f"执行了set_emoji_like动作,{emoji_input},设置表情回应: {emoji_id}, 是否设置: {set_like}", action_done=True, ) - return True, f"成功设置表情回应: {response.get('message', '成功')}" + return True, "成功设置表情回应" else: - error_msg = response.get("message", "未知错误") - logger.error(f"设置表情回应失败: {error_msg}") + logger.error("设置表情回应失败") await self.store_action_info( action_build_into_prompt=True, - action_prompt_display=f"执行了set_emoji_like动作:{self.action_name},失败: {error_msg}", + action_prompt_display=f"执行了set_emoji_like动作:{self.action_name},失败", action_done=False, ) - return False, f"设置表情回应失败: {error_msg}" + return False, "设置表情回应失败" except Exception as e: logger.error(f"设置表情回应失败: {e}")