From ee5e974566395c01da714bec39e64ce515124b87 Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Sun, 6 Nov 2011 14:30:48 +0100 Subject: [PATCH] [FIXED JENKINS-11606]: configuration option to disable commands in chat rooms --- .../hudson/plugins/ircbot/IrcPublisher.java | 19 +++++++++---------- .../hudson/plugins/ircbot/v2/IRCChannel.java | 9 ++++++++- .../plugins/ircbot/v2/IRCConnection.java | 2 +- .../plugins/ircbot/v2/IRCPrivateChat.java | 6 ++++++ .../plugins/ircbot/IrcPublisher/config.jelly | 10 +++++++--- .../plugins/ircbot/IrcPublisher/global.jelly | 12 +++++++++--- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/hudson/plugins/ircbot/IrcPublisher.java b/src/main/java/hudson/plugins/ircbot/IrcPublisher.java index 15d21c6b..3910b502 100644 --- a/src/main/java/hudson/plugins/ircbot/IrcPublisher.java +++ b/src/main/java/hudson/plugins/ircbot/IrcPublisher.java @@ -232,6 +232,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc String[] channelsNames = req.getParameterValues("irc_publisher.channel.name"); String[] channelsPasswords = req.getParameterValues("irc_publisher.channel.password"); + String[] notifyOnlys = req.getParameterValues("irc_publisher.chat.notificationOnly"); List targets = Collections.emptyList(); if (channelsNames != null) { @@ -242,11 +243,10 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc throw new FormException("Channel name must not be empty", "channel.name"); } - if (Util.fixEmpty(channelsPasswords[i]) != null) { - targets.add(new GroupChatIMMessageTarget(channelsNames[i], channelsPasswords[i])); - } else { - targets.add(new GroupChatIMMessageTarget(channelsNames[i])); - } + String password = Util.fixEmpty(channelsPasswords[i]); + boolean notifyOnly = notifyOnlys != null ? "on".equalsIgnoreCase(notifyOnlys[i]) : false; + + targets.add(new GroupChatIMMessageTarget(channelsNames[i], password, notifyOnly)); } } this.defaultTargets = targets; @@ -300,6 +300,7 @@ public String getHelpFile() { public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException { String[] channelsNames = req.getParameterValues("irc_publisher.channel.name"); String[] channelsPasswords = req.getParameterValues("irc_publisher.channel.password"); + String[] notifyOnlys = req.getParameterValues("irc_publisher.chat.notificationOnly"); List targets = Collections.emptyList(); if (channelsNames != null) { @@ -310,11 +311,9 @@ public Publisher newInstance(StaplerRequest req, JSONObject formData) throws For throw new FormException("Channel name must not be empty", "channel.name"); } - if (Util.fixEmpty(channelsNames[i]) != null) { - targets.add(new GroupChatIMMessageTarget(channelsNames[i], channelsPasswords[i])); - } else { - targets.add(new GroupChatIMMessageTarget(channelsNames[i])); - } + String password = Util.fixEmpty(channelsPasswords[i]); + boolean notifyOnly = notifyOnlys != null ? "on".equalsIgnoreCase(notifyOnlys[i]) : false; + targets.add(new GroupChatIMMessageTarget(channelsNames[i], password, notifyOnly)); } } diff --git a/src/main/java/hudson/plugins/ircbot/v2/IRCChannel.java b/src/main/java/hudson/plugins/ircbot/v2/IRCChannel.java index 09369086..713b5119 100644 --- a/src/main/java/hudson/plugins/ircbot/v2/IRCChannel.java +++ b/src/main/java/hudson/plugins/ircbot/v2/IRCChannel.java @@ -14,11 +14,13 @@ public class IRCChannel implements IMChat { private final String channelName; private final PircListener listener; private IRCConnection connection; + private boolean commandsAccepted; - public IRCChannel(String channelName, IRCConnection connection, PircListener listener) { + public IRCChannel(String channelName, IRCConnection connection, PircListener listener, boolean commandsAccepted) { this.channelName = channelName; this.connection = connection; this.listener = listener; + this.commandsAccepted = commandsAccepted; } //@Override @@ -35,6 +37,11 @@ public String getIMId(String senderId) { public boolean isMultiUserChat() { return true; } + + //@Overrid + public boolean isCommandsAccepted() { + return this.commandsAccepted; + } //@Override public void addMessageListener(IMMessageListener listener) { diff --git a/src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java b/src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java index ffdaa90c..d5392ecc 100644 --- a/src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java +++ b/src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java @@ -202,7 +202,7 @@ public void channelJoined(String channelName) { LOGGER.log(Level.INFO, "Joined to channel {0} but I don't seem to belong here", channelName); return; } - Bot bot = new Bot(new IRCChannel(channelName, this, this.listener), + Bot bot = new Bot(new IRCChannel(channelName, this, this.listener, !groupChat.isNotificationOnly()), this.descriptor.getNick(), this.descriptor.getHost(), this.descriptor.getCommandPrefix(), this.authentication); bots.put(channelName, bot); diff --git a/src/main/java/hudson/plugins/ircbot/v2/IRCPrivateChat.java b/src/main/java/hudson/plugins/ircbot/v2/IRCPrivateChat.java index 643b9b0f..7bf98d20 100644 --- a/src/main/java/hudson/plugins/ircbot/v2/IRCPrivateChat.java +++ b/src/main/java/hudson/plugins/ircbot/v2/IRCPrivateChat.java @@ -37,6 +37,12 @@ public String getIMId(String senderId) { public boolean isMultiUserChat() { return false; } + + //@Overrid + public boolean isCommandsAccepted() { + return true; + } + //@Override public void addMessageListener(IMMessageListener listener) { this.listener.addMessageListener(this.nick, this.chatPartner, listener); diff --git a/src/main/resources/hudson/plugins/ircbot/IrcPublisher/config.jelly b/src/main/resources/hudson/plugins/ircbot/IrcPublisher/config.jelly index 47340d92..7eafe4fe 100644 --- a/src/main/resources/hudson/plugins/ircbot/IrcPublisher/config.jelly +++ b/src/main/resources/hudson/plugins/ircbot/IrcPublisher/config.jelly @@ -6,12 +6,16 @@ + + +
NamePasswordNotification only
- - - + + + diff --git a/src/main/resources/hudson/plugins/ircbot/IrcPublisher/global.jelly b/src/main/resources/hudson/plugins/ircbot/IrcPublisher/global.jelly index 23a1b773..0b57ea28 100644 --- a/src/main/resources/hudson/plugins/ircbot/IrcPublisher/global.jelly +++ b/src/main/resources/hudson/plugins/ircbot/IrcPublisher/global.jelly @@ -24,12 +24,18 @@ + +
+
+ +
NamePasswordNotification only
- - - + + +
+