Skip to content

Commit

Permalink
Merge pull request #6 from askeing/disallowPrivateChatCommands
Browse files Browse the repository at this point in the history
[JENKINS-17419] Added new configuration option to disallow bot commands from private chat.
  • Loading branch information
kutzi committed May 21, 2013
2 parents 323ab68 + b1c06df commit 1514125
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/hudson/plugins/ircbot/IrcPublisher.java
Expand Up @@ -168,6 +168,8 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>

private boolean ssl;

private boolean disallowPrivateChat;

private String login = "PircBotx";

String password = null;
Expand Down Expand Up @@ -274,6 +276,8 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
this.commandPrefix = req.getParameter("irc_publisher.commandPrefix");
this.commandPrefix = Util.fixEmptyAndTrim(commandPrefix);

this.disallowPrivateChat = "on".equals(req.getParameter("irc_publisher.disallowPrivateChat"));

String[] channelsNames = req.getParameterValues("irc_publisher.channel.name");
String[] channelsPasswords = req.getParameterValues("irc_publisher.channel.password");
// only checked state can be queried, unchecked state are ignored and the size of
Expand Down Expand Up @@ -461,6 +465,10 @@ public int getPort() {
public boolean isSsl() {
return this.ssl;
}

public boolean isDisallowPrivateChat() {
return this.disallowPrivateChat;
}

//@Override
public boolean isEnabled() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java
Expand Up @@ -306,6 +306,11 @@ private class ChatEstablishedListener implements IMMessageListener {

//@Override
public void onMessage(IMMessage message) {
if(descriptor.isDisallowPrivateChat()) {
// ignore private chat, if disallow private chat commands.
return;
}

if(!message.getTo().equals(descriptor.getNick())) {
throw new IllegalStateException("Intercepted message to '" + message.getTo()
+ "'. That shouldn't happen!");
Expand Down
Expand Up @@ -63,7 +63,9 @@
help="/plugin/ircbot/help-globalConfigCommandPrefix.html">
<f:textbox name="irc_publisher.commandPrefix" value="${descriptor.getCommandPrefix()}" />
</f:entry>

<f:entry title="Disallow Private Chat" description="Disallow bot commands from private chat.">
<f:checkbox name="irc_publisher.disallowPrivateChat" checked="${descriptor.disallowPrivateChat}"/>
</f:entry>
<super:global-jenkinsLogin />

<f:entry title="Notification charset" description="The character set to use for notifications">
Expand Down

0 comments on commit 1514125

Please sign in to comment.