var irc = require('irc'); var authnick = 'felixfire619'; // Create the configuration var config = { channels: ["#pandacoinpnd"], server: "irc.freenode.net", botName: "cwibot", password: "xxxxx", }; var recentLotto = {}; var oneHour = 60000 * 60; var fiftyfive = 55000 * 60; // Create the bot name var bot = new irc.Client(config.server, config.botName, { channels: config.channels, autoConnect: true }); bot.addListener('registered', function () { //TODO: update password bot.say('NickServ', 'IDENTIFY ' + config.password); }); // Add user to recentLotto array, wait one hour, then remove from recentLotto array. function userLotto(from, channel) { if (!recentLotto[channel]) recentLotto[channel] = { names: [] }; var names = recentLotto[channel].names; if (names.indexOf(from) > -1) { bot.say(channel, "Sorry " + from + ". You can only use this ONCE per hour :P"); } else { var selection = Math.floor(Math.random() * 8); var resultants = [ 'Reg',//0 'Med',//1 'Big',//2 'Reg',//3 'Reg',//4 'Med',//5 'Reg',//6 'Jackpot',//7 ]; bot.say(channel, from + ': You got... ' + resultants[selection] + '!'); switch (selection) { case 1: bot.say(channel, "!tip " + from + " 100"); names.push(from); setTimeout(function() { names.splice(names.indexOf(from), 1); }, oneHour); break; case 5: bot.say(channel, "!tip " + from + " 100"); names.push(from); setTimeout(function() { names.splice(names.indexOf(from), 1); }, oneHour); break; case 2: bot.say(channel, "!tip " + from + " 1000"); names.push(from); setTimeout(function() { names.splice(names.indexOf(from), 1); }, oneHour); break; case 7: bot.say(channel, "!tip " + from + " 10000"); names.push(from); setTimeout(function() { names.splice(names.indexOf(from), 1); }, oneHour); break; default: bot.say(channel, "!tip " + from + " 10"); names.push(from); setTimeout(function() { names.splice(names.indexOf(from), 1); }, oneHour); break; } return true; } } bot.addListener("notice", function (nick, to, text, message) { console.log(nick + ": " + text); }); bot.addListener('message#', function (from, to, message) { if (message.length < 1 || !(message[0] == '!')) { return; } message = message.slice(1); var params = message.split(/\s/); switch (params[0]) { case 'lotto': console.log(recentLotto + " AND " + channel); userLotto(from, channel); break; case 'cwibal': bot.say(channel, "!balance"); break; case 'join': if (from == authnick) { bot.join(params[1]); break; } } }); bot.addListener('raw', function(message) { console.log('raw: ', message) }); bot.addListener('error', function(message) { console.log(color('error: ', 'red'), message) }); bot.addListener('error', function (err) { console.log('Error:', err); });// JavaScript Document