From b4ea2360cc7630154fd34e7888570d38df5e2ee9 Mon Sep 17 00:00:00 2001 From: A0000Xz <122650088+A0000Xz@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:14:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=A5=E6=A0=BC=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 会对自定义指令的配置文件制作有所影响,但至少不会被玩坏了 --- .../java/cn/evole/mods/mcbot/cmds/CmdApi.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java index 39cbdbd9..f74345d5 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java @@ -39,15 +39,25 @@ private static void GuildCmd(String guildId, String channelId, String cmd, boole public static void invokeCommandGroup(GroupMessageEvent event) { String command = event.getMessage().substring(1);//去除前缀 + String origincommand = command; + command = BotUtils.cmdParse(command); + String performedcommand = command; - if (BotUtils.groupAdminParse(event)) { + if (performedcommand.equals("list")) { + // 如果指令包含list,则强行以非管理员身份执行 CustomCmdHandler.INSTANCE.getCustomCmds().stream() - .filter(customCmd -> command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, command), true));//admin - } else - CustomCmdHandler.INSTANCE.getCustomCmds().stream() - .filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, command), false)); + .filter(customCmd -> customCmd.getRequirePermission() < 1 && performedcommand.equals(customCmd.getCmdAlies())) + .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, origincommand), false)); + }else{ + if (BotUtils.groupAdminParse(event)) { + CustomCmdHandler.INSTANCE.getCustomCmds().stream() + .filter(customCmd -> performedcommand.equals(customCmd.getCmdAlies())) + .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, origincommand), true));//admin + } else + CustomCmdHandler.INSTANCE.getCustomCmds().stream() + .filter(customCmd -> customCmd.getRequirePermission() < 1 && performedcommand.equals(customCmd.getCmdAlies())) + .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, origincommand), false)); + } } @@ -56,10 +66,10 @@ public static void invokeCommandGuild(GuildMessageEvent event) { if (BotUtils.guildAdminParse(event)) { CustomCmdHandler.INSTANCE.getCustomCmds().stream() - .filter(customCmd -> command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), true));//admin + 。filter(customCmd -> command.contains(customCmd.getCmdAlies())) + 。forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), true));//admin } else CustomCmdHandler.INSTANCE.getCustomCmds().stream() - .filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), false)); + 。filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) + 。forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), false)); } -} \ No newline at end of file +} From bf0050128aeb7352923e7fe2773e552cc76ddf90 Mon Sep 17 00:00:00 2001 From: A0000Xz <122650088+A0000Xz@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:15:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=85=8D=E5=A5=97=E4=B8=A5=E6=A0=BC?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E6=A0=A1=E9=AA=8C=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/evole/mods/mcbot/util/onebot/BotUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java b/fabric/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java index 9c2e9e50..a9fab5ae 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java @@ -84,4 +84,16 @@ private static int getSubStr(String str) { // 查找字符出现的个数 = (原字符串长度 - 替换后的字符串长度)/要查找的字符串长度 return (str.length() - destStr.length()) / "%".length(); } + public static String cmdParse(String command) { + // 找到最后一个空格的位置 + int lastSpaceIndex = command.lastIndexOf(" "); + + // 如果没有空格,则整个命令就是关键词 + if (lastSpaceIndex == -1) { + return command; + } + + // 返回最后一个空格之前的内容 + return command.substring(0, lastSpaceIndex); + } } From 630a14fd2831643615a5fbbc46774793d557de45 Mon Sep 17 00:00:00 2001 From: A0000Xz <122650088+A0000Xz@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:21:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=BF=9B=E8=A1=8C=E4=B8=A5=E6=A0=BC=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 或许会对自定义命令配置文件有新的格式要求 --- .../main/java/cn/evole/mods/mcbot/cmds/CmdApi.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java index f74345d5..b0a38626 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java @@ -17,9 +17,9 @@ public class CmdApi { private static StringBuilder CmdMain(String cmd, boolean isOp) { StringBuilder result = new StringBuilder(); //#if MC >= 11900 - //$$ McBot.SERVER.getCommands().performPrefixedCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd);//优雅 + McBot.SERVER.getCommands().performPrefixedCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd);//优雅 //#else - McBot.SERVER.getCommands().performCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd); + //$$ McBot.SERVER.getCommands().performCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd); //#endif for (String s : (isOp ? BotCmdRun.OP.outPut : BotCmdRun.CUSTOM.outPut)) { result.append(s.replaceAll("§\\S", "")).append("\n"); @@ -66,10 +66,10 @@ public static void invokeCommandGuild(GuildMessageEvent event) { if (BotUtils.guildAdminParse(event)) { CustomCmdHandler.INSTANCE.getCustomCmds().stream() - 。filter(customCmd -> command.contains(customCmd.getCmdAlies())) - 。forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), true));//admin + .filter(customCmd -> command.contains(customCmd.getCmdAlies())) + .forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), true));//admin } else CustomCmdHandler.INSTANCE.getCustomCmds().stream() - 。filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) - 。forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), false)); + .filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) + .forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), false)); } }