-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (59 loc) · 1.59 KB
/
app.js
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
63
64
65
66
67
68
69
70
71
72
var config = {
channels: ["#pcper"],
server: "irc.mibbit.net",
botName: "pcperbot"
};
var irc = require('irc');
var express = require('express');
var path = require('path');
var app = express();
app.locals.started = false;
var msg = '';
var hour = 3600000;
var day = (hour * 24);
var week = (day * 7);
var month = (day * 30);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public'), { maxAge: week }));
app.use(express.bodyParser());
app.get('/', function(req,res) {
res.render('index');
});
app.post('/bot', function(req, res) {
console.log(req.body);
if(app.locals.started == true) {
bot.disconnect();
bot = {};
app.locals.started = false;
res.send({selected: getRandomUser(), first: contestants[0]});
contestants = [];
} else {
res.send(200);
bot = new irc.Client(req.body.server, req.body.name,{
channels: [req.body.channel]
});
bot.addListener("message", function(from, to, text, message) {
console.log('new message');
if(text.toUpperCase() == req.body.targetString.toUpperCase() && contestants.indexOf(message.nick) == -1) {
console.log('added');
contestants.push(message.nick);
}
});
app.locals.started = true
}
});
var contestants = [];
var getRandomUser = function() {
console.log('random called');
return contestants[Math.floor(((Math.random() * 1000000) % contestants.length))];
};
/*
process.on('SIGINT', function(code) {
// do *NOT* do this
console.log(getRandomUser());
setTimeout(function() {
process.exit(1);
}, 200);
});*/
app.listen(3500);