pingex
/
DiscordBot
Archived
1
0
Fork 0

An invalid commandPrefix is now fixed Configuration-wide.

master
Pingex aka Raphaël 9 years ago
parent a07da9394e
commit 47ca96889c

@ -39,11 +39,6 @@ class CommandDispatcher
*/ */
private HashMap<String, String> shortList; private HashMap<String, String> shortList;
/**
* The command prefix used to call commands
*/
private String commandPrefix;
/** /**
* Thread pool used to invoke commands * Thread pool used to invoke commands
*/ */
@ -58,12 +53,10 @@ class CommandDispatcher
rebuildCommandList(); rebuildCommandList();
threadPool = Executors.newCachedThreadPool(new BasicThreadFactory.Builder().namingPattern("CommandDispatcher-%d").build()); // TODO: threadPool.shutdown() threadPool = Executors.newCachedThreadPool(new BasicThreadFactory.Builder().namingPattern("CommandDispatcher-%d").build()); // TODO: threadPool.shutdown()
if(Configuration.exists("general", "commandPrefix") && !Configuration.getValue("general", "commandPrefix").isEmpty()) 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 \"!\""); logger.warning("Invalid command prefix detected, falling back to \"!\"");
commandPrefix = "!"; Configuration.setValue("general", "commandPrefix", "!");
} }
} }
@ -84,7 +77,7 @@ class CommandDispatcher
public void onMessageReceivedEvent(MessageReceivedEvent event) public void onMessageReceivedEvent(MessageReceivedEvent event)
{ {
// Command matcher // Command matcher
Matcher m = Pattern.compile("^" + commandPrefix + "([:\\w]+)(?: (.*))?$").matcher(event.getMessage().getContent()); Matcher m = Pattern.compile("^" + Configuration.getValue("general", "commandPrefix") + "([:\\w]+)(?: (.*))?$").matcher(event.getMessage().getContent());
if(!m.matches()) return; // We don't need to go further if it's not even a command if(!m.matches()) return; // We don't need to go further if it's not even a command
String fullCommand = m.group(1).toLowerCase(); String fullCommand = m.group(1).toLowerCase();