fix:修复禁言插件
This commit is contained in:
@@ -439,7 +439,11 @@ class DefaultExpressor:
|
||||
if type == "emoji":
|
||||
typing = False
|
||||
|
||||
sent_msg = await self.heart_fc_sender.send_message(bot_message, has_thinking=True, typing=typing)
|
||||
if anchor_message.raw_message:
|
||||
set_reply = True
|
||||
else:
|
||||
set_reply = False
|
||||
sent_msg = await self.heart_fc_sender.send_message(bot_message, has_thinking=True, typing=typing, set_reply=set_reply)
|
||||
|
||||
reply_message_ids.append(part_message_id) # 记录我们生成的ID
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class HeartFCSender:
|
||||
thinking_message = self.thinking_messages.get(chat_id, {}).get(message_id)
|
||||
return thinking_message.thinking_start_time if thinking_message else None
|
||||
|
||||
async def send_message(self, message: MessageSending, has_thinking=False, typing=False):
|
||||
async def send_message(self, message: MessageSending, has_thinking=False, typing=False, set_reply=False):
|
||||
"""
|
||||
处理、发送并存储一条消息。
|
||||
|
||||
@@ -97,7 +97,7 @@ class HeartFCSender:
|
||||
message_id = message.message_info.message_id
|
||||
|
||||
try:
|
||||
if has_thinking:
|
||||
if set_reply:
|
||||
_ = message.update_thinking_time()
|
||||
|
||||
# --- 条件应用 set_reply 逻辑 ---
|
||||
|
||||
@@ -31,12 +31,13 @@ def init_prompt():
|
||||
现在是{time_now},你正在上网,和qq群里的网友们聊天,以下是正在进行的聊天内容:
|
||||
{chat_observe_info}
|
||||
|
||||
现在请你根据现有的信息,思考自我认同
|
||||
1. 你是一个什么样的人,你和群里的人关系如何
|
||||
2. 你的形象是什么
|
||||
3. 思考有没有人提到你,或者图片与你有关
|
||||
4. 你的自我认同是否有助于你的回答,如果你需要自我相关的信息来帮你参与聊天,请输出,否则请输出十几个字的简短自我认同
|
||||
5. 一般情况下不用输出自我认同,只需要输出十几个字的简短自我认同就好,除非有明显需要自我认同的场景
|
||||
现在请你根据现有的信息,思考自我认同:请严格遵守以下规则
|
||||
1. 请严格参考最上方的人设,适当参考记忆和当前聊天内容
|
||||
2. 你是一个什么样的人,你和群里的人关系如何
|
||||
3. 你的形象是什么
|
||||
4. 思考有没有人提到你,或者图片与你有关
|
||||
5. 你的自我认同是否有助于你的回答,如果你需要自我相关的信息来帮你参与聊天,请输出,否则请输出十几个字的简短自我认同
|
||||
6. 一般情况下不用输出自我认同,只需要输出十几个字的简短自我认同就好,除非有明显需要自我认同的场景
|
||||
|
||||
输出内容平淡一些,说中文,不要浮夸,平淡一些。
|
||||
请注意不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。只输出自我认同内容,记得明确说明这是你的自我认同。
|
||||
|
||||
@@ -104,10 +104,14 @@ class PersonInfoManager:
|
||||
|
||||
def get_person_id_by_person_name(self, person_name: str):
|
||||
"""根据用户名获取用户ID"""
|
||||
document = db.person_info.find_one({"person_name": person_name})
|
||||
if document:
|
||||
return document["person_id"]
|
||||
else:
|
||||
try:
|
||||
record = PersonInfo.get_or_none(PersonInfo.person_name == person_name)
|
||||
if record:
|
||||
return record.person_id
|
||||
else:
|
||||
return ""
|
||||
except Exception as e:
|
||||
logger.error(f"根据用户名 {person_name} 获取用户ID时出错 (Peewee): {e}")
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
# 导入所有动作模块以确保装饰器被执行
|
||||
from . import test_action # noqa
|
||||
|
||||
from . import online_action # noqa
|
||||
# from . import online_action # noqa
|
||||
from . import mute_action # noqa
|
||||
|
||||
73
src/plugins/test_plugin/actions/group_whole_ban_action.py
Normal file
73
src/plugins/test_plugin/actions/group_whole_ban_action.py
Normal 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}"
|
||||
@@ -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}"
|
||||
|
||||
@@ -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, "测试动作执行成功"
|
||||
Reference in New Issue
Block a user