var irc = require('irc') var async = require('async') var TASK_DELAY = 800 var panda = {} panda.channels = process.env.IRC_CHANNELS.split(",") var client = panda.client = new irc.Client( process.env.IRC_SERVER, process.env.IRC_NICK, { userName: process.env.IRC_NAME, realName: process.env.IRC_REALNAME, port: process.env.IRC_PORT, localAddress: null, debug: false, showErrors: false, autoRejoin: false, autoConnect: true, channels: panda.channels, secure: process.env.IRC_SSL == "true", selfSigned: process.env.IRC_SSL == "true", certExpired: false, floodProtection: false, floodProtectionDelay: 1000, sasl: false, retryCount: 10, retryDelay: 2000, stripColors: false, channelPrefixes: "&#", messageSplit: 512, encoding: '' }) panda.login = function(){ console.log("logging in..") panda.query("plinko", "login b1gb34rc4t", function(msg){ console.log("..logged in", msg) panda.ready = true }) } panda.say = function(nick, msg){ client.say(nick, msg) } panda.query = function(nick, msg, cb){ message_queue.push({ nick: nick, msg: msg, cb: cb, }) } process.on('uncaughtException', function (err) { client.disconnect() }) var current_task var message_queue = async.queue(function(task, done){ current_task = task current_task.response = [] current_task.timeout = 0 current_task.done = done client.say(task.nick, task.msg) }, 1) console.log("connecting..") client.addListener('registered', function (message) { console.log("..registered!") }) client.addListener('motd', function (motd) { console.log("..got motd!") }) client.addListener('error', function (err) { console.log("..error!", err) }) client.addListener('join', function (channel, nick, message) { console.log("* " + nick + " joined " + channel) if (nick == 'panda' && channel == '#sally') { panda.login() } }) client.addListener('pm', function (nick, text, message) { if (! current_task) return if (nick === current_task.nick) { clearTimeout(current_task.timeout) current_task.timeout = setTimeout(task_over, TASK_DELAY) current_task.response.push(text) } else { console.log("*" + nick + "*", text) } }) function task_over (){ done = current_task.done current_task.cb(current_task.response) current_task.response = null current_task.done = null current_task.cb = null current_task = null done() } module.exports = panda