|
|
|
@ -32,6 +32,11 @@ public class CommandDispatcher
|
|
|
|
|
*/
|
|
|
|
|
private HashMap<String, String> shortList;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The command prefix used to call commands
|
|
|
|
|
*/
|
|
|
|
|
private String commandPrefix;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Basic Constructor, automatically rebuilds command list from the modules registry
|
|
|
|
|
*/
|
|
|
|
@ -39,6 +44,14 @@ public class CommandDispatcher
|
|
|
|
|
{
|
|
|
|
|
logger = Logger.getLogger(this.getClass().getName());
|
|
|
|
|
rebuildCommandList();
|
|
|
|
|
|
|
|
|
|
if(Configuration.exists("general", "commandPrefix") && !Configuration.getValue("general", "commandPrefix").isEmpty())
|
|
|
|
|
commandPrefix = Configuration.getValue("general", "commandPrefix");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.warning("Invalid command prefix detected, falling back to \"!\"");
|
|
|
|
|
commandPrefix = "!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -49,7 +62,7 @@ public class CommandDispatcher
|
|
|
|
|
public void onMessageReceivedEvent(MessageReceivedEvent event)
|
|
|
|
|
{
|
|
|
|
|
// Command matcher
|
|
|
|
|
Matcher m = Pattern.compile("^!([:\\w]+)(?: (.*))?$").matcher(event.getMessage().getContent());
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
@ -178,7 +191,7 @@ public class CommandDispatcher
|
|
|
|
|
InvokableMethod matchingMethod = commandList.get(command);
|
|
|
|
|
|
|
|
|
|
StringBuffer toReturn = new StringBuffer("Usage: ");
|
|
|
|
|
toReturn.append("!" + command + " ");
|
|
|
|
|
toReturn.append(commandPrefix + command + " ");
|
|
|
|
|
for(int i=1; i<matchingMethod.getMethod().getParameterCount(); i++)
|
|
|
|
|
toReturn.append(matchingMethod.getMethod().getParameterTypes()[i].getName() + " ");
|
|
|
|
|
|
|
|
|
|