pastebin

Paste #yNB -- näytä pelkkänä tekstinä -- uusi tämän pohjalta

Värjäys: Tyyli: ensimmäinen rivinumero: Tabin korvaus:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var irc = require("irc");
var request = require("request");

function randomRange(min, max) {
    return Math.floor((Math.random() * max) + min);
}

function getRandomPageTitle(cb) {
    var regex = /<title>(.*) – 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);
    }
});