From b94f71465252a3c63f3c4c8ac2c2e8ae34f2cce4 Mon Sep 17 00:00:00 2001 From: Szymon Pilkowski Date: Fri, 7 Mar 2014 01:55:56 +0100 Subject: [PATCH] alternateNick support, ERR_NICKNAMEINUSE handling, nick suffixing --- examples/simple.js | 1 + lib/ircb.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/examples/simple.js b/examples/simple.js index 76abb5c..e7c717c 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -6,6 +6,7 @@ var irc = ircb({ username: 'mycoolbot', realName: 'mycoolbot', nick: 'mycoolbot', + alternateNick: 'mycoolerbot', channels: ['#node.js'] }, function () { irc.on('names', function (channel, names) { diff --git a/lib/ircb.js b/lib/ircb.js index 72cf54f..4edad1a 100644 --- a/lib/ircb.js +++ b/lib/ircb.js @@ -24,6 +24,7 @@ var IRCb = function (options, cb) { self.rejectUnauthorized = !!options.rejectUnauthorized; self.port = options.port || (self.secure ? 6697 : 6667); self.nick = options.nick; + self.alternateNick = options.alternateNick; self.password = options.password; self.channels = []; @@ -158,9 +159,23 @@ IRCb.prototype._processMessage = function (message) { delete this._namesReplies[channel]; } break; + + case "ERR_NICKNAMEINUSE": + var newNick; + if (this.nick == message.middle[1] && this.alternateNick) { + newNick = this.alternateNick; + } else { + newNick = this._suffixNick(message.middle[1]); + } + this.nick_(newNick); + break; } }; +IRCb.prototype._suffixNick = function(baseNick) { + return baseNick + "_"; +}; + IRCb.prototype.pass = function (pass, cb) { this.write('PASS ' + pass, cb); };