fix:修复禁言插件

This commit is contained in:
SengokuCola
2025-05-27 17:07:51 +08:00
parent 0391111c82
commit 548a583cc7
8 changed files with 140 additions and 78 deletions

View File

@@ -3,5 +3,5 @@
# 导入所有动作模块以确保装饰器被执行
from . import test_action # noqa
from . import online_action # noqa
# from . import online_action # noqa
from . import mute_action # noqa

View File

@@ -0,0 +1,73 @@
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("group_whole_ban_action")
@register_action
class GroupWholeBanAction(PluginAction):
"""群聊全体禁言动作处理类"""
action_name = "group_whole_ban_action"
action_description = (
"开启或关闭群聊全体禁言,当群聊过于混乱或需要安静时使用"
)
action_parameters = {
"enable": "是否开启全体禁言输入True开启False关闭必填",
}
action_require = [
"当群聊过于混乱需要安静时使用",
"当需要临时暂停群聊讨论时使用",
"当有人要求开启全体禁言时使用",
"当管理员需要发布重要公告时使用",
]
default = False
associated_types = ["command", "text"]
async def process(self) -> Tuple[bool, str]:
"""处理群聊全体禁言动作"""
logger.info(f"{self.log_prefix} 执行全体禁言动作: {self.reasoning}")
# 获取参数
enable = self.action_data.get("enable")
if enable is None:
error_msg = "全体禁言参数不完整需要enable参数"
logger.error(f"{self.log_prefix} {error_msg}")
return False, error_msg
# 确保enable是布尔类型
if isinstance(enable, str):
if enable.lower() in ['true', '1', 'yes', '开启', '']:
enable = True
elif enable.lower() in ['false', '0', 'no', '关闭', '']:
enable = False
else:
error_msg = f"无效的enable参数: {enable}应该是True或False"
logger.error(f"{self.log_prefix} {error_msg}")
return False, error_msg
# 发送表达情绪的消息
action_text = "开启" if enable else "关闭"
await self.send_message_by_expressor(f"我要{action_text}全体禁言")
try:
# 发送群聊全体禁言命令,按照新格式
await self.send_message(
type="command",
data={
"name": "GROUP_WHOLE_BAN",
"args": {
"enable": enable
}
}
)
logger.info(f"{self.log_prefix} 成功{action_text}全体禁言")
return True, f"成功{action_text}全体禁言"
except Exception as e:
logger.error(f"{self.log_prefix} 执行全体禁言动作时出错: {e}")
await self.send_message_by_expressor(f"执行全体禁言动作时出错: {e}")
return False, f"执行全体禁言动作时出错: {e}"

View File

@@ -7,15 +7,16 @@ logger = get_logger("mute_action")
@register_action
class MuteAction(PluginAction):
"""测试动作处理类"""
"""群聊禁言动作处理类"""
action_name = "mute_action"
action_description = (
"如果某人违反了公序良俗,或者别人戳你太多,或者某人刷屏,一定要禁言某人,如果你很生气,可以禁言某人"
"如果某人违反了公序良俗,或者别人戳你太多,或者某人刷屏,一定要禁言某人,如果你很生气,可以禁言某人,可以自选禁言时长,视严重程度而定"
)
action_parameters = {
"target": "禁言对象,输入你要禁言的对象的名字,必填",
"duration": "禁言时长,输入你要禁言的时长,单位为秒,必填",
"target": "禁言对象,输入你要禁言的对象的名字,必填",
"duration": "禁言时长,输入你要禁言的时长,单位为秒,必填,必须为数字",
"reason": "禁言理由,可选",
}
action_require = [
"当有人违反了公序良俗时使用",
@@ -25,32 +26,55 @@ class MuteAction(PluginAction):
"当千石可乐或可乐酱要求你禁言时使用",
"当你想回避某个话题时使用",
]
default = True # 不是默认动作,需要手动添加到使用集
associated_types = ["command", "text"]
default = True # 默认动作,是否手动添加到使用集
# associated_types = ["command", "text"]
associated_types = ["text"]
async def process(self) -> Tuple[bool, str]:
"""处理测试动作"""
logger.info(f"{self.log_prefix} 执行online动作: {self.reasoning}")
"""处理群聊禁言动作"""
logger.info(f"{self.log_prefix} 执行禁言动作: {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)
reason = self.action_data.get("reason", "违反群规")
if not target or not duration:
error_msg = "禁言参数不完整需要target和duration"
logger.error(f"{self.log_prefix} {error_msg}")
return False, error_msg
await self.send_message_by_expressor(f"我要禁言{target}{platform},时长{duration}秒,理由{reason},表达情绪")
# 获取用户ID
platform, user_id = await self.get_user_id_by_person_name(target)
if not user_id:
error_msg = f"未找到用户 {target} 的ID"
logger.error(f"{self.log_prefix} {error_msg}")
return False, error_msg
# 发送表达情绪的消息
await self.send_message_by_expressor(f"我要禁言{target},时长{duration}秒,理由:{reason}")
try:
# 确保duration是字符串类型
duration_str = str(duration)
# 发送群聊禁言命令,按照新格式
await self.send_message(
type="command",
data={"name": "GROUP_BAN", "args": {"qq_id": f"{user_id}", "duration": f"{duration}"}},
# target = target
data={
"name": "GROUP_BAN",
"args": {
"qq_id": str(user_id),
"duration": duration_str
}
}
)
logger.info(f"{self.log_prefix} 成功禁言用户 {target}({user_id}),时长 {duration}")
return True, f"成功禁言 {target},时长 {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, "测试动作执行成功"
logger.error(f"{self.log_prefix} 执行禁言动作时出错: {e}")
await self.send_message_by_expressor(f"执行禁言动作时出错: {e}")
return False, f"执行禁言动作时出错: {e}"

View File

@@ -1,44 +0,0 @@
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 = False # 不是默认动作,需要手动添加到使用集
associated_types = ["text"]
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("text", "#online detail")
elif mode == "version":
await self.send_message("text", "#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, "测试动作执行成功"