How do I ping/pong with a Node JS Bot?

Alright I do apologize because I realize this is such a simple seeming question but its actually driving me quite crazy… I am using https://github.com/martynsmith/node-irc module to manage the IRC Connection to twitch, and it’s going really well! I have a lot of complex things such as a quote bot, adding quotes to a database and all sorts of various “complex” things, everything works in the bot perfectly as it should…

But the one problem I have is I cannot for the life of me figure out how the ping/pong system works, I know the node-irc has this https://node-irc.readthedocs.org/en/latest/API.html#‘ping’ but I am at a loss as to how to make it work with twitch and the time between the bot finally disconnecting and me being able to test whether my ping code actually works seems to last for hours so it’s really hard to test if I got the right code…

Is this basically what I would want to do? Like on ping have the bot say this message?

bot.addListener('ping', function(server){
bot.say(server, "PONG tmi.twitch.tv\r\n");
});

Or do I have it send a raw message somewhere or am I sending it to the wrong channel or what am I doing wrong? I am struggling way too hard with this lol and I hope it’s not staring me right in the face but thank you a lot for your help and I do apologize if this is a stupid question or in the wrong place.

The node-irc module already handles replying to PINGs.

Twitch will disconnect you in about 10 minutes if you’re not sending PONGs appropriately.

I see, so if I understand correctly do I just need to make sure I send a message saying pong every 10 minutes or something? How do I appropriately send a pong? I am trying this new way where i just send “PONG” like this but i’m not suite sure this would work.

bot.addListener('raw', function(message){
switch ( message.command ) {
    case "PING":
        bot.send("PONG", message.args[0]);
        bot.emit('ping', message.args[0]);
        break;
}

});

I feel like that may be a bit useless now though since I could maybe use the ping event listener, I am not sure I am fairly lost when it comes to this ping/pong thing which is why I posted here lol, once again sorry if I am missing something completely obvious. Is there any way to know if the ping/pong was a success so I can know immediately if my code is working or what would you suggest I do to pong appropriately?

Also thank you sincerely for any help you can give, it is really appreciated!

Edit: actually i seem to be finding reports that the pong should be structured as such

bot.send("PONG tmi.twitch.tv", message.args[0]);

with the tmi.twitch.tv at the end, but I am not positive. is that required?

That is what the module already does. You do not need to handle it in your code while using node-irc.

Ooh alright thank you very much! Do you have any idea why it seems a few hours down the line maybe even a day later the bot seems to randomly disconnect/stop picking up chat for some reason? Is there any failsafe you think I could add in to prevent that? I used to assume it was ping/pong but I suppose it probably isn’t if it already captures that.

Thanks once again.

Add a listener for the 'close' event and reconnect when it’s fired. The disconnects could be caused by a lot of things, but as long as you’re replying to PINGs (which the module is) and staying below 20 messages in 30 seconds (or 100 messages on channels where the bot has moderator status), it’s not your fault. Setting floodProtectionDelay to 1500 will satisfy the lower limit.

The best, and easiest method, would be to use tmi.js, which uses the websockets interface, and handles pretty much everything you could ever need. It correctly parses usernames, works with whispers, and much more, all in a friendly and easy to understand manner.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.