From f5e396cfe06264b4702bfedb9ca3dab552ca7a77 Mon Sep 17 00:00:00 2001 From: Pingex Date: Wed, 27 Apr 2016 13:07:28 +0200 Subject: [PATCH] Commands are now case-insensitive. Closes #1 --- .../java/net/pingex/discordbot/CommandDispatcher.java | 8 ++++---- .../net/pingex/discordbot/InternalCommandsModule.java | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/pingex/discordbot/CommandDispatcher.java b/src/main/java/net/pingex/discordbot/CommandDispatcher.java index 0f45df9..ddb7c77 100644 --- a/src/main/java/net/pingex/discordbot/CommandDispatcher.java +++ b/src/main/java/net/pingex/discordbot/CommandDispatcher.java @@ -86,7 +86,7 @@ class CommandDispatcher // Command matcher Matcher m = Pattern.compile("^" + commandPrefix + "([:\\w]+)(?: (.*))?$").matcher(event.getMessage().getContent()); if(!m.matches()) return; // We don't need to go further if it's not even a command - String fullCommand = m.group(1); + String fullCommand = m.group(1).toLowerCase(); // Arg splitter Matcher am = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher((m.group(2) != null) ? m.group(2) : ""); @@ -188,7 +188,7 @@ class CommandDispatcher for(Method j : i.getClass().getDeclaredMethods()) if(j.isAnnotationPresent(Command.class)) { - String id = i.getClass().getAnnotation(Controllable.class).name() + ":" + j.getName(); + String id = i.getClass().getAnnotation(Controllable.class).name() + ":" + j.getName().toLowerCase(); logger.info("Found " + id); if(j.getParameterCount() >= 1 && j.getParameterTypes()[0] == MessageReceivedEvent.class && j.getReturnType() == String.class) @@ -198,8 +198,8 @@ class CommandDispatcher // Eventual command shorthands if(!j.getAnnotation(Command.class).shorthand().isEmpty()) - if(!shortList.containsKey(j.getAnnotation(Command.class).shorthand())) - shortList.put(j.getAnnotation(Command.class).shorthand(), id); + if(!shortList.containsKey(j.getAnnotation(Command.class).shorthand().toLowerCase())) + shortList.put(j.getAnnotation(Command.class).shorthand().toLowerCase(), id); else logger.warning("Conflicting shorthand for command " + id); } diff --git a/src/main/java/net/pingex/discordbot/InternalCommandsModule.java b/src/main/java/net/pingex/discordbot/InternalCommandsModule.java index 2e4b1f0..0637c2f 100644 --- a/src/main/java/net/pingex/discordbot/InternalCommandsModule.java +++ b/src/main/java/net/pingex/discordbot/InternalCommandsModule.java @@ -27,7 +27,9 @@ public class InternalCommandsModule extends AbstractModule public String help(MessageReceivedEvent event, String command) { if(!command.contains(":") && CommandDispatcher.getInstance().getShortList().containsKey(command)) - command = CommandDispatcher.getInstance().getShortList().get(command); + command = CommandDispatcher.getInstance().getShortList().get(command.toLowerCase()); + else + command = command.toLowerCase(); if(!CommandDispatcher.getInstance().getCommandList().containsKey(command)) return "No help available for this command."; InvokableMethod matchingMethod = CommandDispatcher.getInstance().getCommandList().get(command);