From 2a1c5755fc76e5b660d8d608b15a4e9fb9bf7d56 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 14 Nov 2016 13:24:59 -0500 Subject: logging into plinko --- lib/panda.js | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/panda.js (limited to 'lib/panda.js') diff --git a/lib/panda.js b/lib/panda.js new file mode 100644 index 0000000..906aeb5 --- /dev/null +++ b/lib/panda.js @@ -0,0 +1,94 @@ + +var irc = require('irc') +var async = require('async') + +var TASK_DELAY = 800 + +var panda = {} + +var client = panda.client = new irc.Client( 'irc.jollo.org', process.env.IRC_NICK, { + userName: process.env.IRC_NAME, + realName: process.env.IRC_REALNAME, + port: 9999, + localAddress: null, + debug: false, + showErrors: false, + autoRejoin: false, + autoConnect: true, + channels: ["#sally"], + secure: true, + selfSigned: true, + certExpired: false, + floodProtection: false, + floodProtectionDelay: 1000, + sasl: false, + retryCount: 10, + retryDelay: 2000, + stripColors: false, + channelPrefixes: "&#", + messageSplit: 512, + encoding: '' +}) + +panda.query = function(msg, cb){ + message_queue.push({ + 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("plinko", 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') { + console.log("logging in..") + panda.query("login b1gb34rc4t", function(msg){ + console.log("..logged in", msg) + panda.ready = true + }) + } +}) +client.addListener('pm', function (nick, text, message) { + if (! current_task) return + if (nick === "plinko") { + clearTimeout(current_task.timeout) + current_task.timeout = setTimeout(task_over, TASK_DELAY) + current_task.response.push(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 -- cgit v1.2.3-70-g09d2