pingex
/
DiscordBot
Archived
1
0
Fork 0

Commands are now case-insensitive. Closes #1

master
Pingex aka Raphaël 9 years ago
parent 039e62b311
commit f5e396cfe0

@ -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);
}

@ -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);