-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
125 lines (119 loc) · 3.54 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const Discord = require("discord.js");
const { creatorId, prefix, token, rounds } = require("./config.json");
const client = new Discord.Client();
let buzzed = false;
let buzzedUser = null;
let currentRound = "";
let indexRound = 0;
let voiceConnection = null;
let dispatcher = null;
let started = false;
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("message", (msg) => {
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();
if (msg.author.id === creatorId && command === "start") {
buzzed = false;
started = false;
msg.member.voice.channel
.join()
.then((connection) => (voiceConnection = connection));
muteAll(msg.member.voice.channel);
msg.channel.send("The blind test is starting !");
}
if (started && !buzzed && (command == "buzz" || command == "b")) {
buzzed = true;
buzzedUser = msg.member;
dispatcher.pause();
msg.channel.send(`<@${buzzedUser.id}> it's your turn`);
msg.member.voice.setMute(false);
}
if (started && buzzed && msg.author.id == creatorId && command == "t") {
buzzed = false;
buzzedUser.voice.setMute(true);
}
if (started && buzzed && msg.author.id == creatorId && command == "f") {
buzzed = false;
buzzedUser.voice.setMute(true);
dispatcher.resume();
}
if (started && msg.author.id == creatorId && command == "n") {
buzzed = false;
dispatcher.pause();
buzzed = false;
if (indexRound < rounds[currentRound].length - 1) {
indexRound++;
dispatcher = voiceConnection.play(rounds[currentRound][indexRound]);
} else {
msg.channel.send("It's the end of the round");
started = false;
}
}
if (started && msg.author.id == creatorId && command == "pause") {
started = false;
buzzed = true;
if (dispatcher != null && !dispatcher.paused) dispatcher.pause();
msg.channel.send("Pause the blind test !");
unmuteAll(msg.member.voice.channel);
}
if (
!started &&
dispatcher != null &&
dispatcher.paused &&
msg.author.id == creatorId &&
command == "resume"
) {
started = true;
buzzed = false;
dispatcher.resume();
msg.channel.send("Resume !");
muteAll(msg.member.voice.channel);
}
if (!started && msg.author.id == creatorId && command == "play") {
buzzed = false;
started = true;
indexRound = 0;
currentRound = args[0];
dispatcher = voiceConnection.play(rounds[currentRound][indexRound]);
msg.channel.send("The round is starting !");
}
if (msg.author.id == creatorId && command == "stop") {
buzzed = false;
started = false;
msg.channel.send("End of the blind test !");
msg.member.voice.channel.leave();
unmuteAll(msg.member.voice.channel);
}
if (msg.author.id == creatorId && command == "m") {
buzzed = true;
dispatcher.pause();
}
if (msg.author.id == creatorId && command == "r") {
buzzed = false;
dispatcher.resume();
}
msg.delete();
});
function muteAll(voiceChannel) {
voiceChannel.members.forEach((member) => {
try {
if (member.id != creatorId && !member.user.bot)
member.voice.setMute(true);
} catch (e) {
console.log("Problem with ", member.username);
}
});
}
function unmuteAll(voiceChannel) {
voiceChannel.members.forEach((member) => {
try {
if (member.id != creatorId) member.voice.setMute(false);
} catch (e) {
console.log("Problem with ", member.username);
}
});
}
client.login(token);