diff --git a/config.example.ini b/config.example.ini index 8905b82..340d052 100644 --- a/config.example.ini +++ b/config.example.ini @@ -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 diff --git a/src/main/java/net/pingex/discordbot/CommandDispatcher.java b/src/main/java/net/pingex/discordbot/CommandDispatcher.java index 12af0fc..e4bbc45 100644 --- a/src/main/java/net/pingex/discordbot/CommandDispatcher.java +++ b/src/main/java/net/pingex/discordbot/CommandDispatcher.java @@ -32,6 +32,11 @@ public class CommandDispatcher */ private HashMap 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