添加了帮助指令(感觉没必要提交这个)
This commit is contained in:
@@ -5,6 +5,7 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder;
|
|||||||
import net.mamoe.mirai.event.GlobalEventChannel;
|
import net.mamoe.mirai.event.GlobalEventChannel;
|
||||||
import net.mamoe.mirai.event.events.FriendMessageEvent;
|
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 plugin.constant.ChatConstant;
|
import plugin.constant.ChatConstant;
|
||||||
import plugin.listener.FriendMessageListener;
|
import plugin.listener.FriendMessageListener;
|
||||||
import plugin.listener.GroupMessageListener;
|
import plugin.listener.GroupMessageListener;
|
||||||
@@ -15,6 +16,7 @@ import plugin.utils.ConfigUtil;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +73,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));
|
return !(msg.startsWith(ChatConstant.SET) && sender.equals(owner)) && !msg.equals(ChatConstant.HELP);
|
||||||
})
|
})
|
||||||
.registerListenerHost(new FriendMessageListener());
|
.registerListenerHost(new FriendMessageListener());
|
||||||
|
|
||||||
@@ -83,6 +85,42 @@ public final class App extends JavaPlugin {
|
|||||||
return msg.startsWith(ChatConstant.SET) && sender.equals(owner);
|
return msg.startsWith(ChatConstant.SET) && sender.equals(owner);
|
||||||
}).registerListenerHost(new OwnerMessageListener());
|
}).registerListenerHost(new OwnerMessageListener());
|
||||||
|
|
||||||
|
//帮助监听
|
||||||
|
GlobalEventChannel.INSTANCE
|
||||||
|
.filterIsInstance(MessageEvent.class)
|
||||||
|
.filter(event -> event.getMessage().contentToString().equals(ChatConstant.HELP))
|
||||||
|
.subscribeAlways(MessageEvent.class, event -> {
|
||||||
|
synchronized (customCommands) {
|
||||||
|
final String[] helpMsg = {"""
|
||||||
|
————<群聊命令>————
|
||||||
|
|
||||||
|
@<bot> <content>
|
||||||
|
/<command> <content>
|
||||||
|
|
||||||
|
例:
|
||||||
|
@机器人 你好
|
||||||
|
/c 你好
|
||||||
|
|
||||||
|
————<控制命令>————
|
||||||
|
|
||||||
|
$ clearAll
|
||||||
|
$ shutUp
|
||||||
|
$ speak
|
||||||
|
$ 添加预设|<预设指令>|<模型名称>|<预设内容>
|
||||||
|
$ 切换模型|<预设指令>|<模型名称>
|
||||||
|
$ 更改预设|<预设指令>|<预设内容>
|
||||||
|
$ 删除预设|<预设指令>
|
||||||
|
|
||||||
|
例:
|
||||||
|
$ 添加预设|/c|glm-4-flash|你是一只猫娘...
|
||||||
|
|
||||||
|
"""};
|
||||||
|
helpMsg[0] += "————<预设列表>————";
|
||||||
|
customCommands.forEach((s, s2) -> helpMsg[0] += "\r\n\r\n" + s + "-> \r\n" + s2);
|
||||||
|
event.getSubject().sendMessage(helpMsg[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -42,4 +42,5 @@ public class ChatConstant {
|
|||||||
*/
|
*/
|
||||||
public static final String CURRENT_MODEL = "当前模型";
|
public static final String CURRENT_MODEL = "当前模型";
|
||||||
public static final String SPLIT = "|";
|
public static final String SPLIT = "|";
|
||||||
|
public static final String HELP = "/chatHelp";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class OwnerMessageListener extends SimpleListenerHost {
|
|||||||
String customContent = arguments.split(ConfigConstant.CUSTOM_SPLIT)[2];
|
String customContent = arguments.split(ConfigConstant.CUSTOM_SPLIT)[2];
|
||||||
yield ConfigUtil.addCustom(instruction, customModel, customContent);
|
yield ConfigUtil.addCustom(instruction, customModel, customContent);
|
||||||
} else {
|
} else {
|
||||||
yield "格式不正确! 参数格式如下: \r\n" + ChatConstant.SET + "命令|预设指令|模型名称|预设\r\n例: \r\n"+ChatConstant.SPLIT+"/example|glm-4-flash|你是...\r\n注:如果不需要预设,可以将预设写为null";
|
yield "格式不正确! 格式如下: \r\n" + ChatConstant.SET + "命令|预设指令|模型名称|预设\r\n例: \r\n"+ChatConstant.SPLIT+"/example|glm-4-flash|你是...\r\n注:如果不需要预设,可以将预设写为null";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "切换模型" -> {
|
case "切换模型" -> {
|
||||||
@@ -97,7 +97,7 @@ public class OwnerMessageListener extends SimpleListenerHost {
|
|||||||
String modelName = arguments.split(ConfigConstant.CUSTOM_SPLIT)[1];
|
String modelName = arguments.split(ConfigConstant.CUSTOM_SPLIT)[1];
|
||||||
yield ConfigUtil.customModelChange(instruction, modelName);
|
yield ConfigUtil.customModelChange(instruction, modelName);
|
||||||
} else {
|
} else {
|
||||||
yield "格式不正确! 参数格式如下: \r\n" + ChatConstant.SET + "命令|预设指令|指令对应模型";
|
yield "格式不正确! 格式如下: \r\n" + ChatConstant.SET + "命令|预设指令|指令对应模型";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "更改预设" -> {
|
case "更改预设" -> {
|
||||||
@@ -106,7 +106,7 @@ public class OwnerMessageListener extends SimpleListenerHost {
|
|||||||
String customContent = arguments.split(ConfigConstant.CUSTOM_SPLIT)[1];
|
String customContent = arguments.split(ConfigConstant.CUSTOM_SPLIT)[1];
|
||||||
yield ConfigUtil.customContentChange(instruction, customContent);
|
yield ConfigUtil.customContentChange(instruction, customContent);
|
||||||
} else {
|
} else {
|
||||||
yield "格式不正确! 参数格式如下: \r\n" + ChatConstant.SET + "命令|预设指令|指令对应预设";
|
yield "格式不正确! 格式如下: \r\n" + ChatConstant.SET + "命令|预设指令|指令对应预设";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "删除预设" -> ConfigUtil.removeCustom(arguments);
|
case "删除预设" -> ConfigUtil.removeCustom(arguments);
|
||||||
|
|||||||
@@ -61,9 +61,8 @@ public class ConfigUtil {
|
|||||||
blacklist.add(987654321L);
|
blacklist.add(987654321L);
|
||||||
config.setBlacklist(blacklist);
|
config.setBlacklist(blacklist);
|
||||||
LinkedHashMap<String, String> commands = new LinkedHashMap<>();
|
LinkedHashMap<String, String> commands = new LinkedHashMap<>();
|
||||||
commands.put("default", "null");
|
commands.put("default ", "null");
|
||||||
commands.put("/c ", "glm-4-flash|你是一位智能编程助手,你会为用户回答关于编程、代码、计算机方面的任何问题,并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。 请用中文回答。");
|
commands.put("/c ", "glm-4-flash|你是一位智能编程助手,你会为用户回答关于编程、代码、计算机方面的任何问题,并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。 请用中文回答。");
|
||||||
commands.put("/example ", "模型名称|预设内容");
|
|
||||||
config.setCustomCommands(commands);
|
config.setCustomCommands(commands);
|
||||||
dump();
|
dump();
|
||||||
logger.warning("配置文件创建成功,请关闭后进行配置");
|
logger.warning("配置文件创建成功,请关闭后进行配置");
|
||||||
@@ -87,6 +86,7 @@ public class ConfigUtil {
|
|||||||
|
|
||||||
public static String customModelChange(String instruction, String customModel) throws IOException {
|
public static String customModelChange(String instruction, String customModel) throws IOException {
|
||||||
HashMap<String, String> customCommands = config.getCustomCommands();
|
HashMap<String, String> customCommands = config.getCustomCommands();
|
||||||
|
synchronized (customCommands) {
|
||||||
if (!customCommands.containsKey(instruction)) {
|
if (!customCommands.containsKey(instruction)) {
|
||||||
return "该预设不存在!";
|
return "该预设不存在!";
|
||||||
}
|
}
|
||||||
@@ -95,6 +95,7 @@ public class ConfigUtil {
|
|||||||
dump();
|
dump();
|
||||||
return "模型切换成功: [" + instruction + "->" + customCommands.get(instruction) + "]";
|
return "模型切换成功: [" + instruction + "->" + customCommands.get(instruction) + "]";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void dump() throws IOException {
|
private static void dump() throws IOException {
|
||||||
FileWriter writer = new FileWriter(CONFIG_PATH);
|
FileWriter writer = new FileWriter(CONFIG_PATH);
|
||||||
@@ -132,6 +133,7 @@ public class ConfigUtil {
|
|||||||
*/
|
*/
|
||||||
public static String addCustom(String instruction, String customModel, String customContent) throws IOException {
|
public static String addCustom(String instruction, String customModel, String customContent) throws IOException {
|
||||||
HashMap<String, String> customCommands = config.getCustomCommands();
|
HashMap<String, String> customCommands = config.getCustomCommands();
|
||||||
|
synchronized (customCommands) {
|
||||||
if (customCommands.containsKey(instruction)) {
|
if (customCommands.containsKey(instruction)) {
|
||||||
return "已存在当前指令! \r\n[" + instruction + "->" + customCommands.get(instruction) + "]";
|
return "已存在当前指令! \r\n[" + instruction + "->" + customCommands.get(instruction) + "]";
|
||||||
}
|
}
|
||||||
@@ -140,6 +142,7 @@ public class ConfigUtil {
|
|||||||
dump();
|
dump();
|
||||||
return "预设添加完毕! \r\n[" + instruction + "->" + content + "]";
|
return "预设添加完毕! \r\n[" + instruction + "->" + content + "]";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 改变指令对应预设
|
* 改变指令对应预设
|
||||||
@@ -150,6 +153,7 @@ public class ConfigUtil {
|
|||||||
*/
|
*/
|
||||||
public static String customContentChange(String instruction, String customContent) throws IOException {
|
public static String customContentChange(String instruction, String customContent) throws IOException {
|
||||||
HashMap<String, String> customCommands = config.getCustomCommands();
|
HashMap<String, String> customCommands = config.getCustomCommands();
|
||||||
|
synchronized (customCommands) {
|
||||||
if (!customCommands.containsKey(instruction)) {
|
if (!customCommands.containsKey(instruction)) {
|
||||||
return "该指令不存在!";
|
return "该指令不存在!";
|
||||||
}
|
}
|
||||||
@@ -158,9 +162,11 @@ public class ConfigUtil {
|
|||||||
dump();
|
dump();
|
||||||
return "预设更改成功! \r\n[" + instruction + "->" + customCommands.get(instruction) + "]";
|
return "预设更改成功! \r\n[" + instruction + "->" + customCommands.get(instruction) + "]";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String removeCustom(String arguments) throws IOException {
|
public static String removeCustom(String arguments) throws IOException {
|
||||||
HashMap<String, String> customCommands = getConfig().getCustomCommands();
|
HashMap<String, String> customCommands = getConfig().getCustomCommands();
|
||||||
|
synchronized (customCommands) {
|
||||||
if (!customCommands.containsKey(arguments + ChatConstant.BLANK)) {
|
if (!customCommands.containsKey(arguments + ChatConstant.BLANK)) {
|
||||||
return "该预设不存在";
|
return "该预设不存在";
|
||||||
}
|
}
|
||||||
@@ -169,4 +175,5 @@ public class ConfigUtil {
|
|||||||
dump();
|
dump();
|
||||||
return "删除预设[" + arguments + "->" + content + "]成功";
|
return "删除预设[" + arguments + "->" + content + "]成功";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user