Skip to content
Permalink
Browse files
[FIXED JENKINS-11606]: configuration option to disable commands in ch…
…at rooms
  • Loading branch information
kutzi committed Nov 6, 2011
1 parent 39853f9 commit ee5e974566395c01da714bec39e64ce515124b87
@@ -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<IMMessageTarget> 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<IMMessageTarget> 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));
}
}

@@ -14,11 +14,13 @@
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

This comment has been minimized.

Copy link
@bjori

bjori Nov 7, 2011

typo :)
Same in src/main/java/hudson/plugins/ircbot/v2/IRCPrivateChat.java little further below

public boolean isCommandsAccepted() {
return this.commandsAccepted;
}

//@Override
public void addMessageListener(IMMessageListener listener) {
@@ -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);
@@ -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);
@@ -6,12 +6,16 @@
<f:advanced>
<f:entry title="Channels" description="Name/password pairs of IRC channels (Password is optional)"
help="/plugin/ircbot/help-instanceConfigChannels.html">
<table width="100%">
<tr style="text-align:left"><th width="30%">Name</th><th width="30%">Password</th><th width="10%">Notification only</th><th width="30%"/></tr>
</table>
<f:repeatable name="irc_publisher.channels" var="ch" items="${instance.notificationTargets}">
<table width="100%">
<tr>
<td><input type="text" width="100%" style="text-align:left" name="irc_publisher.channel.name" value="${ch.name}" /></td>
<td><input type="password" width="100%" style="text-align:left" name="irc_publisher.channel.password" value="${ch.password}" /></td>
<td>
<td width="30%"><input type="text" width="100%" style="text-align:left" name="irc_publisher.channel.name" value="${ch.name}" /></td>
<td width="30%"><input type="password" width="100%" style="text-align:left" name="irc_publisher.channel.password" value="${ch.password}" /></td>
<td width="10%"><f:checkbox name="irc_publisher.chat.notificationOnly" checked="${ch.notificationOnly}"/></td>
<td width="30%">
<div align="right"><f:repeatableDeleteButton /></div>
</td>
</tr>
@@ -24,12 +24,18 @@
<f:entry title="Channels"
description="Channels the bot should join"
help="/plugin/ircbot/help-globalConfigChannels.html">
<!-- Note that this strange separation of the table headers into a separate table is done one purpose. I didn't find another way
without breaking the rendering of the whole config page! -->
<table width="100%">
<tr style="text-align:left"><th width="30%">Name</th><th width="30%">Password</th><th width="10%">Notification only</th><th width="30%"/></tr>
</table>
<f:repeatable name="irc_publisher.channels" var="ch" items="${descriptor.defaultTargets}">
<table width="100%">
<tr>
<td><input type="text" width="100%" style="text-align:left" name="irc_publisher.channel.name" value="${ch.name}" /></td>
<td><input type="password" width="100%" style="text-align:left" name="irc_publisher.channel.password" value="${ch.password}" /></td>
<td>
<td width="30%"><input type="text" width="100%" style="text-align:left" name="irc_publisher.channel.name" value="${ch.name}" /></td>
<td width="30%"><input type="password" width="100%" style="text-align:left" name="irc_publisher.channel.password" value="${ch.password}" /></td>
<td width="10%"><f:checkbox name="irc_publisher.chat.notificationOnly" checked="${ch.notificationOnly}"/></td>
<td width="30%">
<div align="right"><f:repeatableDeleteButton /></div>
</td>
</tr>

0 comments on commit ee5e974

Please sign in to comment.