修复了clear指令不能正确清除相关记录的bug
修复了截取消息时出现的错误
This commit is contained in:
@@ -18,7 +18,7 @@ dependencies{
|
|||||||
implementation ("junit:junit:4.13.2")
|
implementation ("junit:junit:4.13.2")
|
||||||
implementation ("org.apache.logging.log4j:log4j-core:2.23.1")
|
implementation ("org.apache.logging.log4j:log4j-core:2.23.1")
|
||||||
implementation ("org.apache.logging.log4j:log4j-api:2.23.1")
|
implementation ("org.apache.logging.log4j:log4j-api:2.23.1")
|
||||||
implementation("top.mrxiaom.mirai:overflow-core:0.9.9.515-f8d867b-SNAPSHOT")
|
implementation("top.mrxiaom.mirai:overflow-core-api:1.0.0.519-0d68f08-SNAPSHOT")
|
||||||
implementation ("com.alibaba:fastjson:1.2.73")
|
implementation ("com.alibaba:fastjson:1.2.73")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.mamoe.mirai.event.events.FriendMessageEvent;
|
|||||||
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
||||||
import net.mamoe.mirai.event.events.MessageEvent;
|
import net.mamoe.mirai.event.events.MessageEvent;
|
||||||
import plugin.constant.ChatConstant;
|
import plugin.constant.ChatConstant;
|
||||||
|
import plugin.constant.Constant;
|
||||||
import plugin.listener.FriendMessageListener;
|
import plugin.listener.FriendMessageListener;
|
||||||
import plugin.listener.GroupMessageListener;
|
import plugin.listener.GroupMessageListener;
|
||||||
import plugin.listener.OwnerMessageListener;
|
import plugin.listener.OwnerMessageListener;
|
||||||
@@ -56,7 +57,7 @@ public final class App extends JavaPlugin {
|
|||||||
.filter(event -> {
|
.filter(event -> {
|
||||||
String msg = event.getMessage().contentToString();
|
String msg = event.getMessage().contentToString();
|
||||||
long groupId = event.getGroup().getId();
|
long groupId = event.getGroup().getId();
|
||||||
return ((msg.startsWith(".") && msg.length() != 1) || msg.startsWith("@" + bot) || customCommands.containsKey(msg.split(" ")[0] + ChatConstant.BLANK)) && !blacklist.contains(groupId);
|
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);
|
||||||
}).registerListenerHost(new GroupMessageListener());
|
}).registerListenerHost(new GroupMessageListener());
|
||||||
|
|
||||||
//私聊监听器
|
//私聊监听器
|
||||||
@@ -64,7 +65,7 @@ public final class App extends JavaPlugin {
|
|||||||
.filter(event -> {
|
.filter(event -> {
|
||||||
String msg = event.getMessage().contentToString();
|
String msg = event.getMessage().contentToString();
|
||||||
String sender = String.valueOf(event.getFriend().getId());
|
String sender = String.valueOf(event.getFriend().getId());
|
||||||
return !(msg.startsWith(ChatConstant.SET) && sender.equals(owner)) && !msg.equals(ChatConstant.HELP);
|
return !(msg.startsWith(Constant.Order.PREFIX_SET) && sender.equals(owner)) && !msg.equals(Constant.Order.MSG_HELP);
|
||||||
}).registerListenerHost(new FriendMessageListener());
|
}).registerListenerHost(new FriendMessageListener());
|
||||||
|
|
||||||
//所有者监听
|
//所有者监听
|
||||||
@@ -72,13 +73,13 @@ public final class App extends JavaPlugin {
|
|||||||
.filter(event -> {
|
.filter(event -> {
|
||||||
String msg = event.getMessage().contentToString();
|
String msg = event.getMessage().contentToString();
|
||||||
String sender = String.valueOf(event.getSender().getId());
|
String sender = String.valueOf(event.getSender().getId());
|
||||||
return msg.startsWith(ChatConstant.SET) && sender.equals(owner);
|
return msg.startsWith(Constant.Order.PREFIX_SET) && sender.equals(owner);
|
||||||
}).registerListenerHost(new OwnerMessageListener());
|
}).registerListenerHost(new OwnerMessageListener());
|
||||||
|
|
||||||
//帮助监听
|
//帮助监听
|
||||||
GlobalEventChannel.INSTANCE
|
GlobalEventChannel.INSTANCE
|
||||||
.filterIsInstance(MessageEvent.class)
|
.filterIsInstance(MessageEvent.class)
|
||||||
.filter(event -> event.getMessage().contentToString().equals(ChatConstant.HELP))
|
.filter(event -> event.getMessage().contentToString().equals(Constant.Order.MSG_HELP))
|
||||||
.subscribeAlways(MessageEvent.class, event -> {
|
.subscribeAlways(MessageEvent.class, event -> {
|
||||||
synchronized (customCommands) {
|
synchronized (customCommands) {
|
||||||
final String[] helpMsg = {"""
|
final String[] helpMsg = {"""
|
||||||
|
|||||||
50
src/main/java/plugin/constant/Constant.java
Normal file
50
src/main/java/plugin/constant/Constant.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package plugin.constant;
|
||||||
|
|
||||||
|
public class Constant {
|
||||||
|
public static class Character{
|
||||||
|
public static final String USER = "user";
|
||||||
|
public static final String SYSTEM = "system";
|
||||||
|
public static final String ASSISTANT = "assistant";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Model{
|
||||||
|
public static final String DEEPSEEK_CHAT = "deepseek-chat";
|
||||||
|
public static final String GLM_4_FLASH = "glm-4-flash";
|
||||||
|
public static final String GLM_4_0520 = "glm-4-0520";
|
||||||
|
public static final String GLM_4_PLUS = "glm-4-Plus";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Status{
|
||||||
|
public static final String SUCCESS = "success";
|
||||||
|
public static final String ERROR = "error";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Regex{
|
||||||
|
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 MODEL_CHANGE = ".*\\|.*";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Order{
|
||||||
|
public static final String PREFIX_ONECE = ".";
|
||||||
|
public static final String PREFIX_DEFAULT = "@";
|
||||||
|
public static final String PREFIX_SET = "$";
|
||||||
|
|
||||||
|
public static final String SPLIT_BLANK = " ";
|
||||||
|
public static final String SPLIT_GUN = "|";
|
||||||
|
public static final String SPLIT_CUSTOM = "\\|";
|
||||||
|
|
||||||
|
public static final String MSG_CLEAR = "clear";
|
||||||
|
public static final String MSG_CURRENT_MODLE = "当前模型";
|
||||||
|
public static final String MSG_HELP = "/chatHelp";
|
||||||
|
|
||||||
|
public static final String DEFAULT = "default";
|
||||||
|
public static final String NULL = "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class StatusCode {
|
||||||
|
public static final int OK = "200";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import net.mamoe.mirai.event.events.GroupMessageEvent;
|
|||||||
import net.mamoe.mirai.message.data.At;
|
import net.mamoe.mirai.message.data.At;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import plugin.constant.ChatConstant;
|
import plugin.constant.ChatConstant;
|
||||||
|
import plugin.constant.Constant;
|
||||||
import plugin.constant.MethodsConstant;
|
import plugin.constant.MethodsConstant;
|
||||||
import plugin.pojo.Config;
|
import plugin.pojo.Config;
|
||||||
import plugin.utils.AIUtil;
|
import plugin.utils.AIUtil;
|
||||||
@@ -41,9 +42,8 @@ public class GroupMessageListener extends SimpleListenerHost {
|
|||||||
String miraiCode = event.getMessage().serializeToMiraiCode();
|
String miraiCode = event.getMessage().serializeToMiraiCode();
|
||||||
String url = null;
|
String url = null;
|
||||||
String chatCommand = null;
|
String chatCommand = null;
|
||||||
if (miraiCode.matches(ChatConstant.MATCH_MESSAGE)) {
|
if (miraiCode.matches(Constant.Regex.MATCH_MESSAGE)) {
|
||||||
String regex = ChatConstant.MATCH_IMAGE;
|
Pattern pattern = Pattern.compile(Constant.Regex.MATCH_IMAGE);
|
||||||
Pattern pattern = Pattern.compile(regex);
|
|
||||||
|
|
||||||
// 创建Matcher对象
|
// 创建Matcher对象
|
||||||
Matcher matcher = pattern.matcher(miraiCode);
|
Matcher matcher = pattern.matcher(miraiCode);
|
||||||
@@ -58,18 +58,18 @@ public class GroupMessageListener extends SimpleListenerHost {
|
|||||||
MethodsConstant method = MethodsConstant.NONE;
|
MethodsConstant method = MethodsConstant.NONE;
|
||||||
|
|
||||||
//消息头处理
|
//消息头处理
|
||||||
if (content.startsWith(ChatConstant.ONCE_MESSAGE_START)) {
|
if (content.startsWith(Constant.Order.PREFIX_ONECE)) {
|
||||||
//单次对话
|
//单次对话
|
||||||
content = content.substring(1);
|
content = content.substring(1);
|
||||||
method = MethodsConstant.ONCE;
|
method = MethodsConstant.ONCE;
|
||||||
} else if (content.startsWith(ChatConstant.DEFAULT_MESSAGE_START + event.getBot().getId())) {
|
} else if (content.startsWith(Constant.Order.PREFIX_DEFAULT + event.getBot().getId())) {
|
||||||
//默认对话
|
//默认对话
|
||||||
content = content.substring((ChatConstant.DEFAULT_MESSAGE_START + event.getBot().getId()).length());
|
content = content.substring((Constant.Order.PREFIX_DEFAULT + event.getBot().getId()).length());
|
||||||
method = MethodsConstant.NORMAL;
|
method = MethodsConstant.NORMAL;
|
||||||
} else if (config.getCustomCommands().containsKey(content.split(ChatConstant.BLANK)[0]+ChatConstant.BLANK)) {
|
} else if (config.getCustomCommands().containsKey(content.split(Constant.Order.SPLIT_BLANK)[0]+Constant.Order.SPLIT_BLANK)) {
|
||||||
//预设对话
|
//预设对话
|
||||||
String[] split = content.split(ChatConstant.BLANK);
|
String[] split = content.split(Constant.Order.SPLIT_BLANK);
|
||||||
chatCommand = split[0] + ChatConstant.BLANK;
|
chatCommand = split[0] + Constant.Order.SPLIT_BLANK;
|
||||||
method = MethodsConstant.CUSTOM;
|
method = MethodsConstant.CUSTOM;
|
||||||
content = content.substring(chatCommand.length());
|
content = content.substring(chatCommand.length());
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public class GroupMessageListener extends SimpleListenerHost {
|
|||||||
case CUSTOM -> AIUtil.customChat(Long.valueOf(id), content, url,chatCommand);
|
case CUSTOM -> AIUtil.customChat(Long.valueOf(id), content, url,chatCommand);
|
||||||
case NORMAL -> AIUtil.defaultChat(Long.valueOf(id), content, url);
|
case NORMAL -> AIUtil.defaultChat(Long.valueOf(id), content, url);
|
||||||
case ONCE -> AIUtil.chatOnce(content, url);
|
case ONCE -> AIUtil.chatOnce(content, url);
|
||||||
default -> "ERROR!";
|
default -> Constant.Status.ERROR;
|
||||||
};
|
};
|
||||||
event.getGroup().sendMessage(new At(Long.parseLong(id)).plus("\r\n").plus(response));
|
event.getGroup().sendMessage(new At(Long.parseLong(id)).plus("\r\n").plus(response));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.mamoe.mirai.event.events.MessageEvent;
|
|||||||
import net.mamoe.mirai.message.data.At;
|
import net.mamoe.mirai.message.data.At;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import plugin.constant.ChatConstant;
|
import plugin.constant.ChatConstant;
|
||||||
|
import plugin.constant.Constant;
|
||||||
import plugin.constant.ConfigConstant;
|
import plugin.constant.ConfigConstant;
|
||||||
import plugin.utils.AIUtil;
|
import plugin.utils.AIUtil;
|
||||||
import plugin.utils.ConfigUtil;
|
import plugin.utils.ConfigUtil;
|
||||||
@@ -40,8 +41,8 @@ public class OwnerMessageListener extends SimpleListenerHost {
|
|||||||
|
|
||||||
private void onGroupMessageEvent(GroupMessageEvent event) {
|
private void onGroupMessageEvent(GroupMessageEvent event) {
|
||||||
String msg = event.getMessage().contentToString();
|
String msg = event.getMessage().contentToString();
|
||||||
String primaryContent = msg.split(ChatConstant.BLANK)[1];
|
String primaryContent = msg.split(Constant.Order.SPLIT_BLANK)[1];
|
||||||
if (!primaryContent.contains(ChatConstant.SPLIT)) {
|
if (!primaryContent.contains(Constant.Order.SPLIT_GUN)) {
|
||||||
String response;
|
String response;
|
||||||
response = switch (primaryContent) {
|
response = switch (primaryContent) {
|
||||||
case "clearAll" -> AIUtil.clearAll();
|
case "clearAll" -> AIUtil.clearAll();
|
||||||
@@ -53,8 +54,8 @@ public class OwnerMessageListener extends SimpleListenerHost {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String command = primaryContent.split(ConfigConstant.CUSTOM_SPLIT)[0];
|
String command = primaryContent.split(Constant.Order.SPLIT_CUSTOM)[0];
|
||||||
String arguments = primaryContent.substring(primaryContent.indexOf(ChatConstant.SPLIT) + 1);
|
String arguments = primaryContent.substring(primaryContent.indexOf(Constant.Order.SPLIT_GUN) + 1);
|
||||||
long id = event.getSender().getId();
|
long id = event.getSender().getId();
|
||||||
String response;
|
String response;
|
||||||
try {
|
try {
|
||||||
@@ -67,12 +68,12 @@ public class OwnerMessageListener extends SimpleListenerHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onFriendMessageEvent(FriendMessageEvent event) throws IOException {
|
private void onFriendMessageEvent(FriendMessageEvent event) throws IOException {
|
||||||
String primaryContent = event.getMessage().contentToString().split(ChatConstant.BLANK)[1];
|
String primaryContent = event.getMessage().contentToString().split(Constant.Order.SPLIT_BLANK)[1];
|
||||||
String command;
|
String command;
|
||||||
String arguments;
|
String arguments;
|
||||||
try {
|
try {
|
||||||
command = primaryContent.split(ConfigConstant.CUSTOM_SPLIT)[0];
|
command = primaryContent.split(ConfigConstant.CUSTOM_SPLIT)[0];
|
||||||
arguments = primaryContent.substring(primaryContent.indexOf(ConfigConstant.CUSTOM_SPLIT) + 1);
|
arguments = primaryContent.substring(primaryContent.indexOf(Constant.Order.SPLIT_CUSTOM) + 1);
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
event.getFriend().sendMessage("操作失败,缺少参数");
|
event.getFriend().sendMessage("操作失败,缺少参数");
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user