refactor(set_emoji_like): 使用 send_command 方法发送表情回应

将原先直接调用底层 `adapter_command_to_stream` 的方式重构为使用封装好的 `self.send_command` 辅助方法。

此次重构简化了动作实现代码,提高了可读性,并更好地封装了命令发送的逻辑。
This commit is contained in:
minecraft1024a
2025-09-24 18:58:46 +08:00
parent 7607b08cc2
commit e3b08b2982

View File

@@ -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}")