From 5a59f0db79501bdbe4aad38a635310488a500370 Mon Sep 17 00:00:00 2001 From: cnaude Date: Sun, 27 Sep 2015 09:39:04 -0700 Subject: [PATCH] Implement user_masks[] option --- .../java/com/cnaude/purpleirc/PurpleBot.java | 18 ++++- .../purpleirc/Utilities/NetPackets.java | 1 - src/main/resources/SampleBot.yml | 73 ++++++++++++++----- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java index b96ed87..4159de5 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java @@ -155,6 +155,7 @@ public final class PurpleBot { public String defaultCustomPrefix; public CaseInsensitiveMap>> commandMap; public CaseInsensitiveMap>> extraCommandMap; + public CaseInsensitiveMap>> commandUsermasksMap; public CaseInsensitiveMap joinNoticeCooldownMap; public ArrayList whoisSenders; public List channelCmdNotifyRecipients; @@ -203,6 +204,7 @@ public PurpleBot(File file, PurpleIRC plugin) { this.channelCmdNotifyIgnore = new ArrayList<>(); this.commandMap = new CaseInsensitiveMap<>(); this.extraCommandMap = new CaseInsensitiveMap<>(); + this.commandUsermasksMap = new CaseInsensitiveMap<>(); this.joinNoticeCooldownMap = new CaseInsensitiveMap<>(); this.enabledMessages = new CaseInsensitiveMap<>(); this.firstOccurrenceReplacements = new CaseInsensitiveMap<>(); @@ -717,6 +719,7 @@ private boolean loadConfig() { worldList.clear(); commandMap.clear(); extraCommandMap.clear(); + commandUsermasksMap.clear(); channelCmdNotifyEnabled = config.getBoolean("command-notify.enabled", false); plugin.logDebug(" CommandNotifyEnabled => " + channelCmdNotifyEnabled); @@ -980,34 +983,45 @@ private boolean loadConfig() { // build command map CaseInsensitiveMap> map = new CaseInsensitiveMap<>(); CaseInsensitiveMap> extraMap = new CaseInsensitiveMap<>(); + CaseInsensitiveMap> userMaskMap = 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<>(); + List userMasks = 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", "")); optionPair.put("game_command_usage", config.getString(commandKey + "game_command_usage", "")); optionPair.put("sender", config.getString(commandKey + "sender", "CONSOLE")); - 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", "")); for (String s : optionPair.keySet()) { config.set(commandKey + s, optionPair.get(s)); } + + extraCommands.addAll(config.getStringList(commandKey + "extra_commands")); + plugin.logDebug("extra_commands: " + extraCommands.toString()); + userMasks.addAll(config.getStringList(commandKey + "user_masks")); + plugin.logDebug("user_masks: " + userMasks.toString()); + map.put(command, optionPair); extraMap.put(command, extraCommands); + userMaskMap.put(command, userMasks); + config.set(commandKey + "extra_commands", extraCommands); + config.set(commandKey + "user_masks", userMasks); } } catch (Exception ex) { plugin.logError("No commands found for channel " + enChannelName); } commandMap.put(channelName, map); extraCommandMap.put(channelName, extraMap); + commandUsermasksMap.put(channelName, userMaskMap); if (map.isEmpty()) { plugin.logInfo("No commands specified!"); } diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java b/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java index 9c9b55d..ddbc375 100644 --- a/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java +++ b/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java @@ -18,7 +18,6 @@ import com.cnaude.purpleirc.PurpleBot; import com.cnaude.purpleirc.PurpleIRC; -import com.cnaude.purpleirc.TemplateName; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.Packets; import com.comphenix.protocol.ProtocolLibrary; diff --git a/src/main/resources/SampleBot.yml b/src/main/resources/SampleBot.yml index d81cacc..be55ccb 100644 --- a/src/main/resources/SampleBot.yml +++ b/src/main/resources/SampleBot.yml @@ -41,7 +41,7 @@ autoconnect: 'false' password: '' # identify password (sent to NickServ) ident-password: '' -# command-prefix - The bot will listen for commands that start with this. +# command-prefix - The bot will listen for commands that start with this. command-prefix: '.' # quit-message - Message the bot will send when it quits the server quit-message: '&r[&5PurpleIRC&r] &rGood bye!' @@ -101,12 +101,12 @@ action-commands: bot-linking-enabled: false # Map of remote linked bots and codes. Use /irc link and /irc linkaccept bot-links: -# - remotebot: 249505593790847552435733176657146971496 +# - remotebot: 249505593790847552435733176657146971496 # channels - List the channels your bot will join here channels: # Channel name must be surrounded by sing quotes to be YAML compliant. # Use %2E instead of dots in the channel names. - # Example: minecraft%2Etest == minecraft.test + # Example: minecraft%2Etest == minecraft.test '#minecraft-test': # message prefix (replaces %CHANNELPREFIX% prefix: '' @@ -122,7 +122,7 @@ channels: # topic - Channel topic topic: New topic # topic-protect - Prevent others from changing the topic - topic-protect: false + topic-protect: false # Enable chanserve mode for topic set command (/msg chanserv topic #channel topic-chanserv: false # If the Shortify plugin is installed then shoten URLs sent from IRC @@ -130,10 +130,10 @@ channels: # Enable or disable message filtering enable-filtering: false # Filters. These wll be removed from IRC to game messages. - filter-list: + filter-list: - AwesomeBot # enabled-messages - These are the message types that are either sent to the game or IRC - # config.yml. Remove or comment the messages you don't want. + # config.yml. Remove or comment the messages you don't want. enabled-messages: # These messages are sent from game to IRC (see permissions) - console-chat @@ -146,8 +146,8 @@ channels: - game-achievement - game-mode - fake-join - - fake-quit - # Essentials helpop messages (/helpop /amsg /ac) + - fake-quit + # Essentials helpop messages (/helpop /amsg /ac) - ess-helpop # Prism #- prism-rollback @@ -178,7 +178,7 @@ channels: - irc-action-dynmap-web-chat # mcMMO messages sent to IRC - mcmmo-admin-chat - - mcmmo-party-chat + - mcmmo-party-chat - mcmmo-chat # mcMMO messages sent from IRC. Replace [PARTY] with destination mcMMO party - irc-mcmmo-admin-chat @@ -227,17 +227,17 @@ channels: #- game-a-chat # AdminPrivateChat messages IRC to game #- irc-a-chat - # Hero channel destination for IRC messages + # Hero channel destination for IRC messages hero-channel: admin # Towny channel destination for IRC messages towny-channel: irc - # Log all messages from IRC to HeroChat + # Log all messages from IRC to HeroChat log-irc-to-hero-chat: false # ops - IRC hostname mask styled ops list - ops: + ops: - '*!*sarah@example.com' # muted - IRC users that should not be heard in game - muted: + muted: - KuShy # Set ignore-irc-chat to true if you are using @chat and don't want regular IRC chat in your game ignore-irc-chat: false @@ -295,81 +295,111 @@ channels: private: false ctcp: false game_command: '@chat' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' ochat: modes: '*' private: false ctcp: false - game_command: '@ochat' + game_command: '@ochat' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' h: modes: '*' private: false ctcp: false - game_command: '@hchat' + game_command: '@hchat' + extras_commands: [] private_listen: true - channel_listen: true + channel_listen: true + user_masks: [] + perm: '' msg: modes: '*' private: true ctcp: false game_command: '@msg' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' list: modes: '*' private: false ctcp: false - game_command: '@list' + game_command: '@list' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' help: modes: '*' private: false ctcp: false game_command: '@help' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' uptime: modes: '*' private: false ctcp: false - game_command: '@uptime' + game_command: '@uptime' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' version: modes: '*' private: false ctcp: false game_command: '@versionfull' + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' lag: modes: '*' private: false ctcp: false - game_command: lag + game_command: lag + extras_commands: [] private_listen: true channel_listen: true + user_masks: [] + perm: '' mb: modes: 'o' private: 'false' ctcp: 'false' game_command: '@rtsmb' + extras_commands: [] private_listen: 'true' channel_listen: 'true' + user_masks: [] perm: '' lv: modes: 'o' private: 'false' ctcp: 'false' game_command: '@list' - extra_commands: + extra_commands: - '@version' private_listen: 'true' channel_listen: 'true' + user_masks: [] perm: '' ## Uncomment this if you want to hook into AdminPrivateChat # a: @@ -379,6 +409,7 @@ channels: # game_command: '@a' # private_listen: true # channel_listen: true +# user_masks: [] ## Uncomment this to allow gamemode changes via IRC # gamemode: # modes: 'o' @@ -387,6 +418,7 @@ channels: # game_command: 'gamemode %ARGS%' # private_listen: true # channel_listen: true +# user_masks: [] ## Sample of %ARGX% and %ARGX+% with game_command_usage # mute: # modes: o @@ -400,3 +432,4 @@ channels: # channel_listen: 'true' # perm: '' # sender: CONSOLE +# user_masks: []