修复了clear指令不能正确清除相关记录的bug
修复了截取消息时出现的错误
This commit is contained in:
@@ -25,8 +25,8 @@ public final class App extends JavaPlugin {
|
||||
public static final App INSTANCE = new App();
|
||||
|
||||
private App() {
|
||||
super(new JvmPluginDescriptionBuilder("com.plugin.chatAI-InGroup-v2", "0.1.0")
|
||||
.name("ChatAI-InGroup-v2")
|
||||
super(new JvmPluginDescriptionBuilder("com.plugin.chatAI-InGroup", "0.1.0")
|
||||
.name("ChatAI-InGroup")
|
||||
.author("SLHAF")
|
||||
.build());
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public final class App extends JavaPlugin {
|
||||
} catch (IOException | ClassNotFoundException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
getLogger().info("ChatAI-InGroup-v2 loaded!");
|
||||
getLogger().info("ChatAI-InGroup loaded!");
|
||||
|
||||
//群聊监听器
|
||||
GlobalEventChannel.INSTANCE.filterIsInstance(GroupMessageEvent.class)
|
||||
@@ -115,6 +115,6 @@ public final class App extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("ChatAI-InGroup-v2 disabled!");
|
||||
getLogger().info("ChatAI-InGroup disabled!");
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class FriendMessageListener extends SimpleListenerHost {
|
||||
String[] split = content.split(ChatConstant.BLANK);
|
||||
chatCommand = split[0] + ChatConstant.BLANK;
|
||||
method = MethodsConstant.CUSTOM;
|
||||
content = split[1];
|
||||
content = content.substring((content.split(ChatConstant.BLANK)[0]+ChatConstant.BLANK).length());
|
||||
} else if (content.startsWith(ChatConstant.ONCE_MESSAGE_START)) {
|
||||
content = content.substring(1);
|
||||
method = MethodsConstant.ONCE;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class GroupMessageListener extends SimpleListenerHost {
|
||||
String[] split = content.split(ChatConstant.BLANK);
|
||||
chatCommand = split[0] + ChatConstant.BLANK;
|
||||
method = MethodsConstant.CUSTOM;
|
||||
content = split[1];
|
||||
content = content.substring(chatCommand.length());
|
||||
}
|
||||
//消息内容处理
|
||||
if (content.isBlank()) {
|
||||
|
||||
@@ -107,11 +107,14 @@ public class AIUtil {
|
||||
if (!userCustomMessages.containsKey(id)) {
|
||||
return "不存在消息记录";
|
||||
}
|
||||
for (UserCustomMessage userCustomMessage : userCustomMessages.get(id)) {
|
||||
if (userCustomMessage.getCommand().equals(chatCommand)) {
|
||||
userCustomMessage.getMessages().clear();
|
||||
ArrayList<Integer> indexToRemove = new ArrayList<>();
|
||||
List<UserCustomMessage> userCustomMessageList = userCustomMessages.get(id);
|
||||
for (int i = 0; i < userCustomMessageList.size(); i++) {
|
||||
if (userCustomMessageList.get(i).getCommand().equals(chatCommand)) {
|
||||
indexToRemove.add(i);
|
||||
}
|
||||
}
|
||||
indexToRemove.forEach(i -> userCustomMessageList.remove(i.intValue()));
|
||||
return "消息记录已清空";
|
||||
} else if (AIConstant.CURRENT_MODEL.equals(content.replace(ChatConstant.BLANK, ""))) {
|
||||
String modelName = customCommands.get(chatCommand).split(ConfigConstant.CUSTOM_SPLIT)[0];
|
||||
@@ -173,8 +176,8 @@ public class AIUtil {
|
||||
if (!userDefaultMessages.containsKey(id)) {
|
||||
//创建消息list
|
||||
List<ChatMessage> chatMessages = new ArrayList<>();
|
||||
if (customCommands.containsKey(ConfigConstant.DEFAULT) && !ConfigConstant.NULL.equals(customCommands.get(ConfigConstant.DEFAULT))) {
|
||||
ChatMessage customMessage = new ChatMessage(ChatMessageRole.SYSTEM.value(), customCommands.get(ConfigConstant.DEFAULT));
|
||||
if (customCommands.containsKey(ConfigConstant.DEFAULT+ChatConstant.BLANK) && !ConfigConstant.NULL.equals(customCommands.get(ConfigConstant.DEFAULT+ChatConstant.BLANK))) {
|
||||
ChatMessage customMessage = new ChatMessage(ChatMessageRole.SYSTEM.value(), customCommands.get(ConfigConstant.DEFAULT+ChatConstant.BLANK));
|
||||
chatMessages.add(customMessage);
|
||||
}
|
||||
userDefaultMessages.put(id, chatMessages);
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.mamoe.mirai.utils.MiraiLogger;
|
||||
import org.slf4j.Logger;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import plugin.constant.AIConstant;
|
||||
import plugin.constant.ChatConstant;
|
||||
import plugin.constant.ConfigConstant;
|
||||
import plugin.pojo.Config;
|
||||
@@ -98,7 +97,7 @@ public class ConfigUtil {
|
||||
if (!customCommands.containsKey(instruction)) {
|
||||
return "该预设不存在!";
|
||||
}
|
||||
if (ConfigConstant.DEFAULT.equals(instruction)){
|
||||
if ((ConfigConstant.DEFAULT+ChatConstant.BLANK).equals(instruction)){
|
||||
config.setDefaultModel(customModel);
|
||||
dump();
|
||||
return "模型切换成功: [defaultModel -> "+config.getDefaultModel()+"]";
|
||||
@@ -171,7 +170,7 @@ public class ConfigUtil {
|
||||
if (!customCommands.containsKey(instruction)) {
|
||||
return "该指令不存在!";
|
||||
}
|
||||
if (ConfigConstant.DEFAULT.equals(instruction)) {
|
||||
if ((ConfigConstant.DEFAULT+ChatConstant.BLANK).equals(instruction)) {
|
||||
customCommands.put(instruction, customContent);
|
||||
}else {
|
||||
String modelName = customCommands.get(instruction).split(ConfigConstant.CUSTOM_SPLIT)[0];
|
||||
|
||||
@@ -23,6 +23,7 @@ import plugin.utils.ConfigUtil;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static kotlin.io.ConsoleKt.readln;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class MyTest {
|
||||
HttpPost httpPost = new HttpPost("https://open.bigmodel.cn/api/paas/v4/assistant");
|
||||
httpPost.setHeaders(new Header[]{
|
||||
new BasicHeader("content-type", "application/json"),
|
||||
new BasicHeader("authorization", "")
|
||||
new BasicHeader("authorization", "f638f59b6b5961bbcd685c85caa0e7e7.Uz5nTEQS2X8LXcxF")
|
||||
});
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -181,10 +182,10 @@ public class MyTest {
|
||||
|
||||
@Test
|
||||
public void terminalTest() throws InterruptedException {
|
||||
MiraiConsoleTerminalLoader.INSTANCE.startAsDaemon(new MiraiConsoleImplementationTerminal());
|
||||
MiraiConsoleImplementationTerminal terminal = new MiraiConsoleImplementationTerminal();
|
||||
MiraiConsoleTerminalLoader.INSTANCE.startAsDaemon(terminal);
|
||||
PluginManager.INSTANCE.loadPlugin(App.INSTANCE);
|
||||
PluginManager.INSTANCE.enablePlugin(App.INSTANCE);
|
||||
while (true);
|
||||
new Scanner(System.in).nextLine();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user