Skip to content

Commit

Permalink
Make it possible to pass node-irc options directly and turn on flood …
Browse files Browse the repository at this point in the history
…protection
  • Loading branch information
ekmartin committed Apr 4, 2015
1 parent 336aafb commit a308fa2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.2.0] - 2015-04-03
### Added
- Support for passing [node-irc](http://node-irc.readthedocs.org/en/latest/API.html#irc.Client)
options directly by adding an `ircOptions` object to the config. Also sets `floodProtection` on
by default, with a delay of 500 ms.

## [3.1.0] - 2015-03-27
### Added
- Make the bot able to join password protected IRC channels. Example:
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,27 @@ as long as they're present in the channel mapping.
Example configuration:
```js
[
// Bot 1:
{
"nickname": "test",
"server": "irc.bottest.org",
"token": "slacktoken", // Your bot user's token
"autoSendCommands": [ // Commands that will be sent on connect
["PRIVMSG", "NickServ", "IDENTIFY password"],
["MODE", "test", "+x"],
["AUTH", "test", "password"]
["PRIVMSG", "NickServ", "IDENTIFY password"],
["MODE", "test", "+x"],
["AUTH", "test", "password"]
],
"channelMapping": { // Maps each Slack-channel to an IRC-channel, used to direct messages to the correct place
"#slack": "#irc channel-password", // Add channel keys after the channel name
"privategroup": "#other-channel" // No hash in front of private groups
},
"ircOptions": { // Optional node-irc options
"floodProtection": false, // On by default
"floodProtectionDelay": 1000 // 500 by default
}
},

// Bot 2:
{
"nickname": "test2",
"server": "irc.testbot.org",
Expand All @@ -68,6 +75,8 @@ Example configuration:
]
```

`ircOptions` is passed directly to node-irc ([available options](http://node-irc.readthedocs.org/en/latest/API.html#irc.Client)).

## Tests
Run the tests with:
```bash
Expand Down
13 changes: 10 additions & 3 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function Bot(options) {

this.server = options.server;
this.nickname = options.nickname;
this.ircOptions = options.ircOptions;

this.channels = _.values(options.channelMapping);

this.channelMapping = {};
Expand All @@ -40,11 +42,16 @@ function Bot(options) {
Bot.prototype.connect = function() {
logger.debug('Connecting to IRC and Slack');
this.slack.login();
this.ircClient = new irc.Client(this.server, this.nickname, {

var ircOptions = _.assign({
userName: this.nickname,
realName: this.nickname,
channels: this.channels
});
channels: this.channels,
floodProtection: true,
floodProtectionDelay: 500
}, this.ircOptions);

this.ircClient = new irc.Client(this.server, this.nickname, ircOptions);
this.attachListeners();
};

Expand Down

0 comments on commit a308fa2

Please sign in to comment.