-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (39 loc) · 1.3 KB
/
index.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
const Kahoot = require('kahoot.js-updated')
var express = require('express')
, bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
function createClient(i, name, gamePin) {
try {
var client = new Kahoot;
console.log("Joining kahoot... " + i);
var b = name;
client.join(gamePin, b+i);
client.on("questionStart", question => {
console.log("A new question has started, answering the first answer.");
setTimeout(() => {
question.answer(Math.floor(Math.random()*4));
}, Math.random() * 4)
});
return client;
} catch (e) {}
}
app.get("/", (req, res) => {
res.sendFile(`${__dirname}/kahoot.html`)
})
app.post('/start', (req, res) => {
if (!req.body.gamePin) return res.send("gamePin not defined")
if (!req.body.name) return res.send("name not defined")
if (!req.body.amount) return res.send("amount not defined")
if(!req.body.amount > 1000) return res.send("max 1000 bots")
for (let i=0;i<req.body.amount;i++) {
if(i+1>1000) {
return;
}
setTimeout(() => {
createClient(i+1, req.body.name,req.body.gamePin)
}, (i*200))
}
})
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));