diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java index 1b3fab1..292282f 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java @@ -140,6 +140,7 @@ public final class PurpleBot { public CaseInsensitiveMap> muteList; public CaseInsensitiveMap> enabledMessages; public CaseInsensitiveMap>> commandMap; + public CaseInsensitiveMap>> extraCommandMap; public CaseInsensitiveMap joinNoticeCooldownMap; public ArrayList whoisSenders; public List channelCmdNotifyRecipients; @@ -167,6 +168,7 @@ public PurpleBot(File file, PurpleIRC plugin) { this.channelCmdNotifyRecipients = new ArrayList<>(); this.channelCmdNotifyIgnore = new ArrayList<>(); this.commandMap = new CaseInsensitiveMap<>(); + this.extraCommandMap = new CaseInsensitiveMap<>(); this.joinNoticeCooldownMap = new CaseInsensitiveMap<>(); this.enabledMessages = new CaseInsensitiveMap<>(); this.muteList = new CaseInsensitiveMap<>(); @@ -631,6 +633,7 @@ private void loadConfig() { enabledMessages.clear(); worldList.clear(); commandMap.clear(); + extraCommandMap.clear(); channelCmdNotifyEnabled = config.getBoolean("command-notify.enabled", false); plugin.logDebug(" CommandNotifyEnabled => " + channelCmdNotifyEnabled); @@ -830,15 +833,19 @@ private void loadConfig() { // build command map CaseInsensitiveMap> map = new CaseInsensitiveMap<>(); + CaseInsensitiveMap> extraMap = new CaseInsensitiveMap<>(); try { for (String command : config.getConfigurationSection("channels." + enChannelName + ".commands").getKeys(false)) { plugin.logDebug(" Command => " + command); CaseInsensitiveMap optionPair = new CaseInsensitiveMap<>(); + List extraCommands = new ArrayList<>(); String commandKey = "channels." + enChannelName + ".commands." + command + "."; optionPair.put("modes", config.getString(commandKey + "modes", "*")); optionPair.put("private", config.getString(commandKey + "private", "false")); optionPair.put("ctcp", config.getString(commandKey + "ctcp", "false")); - optionPair.put("game_command", config.getString(commandKey + "game_command", "@help")); + optionPair.put("game_command", config.getString(commandKey + "game_command", "")); + extraCommands.addAll(config.getStringList(commandKey + "extra_commands")); + plugin.logDebug("extra_commands: " + extraCommands.toString()); optionPair.put("private_listen", config.getString(commandKey + "private_listen", "true")); optionPair.put("channel_listen", config.getString(commandKey + "channel_listen", "true")); optionPair.put("perm", config.getString(commandKey + "perm", "")); @@ -846,11 +853,13 @@ private void loadConfig() { config.set(commandKey + s, optionPair.get(s)); } map.put(command, optionPair); + extraMap.put(command, extraCommands); } } catch (Exception ex) { plugin.logError("No commands found for channel " + enChannelName); } commandMap.put(channelName, map); + extraCommandMap.put(channelName, extraMap); if (map.isEmpty()) { plugin.logInfo("No commands specified!"); } diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/IRCMessageHandler.java b/src/main/java/com/cnaude/purpleirc/Utilities/IRCMessageHandler.java index 857e2ec..ae3ab1a 100644 --- a/src/main/java/com/cnaude/purpleirc/Utilities/IRCMessageHandler.java +++ b/src/main/java/com/cnaude/purpleirc/Utilities/IRCMessageHandler.java @@ -88,14 +88,16 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String return; } - String gameCommand = (String) ircBot.commandMap.get(myChannel).get(command).get("game_command"); + String gc = (String) ircBot.commandMap.get(myChannel).get(command).get("game_command"); + List extraCommands = ircBot.extraCommandMap.get(myChannel).get(command); + List gameCommands = new ArrayList<>(); + gameCommands.add(gc); + gameCommands.addAll(extraCommands); String modes = (String) ircBot.commandMap.get(myChannel).get(command).get("modes"); String perm = (String) ircBot.commandMap.get(myChannel).get(command).get("perm"); boolean privateCommand = Boolean.parseBoolean(ircBot.commandMap.get(myChannel).get(command).get("private")); boolean ctcpResponse = Boolean.parseBoolean(ircBot.commandMap.get(myChannel).get(command).get("ctcp")); - plugin.logDebug(gameCommand + ":" + modes + ":" + privateCommand); - if (privateCommand || privateMessage) { target = user.getNick(); } @@ -103,60 +105,62 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String plugin.logDebug("Target: " + target); if (isValidMode(modes, user, channel) && checkPerm(perm, user.getNick())) { - switch (gameCommand) { - case "@list": - sendMessage(ircBot, target, plugin.getMCPlayers(ircBot, myChannel), ctcpResponse); - break; - case "@uptime": - sendMessage(ircBot, target, plugin.getMCUptime(), ctcpResponse); - break; - case "@help": - sendMessage(ircBot, target, getCommands(ircBot.commandMap, myChannel), ctcpResponse); - break; - case "@chat": - ircBot.broadcastChat(user, channel, target, commandArgs, false, ctcpResponse); - break; - case "@ochat": - ircBot.broadcastChat(user, channel, target, commandArgs, true, ctcpResponse); - break; - case "@hchat": - ircBot.broadcastHeroChat(user, channel, target, commandArgs); - break; - case "@motd": - sendMessage(ircBot, target, plugin.getServerMotd(), ctcpResponse); - break; - case "@rtsmb": - if (plugin.reportRTSHook != null) { - plugin.reportRTSHook.modBroadcast(user.getNick(), commandArgs); - } - break; - case "@msg": - ircBot.playerChat(user, channel, target, commandArgs); - break; - case "@clearqueue": - sendMessage(ircBot, target, plugin.commandQueue.clearQueue(), ctcpResponse); - sendMessage(ircBot, target, ircBot.messageQueue.clearQueue(), ctcpResponse); - break; - case "@query": - sendMessage(ircBot, target, plugin.getRemotePlayers(commandArgs), ctcpResponse); - break; - default: - if (commandArgs == null) { - commandArgs = ""; - } - if (gameCommand.contains("%ARGS%")) { - gameCommand = gameCommand.replace("%ARGS%", commandArgs); - } - if (gameCommand.contains("%NAME%")) { - gameCommand = gameCommand.replace("%NAME%", user.getNick()); - } - plugin.logDebug("GM: \"" + gameCommand.trim() + "\""); - try { - plugin.commandQueue.add(new IRCCommand(new IRCCommandSender(ircBot, target, plugin, ctcpResponse), gameCommand.trim())); - } catch (Exception ex) { - plugin.logError(ex.getMessage()); - } - break; + for (String gameCommand : gameCommands) { + switch (gameCommand) { + case "@list": + sendMessage(ircBot, target, plugin.getMCPlayers(ircBot, myChannel), ctcpResponse); + break; + case "@uptime": + sendMessage(ircBot, target, plugin.getMCUptime(), ctcpResponse); + break; + case "@help": + sendMessage(ircBot, target, getCommands(ircBot.commandMap, myChannel), ctcpResponse); + break; + case "@chat": + ircBot.broadcastChat(user, channel, target, commandArgs, false, ctcpResponse); + break; + case "@ochat": + ircBot.broadcastChat(user, channel, target, commandArgs, true, ctcpResponse); + break; + case "@hchat": + ircBot.broadcastHeroChat(user, channel, target, commandArgs); + break; + case "@motd": + sendMessage(ircBot, target, plugin.getServerMotd(), ctcpResponse); + break; + case "@rtsmb": + if (plugin.reportRTSHook != null) { + plugin.reportRTSHook.modBroadcast(user.getNick(), commandArgs); + } + break; + case "@msg": + ircBot.playerChat(user, channel, target, commandArgs); + break; + case "@clearqueue": + sendMessage(ircBot, target, plugin.commandQueue.clearQueue(), ctcpResponse); + sendMessage(ircBot, target, ircBot.messageQueue.clearQueue(), ctcpResponse); + break; + case "@query": + sendMessage(ircBot, target, plugin.getRemotePlayers(commandArgs), ctcpResponse); + break; + default: + if (commandArgs == null) { + commandArgs = ""; + } + if (gameCommand.contains("%ARGS%")) { + gameCommand = gameCommand.replace("%ARGS%", commandArgs); + } + if (gameCommand.contains("%NAME%")) { + gameCommand = gameCommand.replace("%NAME%", user.getNick()); + } + plugin.logDebug("GM: \"" + gameCommand.trim() + "\""); + try { + plugin.commandQueue.add(new IRCCommand(new IRCCommandSender(ircBot, target, plugin, ctcpResponse), gameCommand.trim())); + } catch (Exception ex) { + plugin.logError(ex.getMessage()); + } + break; + } } } else { plugin.logDebug("User '" + user.getNick() + "' mode not okay."); diff --git a/src/main/resources/SampleBot.yml b/src/main/resources/SampleBot.yml index af52c8f..8b0c379 100644 --- a/src/main/resources/SampleBot.yml +++ b/src/main/resources/SampleBot.yml @@ -7,8 +7,8 @@ nick: AwesomeBot # If your bot's nick is in use try these alternates. Leave blank for none. alt-nicks: - - AwesomeBot_ - - AwesomeBotA + - %NICK%_ + - %NICK%__ # login - Your bot's login name login: AwesomeName # realname @@ -305,6 +305,16 @@ channels: private_listen: 'true' channel_listen: 'true' perm: '' + lv: + modes: 'o' + private: 'false' + ctcp: 'false' + game_command: '@list' + extra_commands: + - version + private_listen: 'true' + channel_listen: 'true' + perm: '' # gamemode: # modes: 'o' # private: false