diff --git a/README.md b/README.md index 523f9c89..b9e8c31e 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,4 @@ You can access more detailed documentation for this module at [Read the Docs](ht The `node-irc` library isn't well maintained and there are a number of issues which are impacting development of the [Matrix-IRC application service](http://github.com/matrix-org/matrix-appservice-irc). We made the decision to fork the project in order to improve reliability of the application service. A summary of modifications from `node-irc@0.3.12` are below: - https://github.com/matrix-org/node-irc/pull/1 - Manifested as [BOTS-80](https://matrix.org/jira/browse/BOTS-80) - https://github.com/matrix-org/node-irc/pull/4 - Manifested as [BOTS-73] (https://matrix.org/jira/browse/BOTS-73) + - Addition of `onNickConflict()` option which is called on `err_nicknameinuse`. This function should return the next nick to try. Defaults to suffixing monotonically increasing integers. diff --git a/lib/irc.js b/lib/irc.js index 69d4c6b3..6d45847a 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -57,6 +57,12 @@ function Client(server, nick, opt) { channelPrefixes: '&#', messageSplit: 512, encoding: false, + onNickConflict: function() { + if (typeof (self.opt.nickMod) == 'undefined') + self.opt.nickMod = 0; + self.opt.nickMod++; + return self.opt.nick + self.opt.nickMod; + }, webirc: { pass: '', ip: '', @@ -228,11 +234,9 @@ function Client(server, nick, opt) { // Random welcome crap, ignoring break; case 'err_nicknameinuse': - if (typeof (self.opt.nickMod) == 'undefined') - self.opt.nickMod = 0; - self.opt.nickMod++; - self.send('NICK', self.opt.nick + self.opt.nickMod); - self.nick = self.opt.nick + self.opt.nickMod; + var nextNick = self.opt.onNickConflict(); + self.send('NICK', nextNick); + self.nick = nextNick; self._updateMaxLineLength(); break; case 'PING':