-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
68 lines (61 loc) · 1.82 KB
/
cli.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
/**
* USAGE: node chooser.js name1 name2 name3 name4
*
* Will choose a name at random, and repeat until a name
* has been chosen three times, that's the winner
*
* If you add a user named 'nobody' that's treated as
* a special case where nobody wins
**/
const fs = require('fs');
const path = require('path');
const chalk = require("chalk");
const { exec } = require('child_process');
const pathToMedia = path.dirname(fs.realpathSync(__filename)) + '/'
let entrants = process.argv.slice(2);
let winners = {};
let roundCount = 1;
console.log("\n🎲 " + chalk.yellow(" Calculating Winner: First person chosen three times wins!\n"));
exec('afplay ' + pathToMedia + 'fanfare.mp3')
setTimeout(function() {
let games = setInterval(function() {
let omg = "";
const winner = Math.round(Math.random() * (entrants.length - 1));
winners[winner] = winners[winner] ? winners[winner] + 1 : 1;
if (winners[winner] === 2) {
omg = "❗";
if (entrants[winner].toUpperCase() === "NOBODY") {
exec('afplay ' + pathToMedia + 'uhoh.wav')
} else {
exec('afplay ' + pathToMedia + 'ooooh.wav')
}
}
if (winners[winner] === 3) {
omg = "🏅";
}
console.log(
"⭐ Round " +
roundCount +
" won by: " +
chalk.green(entrants[winner].toUpperCase()) +
" | total wins: " +
winners[winner] +
omg +
"\n"
);
roundCount += 1;
if (winners[winner] === 3) {
if (entrants[winner].toUpperCase() === "NOBODY") {
exec('afplay ' + pathToMedia + 'boo.wav')
} else {
exec('afplay ' + pathToMedia + 'yay.wav')
}
console.log(
chalk.bold(
"\n\n 🎉 Winner! 🎉 is " + entrants[winner].toUpperCase()
) + "\n\n"
);
clearInterval(games);
}
}, 2500);
}, 2000);