调整自动回复逻辑
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
enable = true
|
||||
command = ["ai介入", "ai对话", "ai自动回复"]
|
||||
command-format = """
|
||||
🤖AI自动对话指令:
|
||||
ai介入 开启/关闭
|
||||
"""
|
||||
|
||||
dify_api_url = "http://192.168.2.240/v1/chat-messages"
|
||||
dify_api_key = "app-oDHbln5CzBLt3uS9bIBlJjhZ" # 请在此处填入您的DIFY API密钥
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
||||
self.intervention_bot = None
|
||||
self.group_messages = {} # 存储每个群的最近消息
|
||||
self.max_messages = 20 # 每个群最多存储的消息数量
|
||||
self.auto_response_enabled = {} # 存储每个群是否启用自动回复
|
||||
|
||||
# DIFY API配置
|
||||
self.dify_api_url = "http://192.168.2.240/v1/chat-messages"
|
||||
@@ -62,8 +61,6 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
||||
|
||||
# 加载配置
|
||||
config_path = os.path.join(os.path.dirname(__file__), "config.toml")
|
||||
self._commands = self._config.get("AIAutoResponse", {}).get("command", ["ai介入", "ai对话", "ai自动回复"])
|
||||
self.command_format = self._config.get("AIAutoResponse", {}).get("command-format", "ai介入 开启/关闭")
|
||||
self.enable = self._config.get("AIAutoResponse", {}).get("enable", True)
|
||||
|
||||
# 从配置中获取DIFY API密钥
|
||||
@@ -95,15 +92,12 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
||||
return False
|
||||
|
||||
content = str(message.get("content", "")).strip()
|
||||
command = content.split(" ")[0]
|
||||
roomid = message.get("roomid", "")
|
||||
|
||||
# 如果是命令,直接处理
|
||||
if command in self._commands:
|
||||
return True
|
||||
|
||||
if GroupBotManager.get_group_permission(roomid, Feature.AI_AUTO) == PermissionStatus.DISABLED:
|
||||
return False
|
||||
# 如果是群消息,且该群启用了自动回复,则处理
|
||||
if roomid and self.auto_response_enabled.get(roomid, False):
|
||||
if roomid:
|
||||
# 存储消息
|
||||
if roomid not in self.group_messages:
|
||||
self.group_messages[roomid] = []
|
||||
@@ -131,37 +125,12 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
self.LOG.debug(f"插件执行: {self.name}:{content}")
|
||||
command = content.split(" ")[0]
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
bot: WechatAPIClient = message.get("bot")
|
||||
# 检查权限
|
||||
if roomid and gbm.get_group_permission(roomid, Feature.AI_AUTO) == PermissionStatus.DISABLED:
|
||||
if roomid and GroupBotManager.get_group_permission(roomid, Feature.AI_AUTO) == PermissionStatus.DISABLED:
|
||||
return False, "没有权限"
|
||||
# 处理命令
|
||||
if command in self._commands:
|
||||
# 检查命令格式
|
||||
if len(content.split(" ")) == 1:
|
||||
await bot.send_text_message((roomid if roomid else sender), f"❌命令格式错误!\n{self.command_format}",
|
||||
sender)
|
||||
return False, "命令格式错误"
|
||||
|
||||
# 提取参数
|
||||
param = content[len(command):].strip()
|
||||
|
||||
if param == "开启":
|
||||
self.auto_response_enabled[roomid] = True
|
||||
await bot.send_text_message(roomid, "✅AI自动对话已开启", sender)
|
||||
return True, "开启成功"
|
||||
elif param == "关闭":
|
||||
self.auto_response_enabled[roomid] = False
|
||||
await bot.send_text_message(roomid, "❌AI自动对话已关闭", sender)
|
||||
return True, "关闭成功"
|
||||
else:
|
||||
await bot.send_text_message(roomid, f"❌参数错误!\n{self.command_format}", sender)
|
||||
return False, "参数错误"
|
||||
|
||||
# 处理自动回复
|
||||
try:
|
||||
# 获取最近的消息
|
||||
|
||||
Reference in New Issue
Block a user