Here ya go. This is my stripped down code that still has the same issue with doubled up messages:
var net = require('net');
var client = new net.Socket();
client.setEncoding('utf-8');
client.setNoDelay(true);
client.connect(6667, 'irc.twitch.tv', function() {
console.log('Connected');
client.write('PASS pass\r\n');
client.write('NICK nick\r\n');
client.write('CAP REQ :twitch.tv/tags\r\n');
client.write('CAP REQ :twitch.tv/commands\r\n');
client.write('JOIN #SomeBusyTwitchChannel\r\n');
});
client.on('data', function(data) {
if(data.indexOf('PRIVMSG') >= 0 && data.match(/PRIVMSG/g).length > 1) {
console.log(data.match(/PRIVMSG/g).length + ' found! ' + data);
}
if(data.indexOf('PING') >= 0) {
client.write('PONG tmi.twitch.tv\r\n');
}
});
client.on('close', function() {
console.log('Connection closed');
client.destroy();
});
client.on('error', function() {
console.log('Connection error');
});
client.on('end', function() {
console.log('Connection end');
});
client.on('timeout', function() {
console.log('Connection timeout');
});
client.on('drain', function() {
console.log('Connection drain');
});
client.on('lookup', function() {
console.log('Connection lookup');
});