From ec19b6d3982c47454d25bb7bed5b37c7dc9a072d Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 04:13:40 +0100 Subject: [PATCH] Make the Discord command parsing more forgiving --- .../discord/DiscordToMinecraftListener.java | 2 +- .../discord/command/DiscordCommandManager.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index 81519493..29a7bdcb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -58,7 +58,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter final Message msg = event.getMessage(); final String content = msg.getContentStripped(); - if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString()) && Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel)) + if (content.toLowerCase().startsWith(ConfigEntry.DISCORD_PREFIX.getString().toLowerCase()) && Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel)) { return; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java index 1426444b..4f669230 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java @@ -48,20 +48,20 @@ public class DiscordCommandManager public boolean parse(String content, Member member, TextChannel channel) { - List args = new ArrayList<>(Arrays.asList(content.split(" "))); + final String actualContent = content.substring(PREFIX.length()).trim(); + List args = new ArrayList<>(Arrays.asList(actualContent.split(" "))); if (args.isEmpty()) { return false; } - final String[] aliasParts = args.remove(0).split(PREFIX); - if (aliasParts.length < 2) + final String alias = args.get(0); + + if (alias.isEmpty()) { return false; } - final String alias = aliasParts[1]; - for (DiscordCommand command : commands) { if (command.getCommandName().equalsIgnoreCase(alias) || command.getAliases().contains(alias.toLowerCase()))