-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 1.01 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
const chalk = require('chalk');
const Kahoot = require('./Kahoot');
function createUser(username, id) {
const user = new Kahoot(`${username}`, id);
user.on('connected', () => {
console.log(`${chalk.green(`[${username}]`)}: Connected`);
});
user.on('question', ({ question, answers }) => {
const answer = Math.floor(Math.random() * answers);
console.log(`${chalk.green(`[${username}]`)}: Question ${chalk.yellow(question)} -> Answer ${chalk.yellow(answer)}`);
user.submitAnswer(question, answer);
});
user.join(id);
}
function start() {
const id = process.argv[2];
const name = process.argv[3];
const count = process.argv[4];
console.log(`${chalk.cyan(`Creating ${count} bots with username ${name}`)}`);
for (let i = 0; i < count; i += 1) {
setTimeout(() => createUser(`${name}${i}`, id), i * 100);
}
}
if (process.argv.length !== 5) {
console.log('Usage: node index [kahoot id] [username] [bot count]');
console.log('Example: node index 3601797 george 25');
} else {
start();
}