Feat:添加对Action插件的支持,现在可以编写插件
This commit is contained in:
1
src/plugins/__init__.py
Normal file
1
src/plugins/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""插件系统包"""
|
||||
4
src/plugins/test_plugin/__init__.py
Normal file
4
src/plugins/test_plugin/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
"""测试插件包"""
|
||||
"""
|
||||
这是一个测试插件
|
||||
"""
|
||||
6
src/plugins/test_plugin/actions/__init__.py
Normal file
6
src/plugins/test_plugin/actions/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
"""测试插件动作模块"""
|
||||
|
||||
# 导入所有动作模块以确保装饰器被执行
|
||||
from . import test_action # noqa
|
||||
# from . import online_action # noqa
|
||||
from . import mute_action # noqa
|
||||
48
src/plugins/test_plugin/actions/mute_action.py
Normal file
48
src/plugins/test_plugin/actions/mute_action.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.chat.focus_chat.planners.actions.plugin_action import PluginAction, register_action
|
||||
from typing import Tuple
|
||||
|
||||
logger = get_logger("mute_action")
|
||||
|
||||
@register_action
|
||||
class MuteAction(PluginAction):
|
||||
"""测试动作处理类"""
|
||||
|
||||
action_name = "mute_action"
|
||||
action_description = "如果某人违反了公序良俗,或者别人戳你太多,,或者某人刷屏,一定要禁言某人,如果你很生气,可以禁言某人"
|
||||
action_parameters = {
|
||||
"target": "禁言对象,输入你要禁言的对象的名字,必填,",
|
||||
"duration": "禁言时长,输入你要禁言的时长,单位为秒,必填",
|
||||
}
|
||||
action_require = [
|
||||
"当有人违反了公序良俗时使用",
|
||||
"当有人刷屏时使用",
|
||||
"当有人要求禁言自己时使用",
|
||||
"当有人戳你两次以上时,防止刷屏,禁言他,必须牢记",
|
||||
"当千石可乐或可乐酱要求你禁言时使用",
|
||||
"当你想回避某个话题时使用",
|
||||
]
|
||||
default = True # 不是默认动作,需要手动添加到使用集
|
||||
|
||||
async def process(self) -> Tuple[bool, str]:
|
||||
"""处理测试动作"""
|
||||
logger.info(f"{self.log_prefix} 执行online动作: {self.reasoning}")
|
||||
|
||||
# 发送测试消息
|
||||
target = self.action_data.get("target")
|
||||
duration = self.action_data.get("duration")
|
||||
reason = self.action_data.get("reason")
|
||||
platform, user_id = await self.get_user_id_by_person_name(target)
|
||||
|
||||
await self.send_message_by_expressor(f"我要禁言{target},{platform},时长{duration}秒,理由{reason},表达情绪")
|
||||
|
||||
try:
|
||||
await self.send_message(f"[command]mute,{user_id},{duration}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix} 执行mute动作时出错: {e}")
|
||||
await self.send_message_by_expressor(f"执行mute动作时出错: {e}")
|
||||
|
||||
return False, "执行mute动作时出错"
|
||||
|
||||
return True, "测试动作执行成功"
|
||||
44
src/plugins/test_plugin/actions/online_action.py
Normal file
44
src/plugins/test_plugin/actions/online_action.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.chat.focus_chat.planners.actions.plugin_action import PluginAction, register_action
|
||||
from typing import Tuple
|
||||
|
||||
logger = get_logger("check_online_action")
|
||||
|
||||
@register_action
|
||||
class CheckOnlineAction(PluginAction):
|
||||
"""测试动作处理类"""
|
||||
|
||||
action_name = "check_online_action"
|
||||
action_description = "这是一个检查在线状态的动作,当有人要求你检查Maibot(麦麦 机器人)在线状态时使用"
|
||||
action_parameters = {
|
||||
"mode": "查看模式"
|
||||
}
|
||||
action_require = [
|
||||
"当有人要求你检查Maibot(麦麦 机器人)在线状态时使用",
|
||||
"mode参数为version时查看在线版本状态,默认用这种",
|
||||
"mode参数为type时查看在线系统类型分布",
|
||||
]
|
||||
default = True # 不是默认动作,需要手动添加到使用集
|
||||
|
||||
async def process(self) -> Tuple[bool, str]:
|
||||
"""处理测试动作"""
|
||||
logger.info(f"{self.log_prefix} 执行online动作: {self.reasoning}")
|
||||
|
||||
# 发送测试消息
|
||||
mode = self.action_data.get("mode", "type")
|
||||
|
||||
await self.send_message_by_expressor("我看看")
|
||||
|
||||
try:
|
||||
if mode == "type":
|
||||
await self.send_message(f"#online detail")
|
||||
elif mode == "version":
|
||||
await self.send_message(f"#online")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix} 执行online动作时出错: {e}")
|
||||
await self.send_message_by_expressor("执行online动作时出错: {e}")
|
||||
|
||||
return False, "执行online动作时出错"
|
||||
|
||||
return True, "测试动作执行成功"
|
||||
38
src/plugins/test_plugin/actions/test_action.py
Normal file
38
src/plugins/test_plugin/actions/test_action.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.chat.focus_chat.planners.actions.plugin_action import PluginAction, register_action
|
||||
from typing import Tuple
|
||||
|
||||
logger = get_logger("test_action")
|
||||
|
||||
@register_action
|
||||
class TestAction(PluginAction):
|
||||
"""测试动作处理类"""
|
||||
|
||||
action_name = "test_action"
|
||||
action_description = "这是一个测试动作,当有人要求你测试插件系统时使用"
|
||||
action_parameters = {
|
||||
"test_param": "测试参数(可选)"
|
||||
}
|
||||
action_require = [
|
||||
"测试情况下使用",
|
||||
"想测试插件动作加载时使用",
|
||||
]
|
||||
default = False # 不是默认动作,需要手动添加到使用集
|
||||
|
||||
async def process(self) -> Tuple[bool, str]:
|
||||
"""处理测试动作"""
|
||||
logger.info(f"{self.log_prefix} 执行测试动作: {self.reasoning}")
|
||||
|
||||
# 获取聊天类型
|
||||
chat_type = self.get_chat_type()
|
||||
logger.info(f"{self.log_prefix} 当前聊天类型: {chat_type}")
|
||||
|
||||
# 获取最近消息
|
||||
recent_messages = self.get_recent_messages(3)
|
||||
logger.info(f"{self.log_prefix} 最近3条消息: {recent_messages}")
|
||||
|
||||
# 发送测试消息
|
||||
test_param = self.action_data.get("test_param", "默认参数")
|
||||
await self.send_message_by_expressor(f"测试动作执行成功,参数: {test_param}")
|
||||
|
||||
return True, "测试动作执行成功"
|
||||
Reference in New Issue
Block a user