Skip to content

Commit 737dfbf

Browse files
committed
Make the bot able to join password protected channels
1 parent 14538c8 commit 737dfbf

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Changelog
22
This project adheres to [Semantic Versioning](http://semver.org/).
33

4+
## [3.1.0] - 2015-03-27
5+
### Added
6+
- Make the bot able to join password protected IRC channels. Example:
7+
8+
```json
9+
"channelMapping": {
10+
"#slack": "#irc channel-password",
11+
}
12+
```
13+
414
## [3.0.0] - 2015-03-24
515
### Changed
616
Move from using outgoing/incoming integrations to Slack's

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ if the IRC channels are on different networks.
3737

3838
To set the log level to debug, export the environment variable `NODE_ENV` as `development`.
3939

40+
slack-irc also supports invite-only IRC channels, and will join any channels it's invited to
41+
as long as they're present in the channel mapping.
42+
4043
Example configuration:
4144
```js
4245
[
@@ -49,7 +52,7 @@ Example configuration:
4952
["AUTH", "test", "password"]
5053
],
5154
"channelMapping": { // Maps each Slack-channel to an IRC-channel, used to direct messages to the correct place
52-
"#slack": "#irc",
55+
"#slack": "#irc channel-password", // Add channel keys after the channel name
5356
"privategroup": "#other-channel" // No hash in front of private groups
5457
}
5558
},

lib/bot.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ function Bot(options) {
2323

2424
this.server = options.server;
2525
this.nickname = options.nickname;
26-
this.channelMapping = validateChannelMapping(options.channelMapping);
26+
this.channels = _.values(options.channelMapping);
27+
28+
this.channelMapping = {};
29+
30+
// Remove channel passwords from the mapping
31+
_.forOwn(options.channelMapping, function(ircChan, slackChan) {
32+
this.channelMapping[slackChan] = ircChan.split(' ')[0];
33+
}, this);
34+
2735
this.invertedMapping = _.invert(this.channelMapping);
28-
this.channels = _.values(this.channelMapping);
36+
2937
this.autoSendCommands = options.autoSendCommands || [];
3038
}
3139

@@ -37,7 +45,6 @@ Bot.prototype.connect = function() {
3745
realName: this.nickname,
3846
channels: this.channels
3947
});
40-
4148
this.attachListeners();
4249
};
4350

@@ -116,6 +123,8 @@ Bot.prototype.sendToIRC = function(message) {
116123

117124
var channelName = channel.is_channel ? '#' + channel.name : channel.name;
118125
var ircChannel = this.channelMapping[channelName];
126+
127+
logger.debug('chan', channelName, this.channelMapping[channelName]);
119128
if (ircChannel) {
120129
var user = this.slack.getUserByID(message.user);
121130
var text = '<' + user.name + '> ' + this.parseText(message.getBody());
@@ -141,7 +150,7 @@ Bot.prototype.sendToSlack = function(author, channel, text) {
141150
parse: 'full',
142151
icon_url: 'http://api.adorable.io/avatars/48/' + author + '.png'
143152
};
144-
logger.debug('Sending message to Slack', message);
153+
logger.debug('Sending message to Slack', message, channel, '->', slackChannelName);
145154
slackChannel.postMessage(message);
146155
}
147156
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "slack-irc",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "Connects IRC and Slack channels by sending messages back and forth.",
55
"keywords": [
66
"slack",

test/bot.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Bot', function() {
3939
icon_url: 'http://api.adorable.io/avatars/48/testuser.png'
4040
};
4141

42-
this.bot.sendToSlack(message.username, config.channelMapping['#slack'], message.text);
42+
this.bot.sendToSlack(message.username, '#irc', message.text);
4343
ChannelStub.prototype.postMessage.should.have.been.calledWith(message);
4444
});
4545

test/channel-mapping.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
var chai = require('chai');
2+
var rewire = require('rewire');
3+
var irc = require('irc');
24
var ConfigurationError = require('../lib/errors').ConfigurationError;
35
var validateChannelMapping = require('../lib/validators').validateChannelMapping;
6+
var Bot = rewire('../lib/bot');
7+
var config = require('./fixtures/single-test-config.json');
8+
var SlackStub = require('./stubs/slack-stub');
9+
var ClientStub = require('./stubs/irc-client-stub');
10+
411
chai.should();
512

613
describe('Channel Mapping', function() {
14+
before(function() {
15+
irc.Client = ClientStub;
16+
Bot.__set__('Slack', SlackStub);
17+
});
18+
719
it('should fail when not given proper JSON', function() {
820
var wrongMapping = 'not json';
921
function wrap() {
@@ -19,4 +31,11 @@ describe('Channel Mapping', function() {
1931
}
2032
(wrap).should.not.throw();
2133
});
34+
35+
it('should clear channel keys from the mapping', function() {
36+
var bot = new Bot(config);
37+
bot.channelMapping['#slack'].should.equal('#irc');
38+
bot.invertedMapping['#irc'].should.equal('#slack');
39+
bot.channels[0].should.equal('#irc channelKey');
40+
});
2241
});

test/fixtures/single-test-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
["AUTH", "test", "password"]
88
],
99
"channelMapping": {
10-
"#slack": "#irc"
10+
"#slack": "#irc channelKey"
1111
}
1212
}

0 commit comments

Comments
 (0)