diff --git a/build.gradle.kts b/build.gradle.kts index d88da82..5a9dc0b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ dependencies{ implementation ("junit:junit:4.13.2") implementation ("org.apache.logging.log4j:log4j-core:2.23.1") implementation ("org.apache.logging.log4j:log4j-api:2.23.1") - implementation("top.mrxiaom.mirai:overflow-core-api:1.0.0.519-0d68f08-SNAPSHOT") + implementation("top.mrxiaom.mirai:overflow-core-all:1.0.0") implementation ("com.alibaba:fastjson:1.2.73") implementation ("org.projectlombok:lombok:1.18.36") diff --git a/src/main/java/plugin/App.java b/src/main/java/plugin/App.java index 1a9ab4b..33d642f 100644 --- a/src/main/java/plugin/App.java +++ b/src/main/java/plugin/App.java @@ -9,6 +9,7 @@ import net.mamoe.mirai.event.events.MessageEvent; import plugin.chat.constant.Constant; import plugin.config.Config; import plugin.config.CustomCommandTemplate; +import plugin.config.ModelConfigTemplate; import plugin.listener.FriendMessageListener; import plugin.listener.GroupMessageListener; import plugin.listener.OwnerMessageListener; @@ -117,7 +118,10 @@ public final class App extends JavaPlugin { 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(); + ModelConfigTemplate modelConfigTemplate = Config.ConfigLoader.getConfig().getModelConfigTemplates().get(i); + helpMsg[0] += "\r\n\r\n"+"TemplateIndex: "+i+"\r\n" + + "name: "+modelConfigTemplate.getTemplate_name() + + "base_url: "+modelConfigTemplate.getBase_url()+"\r\n"; } event.getSubject().sendMessage(helpMsg[0]); } diff --git a/src/main/java/plugin/chat/ChatClient.java b/src/main/java/plugin/chat/ChatClient.java index 9ed5350..b956dc9 100644 --- a/src/main/java/plugin/chat/ChatClient.java +++ b/src/main/java/plugin/chat/ChatClient.java @@ -55,11 +55,13 @@ public class ChatClient { } public void setPromotion(String promotion){ - Message message = Message.builder() - .role(Constant.Character.SYSTEM) - .content(promotion) - .build(); - messages.add(0,message); + if (!promotion.equals("null")) { + Message message = Message.builder() + .role(Constant.Character.SYSTEM) + .content(promotion) + .build(); + messages.add(0, message); + } } public ChatResponse runChat(String content){ diff --git a/src/main/java/plugin/chat/constant/Constant.java b/src/main/java/plugin/chat/constant/Constant.java index 95625aa..3bb2de6 100644 --- a/src/main/java/plugin/chat/constant/Constant.java +++ b/src/main/java/plugin/chat/constant/Constant.java @@ -23,7 +23,7 @@ public class Constant { public static final String MATCH_IMAGE = "\\[mirai:image:(.*?)]"; public static final String MATCH_MESSAGE = ".*[mirai:image:(https?://[\\w./?&=]+)].*"; public static final String CUSTOM_SPLIT = "\\|"; - public static final String ADD_CUSTOM = "/[a-zA-Z]+\\|.*\\|.*"; + public static final String ADD_CUSTOM = "/[a-zA-Z]+\\|[0-9]+\\|.*\\|.*"; public static final String MODEL_CHANGE = ".*\\|.*"; } diff --git a/src/main/java/plugin/config/Config.java b/src/main/java/plugin/config/Config.java index 3c569f1..1552675 100644 --- a/src/main/java/plugin/config/Config.java +++ b/src/main/java/plugin/config/Config.java @@ -5,7 +5,9 @@ import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.inspector.TagInspector; import plugin.chat.constant.Constant; import java.io.File; @@ -76,10 +78,10 @@ public class Config { } public static Config load() throws IOException { - Config config; - DumperOptions dumperOptions = new DumperOptions(); - dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - Yaml yaml = new Yaml(dumperOptions); + LoaderOptions loaderOptions = new LoaderOptions(); + TagInspector tagInspector = tag -> true; + loaderOptions.setTagInspector(tagInspector); + Yaml yaml = new Yaml(loaderOptions); File file = new File(Constant.Path.CONFIG_PATH); if (file.exists()) { FileInputStream fileInputStream = new FileInputStream(Constant.Path.CONFIG_PATH); diff --git a/src/main/java/plugin/config/CustomCommandTemplate.java b/src/main/java/plugin/config/CustomCommandTemplate.java index 292b7e1..3d388ba 100644 --- a/src/main/java/plugin/config/CustomCommandTemplate.java +++ b/src/main/java/plugin/config/CustomCommandTemplate.java @@ -20,6 +20,6 @@ public class CustomCommandTemplate { return "command: " + command + "\r\n" + "modelTemplateIndex: " + modelTemplateIndex + "\r\n" + "customModel: " + customModel + "\r\n" + - "customPromotion: " + customPromotion + "\r\n"; + "customPromotion: " + customPromotion; } } diff --git a/src/main/java/plugin/listener/FriendMessageListener.java b/src/main/java/plugin/listener/FriendMessageListener.java index 9065933..9a08b1e 100644 --- a/src/main/java/plugin/listener/FriendMessageListener.java +++ b/src/main/java/plugin/listener/FriendMessageListener.java @@ -36,7 +36,8 @@ public class FriendMessageListener extends SimpleListenerHost { } } if (OCRUtil.isSupported && url != null) { - content = content + "```content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```"; + content = content.replace("[图片]","```recognized_image_content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```"); +// content = content + "```image content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```"; } //处理消息头 diff --git a/src/main/java/plugin/listener/GroupMessageListener.java b/src/main/java/plugin/listener/GroupMessageListener.java index 6b300f0..b999922 100644 --- a/src/main/java/plugin/listener/GroupMessageListener.java +++ b/src/main/java/plugin/listener/GroupMessageListener.java @@ -44,7 +44,7 @@ public class GroupMessageListener extends SimpleListenerHost { } } if (OCRUtil.isSupported && url != null) { - content = content + "```content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```"; + content = content.replace("[图片]","```recognized_image_content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```"); } //消息头处理 diff --git a/src/main/java/plugin/listener/OwnerMessageListener.java b/src/main/java/plugin/listener/OwnerMessageListener.java index 0939226..b9b0814 100644 --- a/src/main/java/plugin/listener/OwnerMessageListener.java +++ b/src/main/java/plugin/listener/OwnerMessageListener.java @@ -46,7 +46,7 @@ public class OwnerMessageListener extends SimpleListenerHost { } String instruction = primaryContent.split(Constant.Order.SPLIT_CUSTOM)[0]; - String arguments = primaryContent.substring(primaryContent.indexOf(Constant.Order.SPLIT_GUN) + 1); + String arguments = primaryContent.substring(instruction.length() + 1); long id = event.getSender().getId(); String response; try { @@ -64,7 +64,7 @@ public class OwnerMessageListener extends SimpleListenerHost { String arguments; try { instruction = primaryContent.split(Constant.Order.SPLIT_CUSTOM)[0]; - arguments = primaryContent.substring(primaryContent.indexOf(Constant.Order.SPLIT_CUSTOM) + 1); + arguments = primaryContent.substring(instruction.length()+1); } catch (ArrayIndexOutOfBoundsException e) { event.getFriend().sendMessage("操作失败,缺少参数"); return; diff --git a/src/main/java/plugin/utils/ChatUtil.java b/src/main/java/plugin/utils/ChatUtil.java index 57a6009..b99118c 100644 --- a/src/main/java/plugin/utils/ChatUtil.java +++ b/src/main/java/plugin/utils/ChatUtil.java @@ -27,8 +27,8 @@ public class ChatUtil { private static void launchCleanerThread() { Config config = Config.ConfigLoader.getConfig(); - long timeout = Long.parseLong(config.getTimeout()); - long timeCheck = Long.parseLong(config.getTimeCheck()); + long timeout = Long.parseLong(config.getTimeout().substring(1)); + long timeCheck = Long.parseLong(config.getTimeCheck().substring(1)); Thread thread = new Thread(() -> { long currentTime = System.currentTimeMillis(); while (true) { @@ -77,6 +77,7 @@ public class ChatUtil { ChatClient chatClient = new ChatClient(chatId, url, apikey, customModel); chatClient.setPromotion(customPromotion); chatClients.put(chatId, chatClient); + log.info("final content: {}",content); chatResponse = chatClient.runChat(content); } } diff --git a/src/test/java/MyTest.java b/src/test/java/MyTest.java index 0926fa1..06da20e 100644 --- a/src/test/java/MyTest.java +++ b/src/test/java/MyTest.java @@ -126,6 +126,12 @@ public class MyTest { MiraiConsoleTerminalLoader.INSTANCE.startAsDaemon(terminal); PluginManager.INSTANCE.loadPlugin(App.INSTANCE); PluginManager.INSTANCE.enablePlugin(App.INSTANCE); - new Scanner(System.in).nextLine(); + Scanner scanner = new Scanner(System.in); + String input = scanner.nextLine(); + while (true) { + if (input.equals("exit")) { + return; + } + } } }