Nick Changed on Reconnect
Hello! Apologies if this has been brought up, but I couldn't find it in a search.
We're bridging to a channel on Freenode and finding that when the bot loses connection and has to reconnect, it reconnects as <BotNick>1 (since I guess the old nick hasn't been counted as disconnected yet when it comes back). I tried fixing this by adding the following to config.json, but I found that the bot just winds up with <BotNick>2 for some reason:
"autoSendCommands": [
["PRIVMSG", "NickServ", "GHOST <BotNick> <key>"],
["NICK", "<BotNick>"],
["PRIVMSG", "NickServ", "IDENTIFY <key>"]
],
Is there some way to either set up these auto sends or to have the functionality in the bot to deal with this (maybe if your nick != the configured nick, wait a configurable amount of time and try again?)
Another good alternative might be to add a bot command that just issues a nick for the configured nick.
Looking at the code of node-irc it looks like this should be handled already: https://github.com/martynsmith/node-irc/blob/master/lib/irc.js#L230-L237
Maybe this is a non-protocol event though, so it's up to each IRC server how they're handling it?
Ohhh, so the bot is doing the appending of the numbers itself? Does that explain why I'm getting <BotNick>2 the second time? Seems like what might be happening is:
- Connect
- Send normal nick command
- Get nick in use
- Set nickmod to 1
- Retry and succeed
- Do autosendcmd
- Get nick in use (for whatever reason)
- Set nickmod to 2
- Change to <BotNick>2
(I haven't looked at the code around to see if that makes sense)
In that case a solution might be to have some ability to tell the bot to set nickMod to undefined again and retry its nick process, or an ability to tell the autosendcmd to wait some amount of time.
Also, just realized that's an external library, so maybe I'm asking the wrong person for those things haha
It's supposed to append the number to the already existing nick though, not just replace it. See https://github.com/martynsmith/node-irc/blob/master/lib/irc.js#L234
Looks to me like it's appending to self.opt.nick which I think is what's in my config file, not self.nick which is already the existing nick?
It should set self.opt.nick to the correct nick here.
If you're interested in debugging further you could put a few console.logs inside node-irc' code to see what it's actually sending on the specific event.
Should be in node_modules/irc/lib/irc.js if you've cloned the project, or something like /usr/local/lib/node_modules/discord-irc/irc/lib/irc.js if you're running it with the CLI.
Good idea. I modified that block to read:
case 'err_nicknameinuse':
if (typeof (self.opt.nickMod) == 'undefined')
self.opt.nickMod = 0;
self.opt.nickMod++;
console.log("Requested nickname in use. Attempting " + self.opt.nick + self.opt.nickMod);
console.log("self.nick is: " + self.nick);
console.log("self.opt.nick is: " + self.opt.nick);
self.send('NICK', self.opt.nick + self.opt.nickMod);
self.nick = self.opt.nick + self.opt.nickMod;
self._updateMaxLineLength();
console.log("Sent nick change.");
console.log("self.nick is: " + self.nick);
console.log("self.opt.nick is: " + self.opt.nick);
break;
Will report back next time my bot suffers a disconnect