From a308fa2251c24cb1397b962981d07ca35934650b Mon Sep 17 00:00:00 2001 From: ekmartin Date: Fri, 3 Apr 2015 21:53:56 +0200 Subject: [PATCH] Make it possible to pass node-irc options directly and turn on flood protection --- CHANGELOG.md | 6 ++++++ README.md | 15 ++++++++++++--- lib/bot.js | 13 ++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f71833f..7a05a4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/README.md b/README.md index f738d43..8d56157 100644 --- a/README.md +++ b/README.md @@ -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", @@ -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 diff --git a/lib/bot.js b/lib/bot.js index 60a06d2..01e3c6d 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -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 = {}; @@ -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(); };