This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
397 lines (357 loc) · 13.1 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
To Do:
Looking for Group command
[/] $mute command to mute users on mobile
*/
const Discord = require("discord.js");
const nodeCMD = require("node-cmd");
const client = new Discord.Client();
require("dotenv").config();
const token = process.env.TOKEN;
const commandsList = require("./commands.json");
const prefix = "$";
var gitCommit = "Couldn't get commit";
// Command variables
var peopleInQueue = [];
var alreadyMuted = false;
client.on("ready", async () => {
gitCommit = await nodeCMD.get(`git rev-parse --short HEAD`, function (
err,
data,
stderr
) {
console.log(`${client.user.username} is online on commit ${data}`);
// is this okay in an await function?
client.user.setActivity("Among Us", {
type: "PLAYING",
});
gitCommit = data;
});
});
client.on("voiceStateUpdate", (oldState, newState) => {
let oldID;
let newID;
if (oldState.channel) oldID = oldState.channelID;
if (newState.channel) newID = newState.channelID;
var queueID = "";
var gamechannelID = "";
try {
queueID = client.channels.cache.find((channel) => channel.name === "Queue")
.id;
gamechannelID = client.channels.cache.find((channel) =>
channel.name.includes("| Among Us")
);
} catch (err) {
console.log(err);
}
if (oldID !== queueID && newID === queueID) {
// JOINED QUEUE CHAT
peopleInQueue.push(newState.member.id);
if (gamechannelID.members.size < 10) {
var toBeMoved = newState.guild.members.cache.get(peopleInQueue[0]);
toBeMoved.voice.setChannel(gamechannelID);
peopleInQueue.shift();
}
}
if (oldID === queueID && newID !== queueID) {
// LEFT QUEUE CHAT
peopleInQueue.splice(peopleInQueue.indexOf(newState.member.id), 1);
}
if (oldID === gamechannelID.id && newID !== gamechannelID.id) {
if (gamechannelID.members.size < 10) {
if (peopleInQueue.length >= 1) {
var toBeMoved = newState.guild.members.cache.get(peopleInQueue[0]);
toBeMoved.voice.setChannel(gamechannelID);
peopleInQueue.shift();
}
}
}
});
client.on("message", (message) => {
const args = message.content.substr(prefix.length).split(" ");
if (!message.content.startsWith(prefix)) return;
if (message.author.bot) {
return;
}
switch (args[0]) {
case "ping":
// Ping the bot and get the delay
message.channel.send("Pinging...").then((msg) => {
msg.edit("Ping: " + (Date.now() - msg.createdTimestamp + " ms"));
});
break;
case "m":
case "mute":
// deafen and mutme evryone
var _game = "";
try {
_game = client.channels.cache.find((channel) =>
channel.name.includes("| Among Us")
);
} catch (err) {}
if (message.member.voice.channel.id === _game.id) {
var channel = message.guild.channels.cache.get(
message.member.voice.channel.id
);
alreadyMuted = !alreadyMuted;
for (const [memberID, member] of channel.members) {
if (alreadyMuted) {
member.voice.setMute(true);
} else {
member.voice.setMute(false);
}
}
} else {
message.author.send(
"You must be in the game channel to use this command!"
);
}
break;
case "d":
case "dead":
// lets dead people talk while players are deafened
if (message.member.voice.channel) {
var channel = message.guild.channels.cache.get(
message.member.voice.channel.id
);
message.member.voice.setMute(false);
}
break;
case "version":
// Get the git version
message.channel.send(`Commit \`${gitCommit}\``);
break;
case "help":
// Sends help on the bot
const helpEmbed = new Discord.MessageEmbed()
.setColor("#5CFF35")
.setTitle("Among Us Bot Help")
.setDescription(
"There are many commands with Among Us Bot. Most of them you don't even have to do anything to prep!\nBy using the `$commands` command you can view all of the commands."
)
.addFields(
{
name: "Github",
value:
"[Contribute Here!](https://www.github.com/mrauro/among-us-bot/)",
inline: "true",
},
{
name: "Twitter",
value: "[Follow me on Twitter!](https://www.twitter.com/auror6s)",
inline: "true",
},
{
name: "Invite",
value:
"Currently, this bot is private however later you can add this bot to your own Discord!", // im planning on making this public
inline: "true",
}
)
.setThumbnail(
"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.HCuyxDU5qqVDlpp0FnPVJwAAAA%26pid%3DApi&f=1"
)
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
message.channel.send(helpEmbed);
break;
case "commands":
// List all the commands from the commands.json file
const commandsEmbed = new Discord.MessageEmbed()
.setColor("#5CFF35")
.setTitle("Among Us Bot Commands")
.setDescription(
"Below are all of the commands associated with the bot!"
);
for (var i = 0; i < commandsList.length; i++) {
commandsEmbed.addField(commandsList[i].command, commandsList[i].usage);
}
commandsEmbed
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
message.channel.send(commandsEmbed);
break;
case "usage":
// Sends the usage of a command
// this needs to check if there is no command in commands.json
if (args[1] === undefined) {
for (var i = 0; i < commandsList.length; i++) {
// this is unnessacary, fix this later.
if (commandsList[i].command == "usage") {
const usageUsageEmbed = new Discord.MessageEmbed()
.setColor("#66B66E")
.setTitle(`Usage of: ${commandsList[i].command}`)
.setDescription(commandsList[i].usage)
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
message.channel.send(usageUsageEmbed);
}
}
}
for (var i = 0; i < commandsList.length; i++) {
if (commandsList[i].command == args[1]) {
const usageEmbed = new Discord.MessageEmbed()
.setColor("#66B66E")
.setTitle(`Usage of: ${commandsList[i].command}`)
.setDescription(commandsList[i].usage)
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
message.channel.send(usageEmbed);
}
}
break;
case "code":
// changes the vc name based on the code and region
message.delete();
let re = new RegExp("^[A-Za-z]+");
if (args[1] !== undefined) {
if (args[1].length === 4 || args[1].length === 6) {
// 6 digit codes now (at least on test branch)
if (
args[2] === "NA" ||
args[2] === "na" ||
args[2] === "EU" ||
args[2] === "eu" ||
args[2] === "ASIA" ||
args[2] === "asia"
) {
if (args[1].match(re)) {
if (message.member.voice.channel) {
const codeEmbed = new Discord.MessageEmbed()
.setColor("#3A92EF")
.setTitle(
`${args[1].toUpperCase()} on ${args[2].toUpperCase()}`
)
.setDescription(
`The code is ${args[1].toUpperCase()} on ${args[2].toUpperCase()}.\n\nCheck the voice channel name too!\n*sometimes the voice channel name wont change due to being rate limited*`
) // make this look better
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
try {
var codesID = message.guild.channels.cache.find(
(channel) => channel.name === "codes"
).id;
client.channels.cache.get(codesID).send(codeEmbed);
if (!message.channel.id === codesID) {
// check if the command wasnt sent in the codes channel
message.channel
.send(`Sent in <#${codesID}>`)
.then((msg) => {
msg.delete({
timeout: 5000,
});
});
}
} catch (err) {
message.channel.send(codeEmbed);
}
message.member.voice.channel.edit({
name: `${args[1].toUpperCase()} | ${args[2].toUpperCase()} | Among Us`, // This among us NEEDS to be here, it makes the bot work without storing data
});
} else {
message.channel.send("**Error:** Please join a voice channel.");
}
} else {
message.channel.send("**Error:** Invalid Code");
}
} else {
message.channel.send("**Error:** Invalid Region (NA, EU, or ASIA)");
}
} else {
message.channel.send("**Error:** Invalid Code");
return;
}
} else {
message.channel.send("**Error:** Missing Arguments");
}
case "overlay":
if (message.member.voice.channel){
const overlayEmbed = new Discord.MessageEmbed()
.setColor("#66B66E")
.setTitle(`Overlay for ${message.member.voice.channel.name}`)
.setURL(`https://streamkit.discord.com/overlay/voice/${message.member.voice.channel.guild.id}/${message.member.voice.channel.id}?icon=false&online=false&logo=white&text_color=%23ffffff&text_size=28&text_outline_color=%23000000&text_outline_size=0&text_shadow_color=%23000000&text_shadow_size=0&bg_color=%231e2124&bg_opacity=0&bg_shadow_color=%23000000&bg_shadow_size=0&invite_code=jreTYZS&limit_speaking=true&small_avatars=false&hide_names=false&fade_chat=0`)
.setDescription(`Create a browser capture and set the URL to:\n\nhttps://streamkit.discord.com/overlay/voice/${message.member.voice.channel.guild.id}/${message.member.voice.channel.id}?icon=false&online=false&logo=white&text_color=%23ffffff&text_size=28&text_outline_color=%23000000&text_outline_size=0&text_shadow_color=%23000000&text_shadow_size=0&bg_color=%231e2124&bg_opacity=0&bg_shadow_color=%23000000&bg_shadow_size=0&invite_code=jreTYZS&limit_speaking=true&small_avatars=false&hide_names=false&fade_chat=0`)
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
message.channel.send(overlayEmbed)
} else {message.channel.send("**Error:** Please join a voice channel.")}
break;
/*
in development
case "lfg":
// find a text channel that has among-us-lfg
var lfgChat = "";
try {
lfgChat = client.channels.cache.find((channel) => channel.name === "among-us-lfg")
.id;
if(queueID.type === "text") {
// is text type
} else { return; }
} catch (err) {
console.log(err);
}
const lfgEmbed = new Discord.MessageEmbed()
.setColor("#3A92EF")
.setTitle(
`${message.author.name} is looking for a group!`
)
.setDescription(
`Use the \`$join\` command to join! After 3 hours if 10 people aren't wanting to play this message will self-destruct.`
)
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
lfgChat.send()
break;
*/
}
});
client.on("message", (message) => {
const args = message.content.toLowerCase();
if (message.author.bot) {
return;
}
function codeFeature() {
for (var i = 0; i < commandsList.length; i++) {
// this is unnessacary, fix this later.
if (commandsList[i].command == "code") {
const usageUsageEmbed = new Discord.MessageEmbed()
.setColor("#66B66E")
.setTitle(`Usage of: ${commandsList[i].command}`)
.setDescription(commandsList[i].usage)
.setTimestamp()
.setFooter(
`Requested by ${message.author.username}`,
message.author.avatarURL
);
message.channel.send(usageUsageEmbed);
}
}
}
if (args.includes("code is")) {
// remind users of my nifty featuere :)
message.channel.send("**Hey!** I have a feature for that!");
codeFeature();
}
});
client.login(token);