pingex
/
DiscordBot
Archived
1
0
Fork 0

Command prefix.

master
Pingex aka Raphaël 9 years ago
parent 94da2ceb2d
commit b21e6c9647

@ -1,3 +1,8 @@
[general]
; The command prefix which precedes the actual command, ie: "§" for "§command arguments".
; Will fallback to "!" if the prefix is invalid or empty.
commandPrefix = !
[discord]
; Change next value to true if the account is a bot, thus logins using a token.
; Don't forget to uncomment token then

@ -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() + " ");