Fix invalid Discord command handling

This commit is contained in:
Allink 2023-07-25 03:57:24 +01:00
parent 8876076a9d
commit b2c636f919
No known key found for this signature in database
2 changed files with 17 additions and 4 deletions

View File

@ -58,9 +58,8 @@ public class DiscordToMinecraftListener extends ListenerAdapter
final Message msg = event.getMessage(); final Message msg = event.getMessage();
final String content = msg.getContentStripped(); final String content = msg.getContentStripped();
if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString())) if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString()) && Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel))
{ {
Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel);
return; return;
} }

View File

@ -46,11 +46,21 @@ public class DiscordCommandManager
FLog.info("Loaded " + commands.size() + " Discord commands."); FLog.info("Loaded " + commands.size() + " Discord commands.");
} }
public void parse(String content, Member member, TextChannel channel) public boolean parse(String content, Member member, TextChannel channel)
{ {
List<String> args = new ArrayList<>(Arrays.asList(content.split(" "))); List<String> args = new ArrayList<>(Arrays.asList(content.split(" ")));
if (args.isEmpty())
{
return false;
}
final String alias = args.remove(0).split(PREFIX)[1]; // The joys of command parsing final String[] aliasParts = args.remove(0).split(PREFIX);
if (aliasParts.length < 2)
{
return false;
}
final String alias = aliasParts[1];
for (DiscordCommand command : commands) for (DiscordCommand command : commands)
{ {
@ -63,6 +73,7 @@ public class DiscordCommandManager
final CompletableFuture<Message> futureMessage = channel.sendMessage(message).submit(true); final CompletableFuture<Message> futureMessage = channel.sendMessage(message).submit(true);
this.discord.sentMessages.add(futureMessage); this.discord.sentMessages.add(futureMessage);
return true;
} }
else else
{ {
@ -77,8 +88,11 @@ public class DiscordCommandManager
final CompletableFuture<Message> futureMessage = channel.sendMessage(message).submit(true); final CompletableFuture<Message> futureMessage = channel.sendMessage(message).submit(true);
this.discord.sentMessages.add(futureMessage); this.discord.sentMessages.add(futureMessage);
return true;
} }
} }
} }
return false;
} }
} }