修改为OpenAI规范

去除了单次对话
配置文件格式修改
待测试
This commit is contained in:
2024-12-07 15:08:56 +08:00
parent d8932aba5c
commit dba16e99c2
28 changed files with 827 additions and 1269 deletions

View File

@@ -6,16 +6,15 @@ import net.mamoe.mirai.event.GlobalEventChannel;
import net.mamoe.mirai.event.events.FriendMessageEvent;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.event.events.MessageEvent;
import plugin.constant.ChatConstant;
import plugin.constant.Constant;
import plugin.chat.constant.Constant;
import plugin.config.Config;
import plugin.config.CustomCommandTemplate;
import plugin.listener.FriendMessageListener;
import plugin.listener.GroupMessageListener;
import plugin.listener.OwnerMessageListener;
import plugin.pojo.Config;
import plugin.utils.ConfigUtil;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
@@ -36,28 +35,30 @@ public final class App extends JavaPlugin {
@Override
public void onEnable() {
String owner, bot;
HashMap<String, String> customCommands;
ArrayList<CustomCommandTemplate> customCommands;
List<Long> blacklist;
//加载配置
try {
ConfigUtil.load();
Thread.sleep(1500);
Config config = ConfigUtil.getConfig();
Config config = Config.ConfigLoader.load();
App.class.getClassLoader().loadClass("plugin.utils.OCRUtil");
App.class.getClassLoader().loadClass("plugin.utils.ChatUtil");
owner = config.getOwner().substring(1);
bot = config.getBot().substring(1);
customCommands = config.getCustomCommands();
customCommands = config.getCustomCommandTemplates();
blacklist = config.getBlacklist();
} catch (IOException | ClassNotFoundException | InterruptedException e) {
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
getLogger().info("ChatAI-InGroup loaded!");
getLogger().info("ChatAI loaded!");
//群聊监听器
GlobalEventChannel.INSTANCE.filterIsInstance(GroupMessageEvent.class)
.filter(event -> {
String msg = event.getMessage().contentToString();
long groupId = event.getGroup().getId();
return ((msg.startsWith(Constant.Order.PREFIX_ONECE) && msg.length() != 1) || msg.startsWith(Constant.Order.PREFIX_DEFAULT + bot) || customCommands.containsKey(msg.split(Constant.Order.SPLIT_BLANK)[0] + Constant.Order.SPLIT_BLANK)) && !blacklist.contains(groupId);
String prefix = msg.split(Constant.Order.SPLIT_BLANK)[0];
return (msg.startsWith(Constant.Order.PREFIX_DEFAULT + bot) || checkCommandExist(prefix,customCommands)) && !blacklist.contains(groupId);
}).registerListenerHost(new GroupMessageListener());
//私聊监听器
@@ -65,7 +66,10 @@ public final class App extends JavaPlugin {
.filter(event -> {
String msg = event.getMessage().contentToString();
String sender = String.valueOf(event.getFriend().getId());
return !(msg.startsWith(Constant.Order.PREFIX_SET) && sender.equals(owner)) && !msg.equals(Constant.Order.MSG_HELP);
String prefix = msg.split(Constant.Order.SPLIT_BLANK)[0];
// return !(msg.startsWith(Constant.Order.PREFIX_SET) && sender.equals(owner)) && !msg.equals(Constant.Order.MSG_HELP);
return checkCommandExist(prefix,customCommands) //包含指令前缀
|| !((msg.startsWith(Constant.Order.PREFIX_SET) && sender.equals(owner)) || msg.startsWith(Constant.Order.PREFIX_CUSTOM)); //如果不包含指令前缀,则不能以设置指令、"/"开头
}).registerListenerHost(new FriendMessageListener());
//所有者监听
@@ -97,25 +101,41 @@ public final class App extends JavaPlugin {
$ clearAll (仅限群聊)
$ shutUp (仅限群聊)
$ speak (仅限群聊)
$ 添加预设|<预设指令>|<模型名称/null>|<预设内容>
$ 切换模型|<预设指令>|<模型名称>
$ 添加预设|<预设指令>|<模型模板ID>|<模型名称>|<预设内容>
$ 切换模型|<预设指令>|<模型模板ID>|<模型名称>
$ 更改预设|<预设指令>|<预设内容>
$ 删除预设|<预设指令>
例:
$ 添加预设|/c|glm-4-flash|你是一只猫娘...
$ 添加预设|/c|<模型模板ID>|glm-4-flash|你是一只猫娘...
"""};
helpMsg[0] += "————<预设列表>————";
customCommands.forEach((s, s2) -> helpMsg[0] += "\r\n\r\n" + s + "-> \r\n" + s2);
for (CustomCommandTemplate customCommand : customCommands) {
helpMsg[0] += "\r\n\r\n"+customCommand.toString();
}
helpMsg[0] += "\r\n";
helpMsg[0] += "————<模型列表>————";
for (int i = 0; i < Config.ConfigLoader.getConfig().getModelConfigTemplates().size(); i++) {
helpMsg[0] += "\r\n\r\n"+"TemplateIndex: "+i+"\r\n"+Config.ConfigLoader.getConfig().getModelConfigTemplates().get(i).toString();
}
event.getSubject().sendMessage(helpMsg[0]);
}
});
}
private boolean checkCommandExist(String prefix, ArrayList<CustomCommandTemplate> customCommands) {
for (CustomCommandTemplate customCommand : customCommands) {
if (customCommand.getCommand().equals(prefix)) {
return true;
}
}
return false;
}
@Override
public void onDisable() {
getLogger().info("ChatAI-InGroup disabled!");
}
}
}