var irc = require("irc"); var request = require("request"); function randomRange(min, max) { return Math.floor((Math.random() * max) + min); } function getRandomPageTitle(cb) { var regex = /(.*) – Wikipedia<\/title>/; request("http://fi.wikipedia.org/wiki/Toiminnot:Satunnainen_sivu", function(error, response, body) { if(!error && response.statusCode == 200) { cb(body.match(regex)[1]); } else { cb("ovi"); } }); } var config = { channels: ["#ohjelmointiputka"], server: "irc.cc.tut.fi", botName: "latzi", userName: "ovi", realName: "Paskabotti (ei oikea Latska)" }; var minInterval = 1; var maxInterval = 30; var msgCount = 0; var interval = randomRange(minInterval, maxInterval); var bot = new irc.Client(config.server, config.botName, { userName: config.userName, realName: config.realName, channels: config.channels }); bot.addListener("raw", function(rawMessage) { console.log(rawMessage.command); }); bot.addListener("message", function(from, to, text, message) { msgCount++; if (msgCount == interval) { msgCount = 0; interval = randomRange(minInterval, maxInterval); var sayItLoud = function(title) { var msg; if (randomRange(0, 6) > 2) { msg = (title + " :l").toLowerCase(); } else { msg = title.toLowerCase(); } bot.say(config.channels[0], msg); } getRandomPageTitle(sayItLoud); } });