Skip to content

Commit

Permalink
Add onNickConflict to Client.opts
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Aug 17, 2015
1 parent 45291af commit 627625b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `[email protected]` 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.
14 changes: 9 additions & 5 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 627625b

Please sign in to comment.