Skip to content

Commit

Permalink
[FIXED JENKINS-11606]: configuration option to disable commands in ch…
Browse files Browse the repository at this point in the history
…at rooms
  • Loading branch information
kutzi committed Nov 6, 2011
1 parent 39853f9 commit ee5e974
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
19 changes: 9 additions & 10 deletions src/main/java/hudson/plugins/ircbot/IrcPublisher.java
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/hudson/plugins/ircbot/v2/IRCChannel.java
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/ircbot/v2/IRCPrivateChat.java
Expand Up @@ -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);
Expand Down
Expand Up @@ -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>
Expand Down
Expand Up @@ -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>
Expand Down

0 comments on commit ee5e974

Please sign in to comment.