fix:修改插件基类,现在支持任意类型发送

This commit is contained in:
SengokuCola
2025-05-23 10:53:18 +08:00
parent 7acee94ee4
commit 0eb1320481
5 changed files with 15 additions and 10 deletions

View File

@@ -78,7 +78,7 @@ class ExitFocusChatAction(BaseAction):
if self.sub_heartflow:
try:
# 转换为normal_chat状态
await self.sub_heartflow.change_chat_state(ChatState.NORMAL_CHAT)
await self.sub_heartflow.change_chat_state(ChatState.CHAT)
status_message = "已成功切换到普通聊天模式"
logger.info(f"{self.log_prefix} {status_message}")
except Exception as e:

View File

@@ -41,7 +41,7 @@ class PluginAction(BaseAction):
return platform, user_id
# 提供简化的API方法
async def send_message(self, text: str, target: Optional[str] = None) -> bool:
async def send_message(self, type: str, data: str, target: Optional[str] = "") -> bool:
"""发送消息的简化方法
Args:
@@ -60,7 +60,7 @@ class PluginAction(BaseAction):
return False
# 构造简化的动作数据
reply_data = {"text": text, "target": target or "", "emojis": []}
# reply_data = {"text": text, "target": target or "", "emojis": []}
# 获取锚定消息(如果有)
observations = self._services.get("observations", [])
@@ -68,7 +68,8 @@ class PluginAction(BaseAction):
chatting_observation: ChattingObservation = next(
obs for obs in observations if isinstance(obs, ChattingObservation)
)
anchor_message = chatting_observation.search_message_by_text(reply_data["target"])
anchor_message = chatting_observation.search_message_by_text(target)
# 如果没有找到锚点消息,创建一个占位符
if not anchor_message:
@@ -80,7 +81,7 @@ class PluginAction(BaseAction):
anchor_message.update_chat_stream(chat_stream)
response_set = [
("text", text),
(type, data),
]
# 调用内部方法发送消息

View File

@@ -1,7 +1,7 @@
"""测试插件动作模块"""
# 导入所有动作模块以确保装饰器被执行
# from . import test_action # noqa
from . import test_action # noqa
# from . import online_action # noqa
# from . import mute_action # noqa
from . import online_action # noqa
from . import mute_action # noqa

View File

@@ -40,7 +40,11 @@ class MuteAction(PluginAction):
await self.send_message_by_expressor(f"我要禁言{target}{platform},时长{duration}秒,理由{reason},表达情绪")
try:
await self.send_message(f"[command]mute,{user_id},{duration}")
await self.send_message(
type = "text",
data = f"[command]mute,{user_id},{duration}",
# target = target
)
except Exception as e:
logger.error(f"{self.log_prefix} 执行mute动作时出错: {e}")

View File

@@ -17,7 +17,7 @@ class CheckOnlineAction(PluginAction):
"mode参数为version时查看在线版本状态默认用这种",
"mode参数为type时查看在线系统类型分布",
]
default = True # 不是默认动作,需要手动添加到使用集
default = False # 不是默认动作,需要手动添加到使用集
async def process(self) -> Tuple[bool, str]:
"""处理测试动作"""