node-irc icon indicating copy to clipboard operation
node-irc copied to clipboard

Trying to send a quit message does not work

Open paladox opened this issue 9 years ago • 12 comments

Hi, when we do ircClient.send('QUIT', "example"); it dosent send the quit message instead it sends the default Quit.

See source code at https://phabricator.wikimedia.org/diffusion/1982/browse/master/src/relay.js;8f31f69ddc5f9983fdb92cb90e754b408e75ede8$196 please.

paladox avatar Nov 24 '16 08:11 paladox

it seems because of .send is set out like

Client.prototype.send = function(command) { var args = Array.prototype.slice.call(arguments);

// Note that the command arg is included in the args array as the first element

if (args[args.length - 1].match(/\s/) || args[args.length - 1].match(/^:/) || args[args.length - 1] === '') {
    args[args.length - 1] = ':' + args[args.length - 1];
}

if (this.opt.debug)
    util.log('SEND: ' + args.join(' '));

if (!this.conn.requestedDisconnect) {
    this.conn.write(args.join(' ') + '\r\n');
}

}; so it only gets the command and not the message.

paladox avatar Nov 24 '16 22:11 paladox

@jirwin hi would you know why the quit message is not being sent please? I have flood protection on, but I switched t off to see if that fixes it but it dosent.

paladox avatar Nov 25 '16 09:11 paladox

@paladox you can pass a message to the client.disconnect(msg, callback) function to quit with custom message. That said, sending quit manually should probably work, so I'll look into that.

jirwin avatar Nov 25 '16 21:11 jirwin

@jirwin thanks, but even calling disconnect does not work, it sends the default quit msg. Also disconnect disconnects everything before it has a chance to process the other code before it.

paladox avatar Nov 25 '16 21:11 paladox

@paladox can you put together a test case that shows this? In my testing, disconnect(msg) and send('QUIT', msg) both appear to work.

jirwin avatar Nov 25 '16 21:11 jirwin

@jirwin the test case is I used https://phabricator.wikimedia.org/diffusion/1982/repository/master/

I entered in the correct details (that project is for gerrit)

I then node src/relay.js

I then go to irc and to the channel where the bot joined, I then <bot_nick>: force-restart

it should then disconnect ssh and quit irc and then rejoins.

But this should still work as long as the ssh key is valid even if you haven't setup gerrit.

https://phabricator.wikimedia.org/T151508

paladox avatar Nov 25 '16 21:11 paladox

@paladox interesting. I've added a test case(https://github.com/martynsmith/node-irc/blob/master/test/test-quit.js) that verifies that the disconnect message is properly sent. Maybe this is a quirk with the irc server?

Also, if you are trying to restart the irc client you'll want to call disconnect because it does some clean up logic and actually terminates the irc connection properly.

jirwin avatar Nov 26 '16 00:11 jirwin

Oh.

paladox avatar Nov 26 '16 00:11 paladox

@jirwin All the source code for the bot is at https://phabricator.wikimedia.org/diffusion/1982/browse/master/

https://phabricator.wikimedia.org/diffusion/1982/browse/master/src/relay.js;8f31f69ddc5f9983fdb92cb90e754b408e75ede8$196

I can change it to disconnect, but I want to get the quit message working first.

paladox avatar Nov 26 '16 00:11 paladox

This is how I set it up

https://phabricator.wikimedia.org/diffusion/1982/browse/master/config.yaml;8f31f69ddc5f9983fdb92cb90e754b408e75ede8$2

https://phabricator.wikimedia.org/diffusion/1982/browse/master/src/relay.js;8f31f69ddc5f9983fdb92cb90e754b408e75ede8$111

(config)

paladox avatar Nov 26 '16 00:11 paladox

@jirwin hi trying to use the disconnect code, when I disconnect the bot and use the connect one to rejoin it causes the nick to change to have a number like for example grrrit-wm-test1 instead of grrrit-test-wm.

It seems that it keeps connecting twice. so you have two bots.

paladox avatar Nov 27 '16 21:11 paladox

It seems the quit message will only work if you are registered on irc.

paladox avatar Nov 27 '16 21:11 paladox