-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
225 lines (181 loc) · 7.04 KB
/
Copy pathindex.js
File metadata and controls
225 lines (181 loc) · 7.04 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
const Discord = require('discord.js');
require('dotenv').config();
const client = new Discord.Client();
const token = process.env.BOT_TOKEN;
let players = [];
let extraRoles = {blue: [], red: [], grey: []};
let numRoles = 0;
let timeout = false;
let timer = 3;
let seconds = 0;
let int = null;
let ingame = false;
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function printPlayers(){
return players.map(player => ' - <@' + player.id + '>\n').join('')
}
function printRoles(){
let roles = '';
roles += 'Blue:\n' + extraRoles.blue.map(role => ' - ' + role + '\n').join('');
roles += 'Red:\n' + extraRoles.red.map(role => ' - ' + role + '\n').join('');
roles += 'Grey:\n' + extraRoles.grey.map(role => ' - ' + role + '\n').join('');
return roles;
}
function sendRoles() {
//send roles to players
let characters = Array.from(players);
shuffle(characters);
characters.pop().send('You are the President! You are on the blue team. Don\'t get placed in the same room as the bomber!');
characters.pop().send('You are the Bomber! You are on the red team. KILL THE PRESIDENT!');
if(characters.length % 2 != 0) {
characters.pop().send('You are the Gambler! At the end of the 3 rounds, try to guess which team won!');
}
Object.keys(extraRoles).forEach(color => {
extraRoles[color].forEach(role => {
characters.pop().send(`You are on the ${color} team! You have the role of ${role}.`);
})
})
color = true;
if(characters !== undefined){
characters.forEach(character => {
character.send(`You are on the ${color ? 'blue' : 'red'} team! You have no special role.`);
color = !color;
})
}
}
client.on('ready', () => {
console.log('Bot is online!');
})
client.on('message', (msg)=>{
if(msg.content === '!help'){
msg.channel.send('Hello degenerates! I am a Discord bot that can help faciliate the game of 2 Rooms and Boom. Here are a list of my commands: \n' +
'!join - join the Queue for the game\n' +
'!leave - leave the Queue for the game\n' +
'!queue - check who is in the Queue\n' +
'!refresh - refreshes the Queue\n' +
'!startgame - starts the game. Only works when there are 6 players!\n' +
'!timer - there are 3 timers. Starts the countdown for the current timer\n' +
'!endgame - ends the current game. Restarts the timers.'
);
}
if(msg.content === '!sendnudes'){
msg.reply('B-..Ba-...Baa-...Baaka! Hentai! Don\'t do me dirty like that senpai!');
}
//commands for if the game hasn't started yet
if(!ingame){
if(msg.content === '!join'){
let index = players.indexOf(msg.author);
//comment this out to test
if(index == -1){
players.push(msg.author);
}
msg.channel.send('Players in Queue are: \n' + printPlayers());
}
else if(msg.content === '!leave'){
let index = players.indexOf(msg.author);
if(index > -1){
players.splice(index, 1);
}
msg.channel.send('Players in Queue are: \n' + printPlayers());
}
if(msg.content === '!queue'){
msg.channel.send('Players in Queue are: \n' + printPlayers());
}
if(msg.content.includes('!addrole')){
let info = msg.content.split(" ");
let color = info[1];
let role = info[2];
if (color === 'blue') {
extraRoles.blue.push(role);
numRoles++;
} else if (color === 'red') {
extraRoles.red.push(role);
numRoles++;
} else if (color === 'grey') {
extraRoles.grey.push(role);
numRoles++;
} else if (color === 'both') {
extraRoles.blue.push(role);
extraRoles.red.push(role);
numRoles += 2;
} else {
msg.channel.send(`Color not recognized`);
}
msg.channel.send('Roles in game are: \n' + printRoles());
}
if(msg.content === '!roles'){
msg.channel.send('Roles in game are: \n' + printRoles());
}
if(msg.content === '!clearroles'){
extraRoles = {red: [], blue: [], grey: []};
numRoles = 0;
msg.channel.send('Roles reset.');
}
if(msg.content === '!refresh'){
players.length = 0;
msg.channel.send('Queue reset.');
}
if(msg.content === '!startgame'){
if(players.length < 6){
msg.channel.send('Not enough players in Queue to start the game!');
} else if (numRoles > players.length - 2) {
msg.channel.send('More roles than player in Queue. Please remove roles or add more players!');
} else {
msg.channel.send('Starting the game!');
msg.channel.send('Prepare to play, and check your DMs for your roles! The people playing are: \n' + printPlayers());
timer = 3;
ingame = true;
sendRoles();
}
}
}
else {
if(msg.content === '!timer'){
if(timeout) {
msg.channel.send('A timer is in session: ' + seconds+'s left on the timer.');
}
else {
if(timer > 0){
timeout = true;
seconds = timer * 60;
msg.channel.send('Starting a timer for ' + timer + ' minutes.')
int = setInterval(function() {
seconds = seconds - 1;
console.log('Time left: '+seconds+'s');
if(seconds == 60){
msg.channel.send('1 minute remaining');
}
if(seconds == 30){
msg.channel.send('30 seconds remaining');
}
if(seconds == 10){
msg.channel.send('10 seconds remaining');
}
if(seconds == 0){
msg.channel.send('TIME IS UP!');
timeout = false;
clearInterval(int);
int = null;
}
}, 1000);
timer = timer - 1;
}
}
}
if(msg.content === '!endgame'){
msg.channel.send('Ending the game. Timers and roles restarted.');
if(int != null){
clearInterval(int);
}
timeout = false;
timer = 3;
ingame = false;
}
}
})
client.login(token)