-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
383 lines (295 loc) · 11.2 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
// REQUIRES
const Discord = require("discord.js");
const config = require("./config.json");
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');
const { exec } = require("ffmpeg/lib/utils");
const QuadrasDoTji = require("./QuadrasDoTji.json");
// Bot settings
const client = new Discord.Client({ intents: ["GUILDS"] });
client.login(config.BOT_TOKEN);
const prefix = config.PREFIX;
const queue = new Map(); // music queue
let MandarMadonisComOCaralho = false;
client.once('ready', () => {
console.log('Bot Started With Success!');
console.log('prefix is ' + prefix);
console.log('_________________________');
});
client.once('reconnecting', () => {
console.log('Bot is reconnecting...');
});
client.once('disconnect', () => {
console.log('Bot disconnected...');
});
client.on('guildMemberRemove', async(member) => {
if(member == left){
console.log(member.user.tag + "left the server")
}else if(member == kicked){
console.log(member.user.tag + "got kicked from the server the server bacause, "+reason)
}else if(member == banned){
console.log(member.user.tag + "got banned from the server the server bacause, "+reason)
}
});
client.on("message", async message => {
//if message is from bot or message does not start with prefix -> ignore
if (message.author.bot || !message.content.startsWith(prefix)){
return;
}
//explanation bellow
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args[0].toLowerCase();
const serverQueue = queue.get(message.guild.id);
/*
console.log("body:");
console.log(commandBody); //say balshit monte
console.log("args:");
console.log(args); // [ 'say', 'balshit', 'monte' ]
console.log("command:");
console.log(command); // say
*/
//Commands inside Switch statement with { } for better reading.
switch(command) {
case "say":{ //Say command. Says whatever was said after "prefix say"
var i;
let saymsg = "";
for (i = 1; i < args.length; i++) {
saymsg += args[i] + " ";
}
message.channel.send(saymsg);
break;
}
case "play":{ //play command. adds to queue the music, if found.
execute(message, serverQueue);
break;
}
case "andacacaralho":{ //enters the server.
JoinVoiceChat(message);
break;
}
case "madonis":{ //play command. adds to queue the music, if found.
MandarMadonisComOCaralho = !MandarMadonisComOCaralho;
break;
}
case "skip":{ //play command. adds to queue the music, if found.
skip(message, serverQueue);
break;
}
case "stop":{ //play command. adds to queue the music, if found.
stop(message, serverQueue);
break;
}
case "volume":{ //play command. adds to queue the music, if found.
volume(message, serverQueue);
break;
}
case "queue":{ //play command. adds to queue the music, if found.
queuelist(message, serverQueue);
break;
}
case "decide":{ //play command. adds to queue the music, if found.
let randomvars = args;
randomvars.shift();
let maxval = args.length;
let random = Math.floor(Math.random() * maxval) + 1;
message.channel.send("I would say " + randomvars[random-1]);
break;
}
case "commands":{ //play command. adds to queue the music, if found.
let msg = "``` \n say \n play \n skip \n stop \n volume (1 - 100) \n queue \n decide \n ```";
message.channel.send(msg);
break;
}
default:{
return message.channel.send("Wtf is that command u stupid? use commands to check my commands");
}
}
});
async function execute(message, serverQueue) {
const args = message.content.split(" ");
const voiceChannel = message.member.voice.channel;
if (!voiceChannel){
return message.channel.send("Join a voice channel first!");
}
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send("Someone took my permissions... I need CONNECT and SPEAK to play music");
}
let songInfo;
if(args[1].includes("www.youtube.com/watch?v=")){
songInfo = await ytdl.getInfo(args[1]);
}else{
let saymsg = "";
for (i = 1; i < args.length; i++) {
saymsg += args[i] + " ";
}
const r = await ytSearch(saymsg);
if(r.all){
songInfo = await ytdl.getInfo(r.all[0].url);
}
}
const song = {
title: songInfo.videoDetails.title,
url: songInfo.videoDetails.video_url,
};
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 0.5,
playing: true
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
}
else
{
serverQueue.songs.push(song);
return message.channel.send("I added " + song.title + " to the queue");
}
}
async function JoinVoiceChat(message) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel){
return message.channel.send("Join a voice channel first!");
}
try {
var connection = await voiceChannel.join();
} catch (err) {
}
}
function skip(message, serverQueue) {
if (!message.member.voice.channel){
return message.channel.send("You have to be in my voice channel to skip the music!");
}
if (!serverQueue){
return message.channel.send("No song is playing!");
}
serverQueue.songs.shift();
play(message.guild, serverQueue.songs[0]);
/*
message.channel.send("No song in queue, leaving...");
serverQueue.connection.dispatcher.end();
*/
}
function stop(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in my voice channel to stop the music!"
);
if (!serverQueue){
return message.channel.send("No song is playing!");
}
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on("finish", () => {
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(0.25);
serverQueue.textChannel.send(`Now Playing: ---> ${song.title} <---`);
}
function volume(message, serverQueue){
try {
const args = message.content.slice(prefix.length).split(' ');
let newVolume = args[1];
if(newVolume > 100 && newVolume <= 0){
return message.channel.send("Volume must be between 1 and 100");
}
serverQueue.volume = newVolume / 100;
serverQueue.connection.dispatcher.setVolumeLogarithmic(serverQueue.volume);
serverQueue.textChannel.send(`Volume changed to ${newVolume}%`);
} catch (error) {
return;
}
}
function queuelist(message, serverQueue) {
try {
let msg = "```";
for (var i = 0; i < serverQueue.songs.length; i++) {
if(i == 0){
msg += "\n" + serverQueue.songs[i].title + " -----> (Currently playing)";
continue;
}
msg += "\n" + serverQueue.songs[i].title;
}
msg += "\n```";
return message.channel.send(msg);
} catch (error) {
return null;
}
}
//get a random number between variables parameters
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
client.on("voiceStateUpdate", async (oldVoiceState, newVoiceState) => { // Listening to the voiceStateUpdate event
const serverQueue = queue.get(oldVoiceState.guild.id);
if (oldVoiceState.channel) {
if(oldVoiceState.member.user.tag === "MahallaBot#5373"){ //this bot was disconnected
queue.delete(oldVoiceState.guild.id)
}
};
try {
if (newVoiceState.channel === null) {
if (!oldVoiceState.guild.me.hasPermission('VIEW_AUDIT_LOG'))
return console.log('Missing permission: "VIEW_AUDIT_LOG"');
const fetchedLogs = await oldVoiceState.guild.fetchAuditLogs({
type: 'MEMBER_DISCONNECT'
});
var LastDC = fetchedLogs.entries.sort((a, b) => b.createdAt - a.createdAt).first();
// console.dir(LastDC);
const { executor } = LastDC;
var AuditDate = LastDC.createdAt;
console.log("AuditDate " + AuditDate);
var diff = Date.now() - AuditDate;
if(diff > 7500)
return;
if(executor.tag === "MahallaBot#5373" || executor.id === "452275672757436436")
return;
console.log(`<@${executor.id}>(@${executor.username}) Disconnected <@${oldVoiceState.id}>(${oldVoiceState.member.user.username})`);
var UserToDisconnect = oldVoiceState.guild.voiceStates.cache.get(executor.id);
if(UserToDisconnect !== undefined){
UserToDisconnect.setChannel(null, "Mandou uma pessoa com o caralho também.");
console.log("A mandar o " + UserToDisconnect.member.displayName + " com o caralho");
var NumQuadra = getRandomInt(0, QuadrasDoTji.quadras.length - 1);
client.channels.cache.get(`925162059753205850`).send(`O <@${UserToDisconnect.member.id}> foi com o caralho.`);
client.channels.cache.get(`925162059753205850`).send(QuadrasDoTji.quadras[NumQuadra]);
}
}else{
console.log(newVoiceState.member.user.id + " | " + MandarMadonisComOCaralho);
if(newVoiceState.member.user.id+"" === '183249276598484992' && MandarMadonisComOCaralho){
var UserToDisconnect = newVoiceState.guild.voiceStates.cache.get('183249276598484992');
UserToDisconnect.setChannel(null, "É o madonis. Não merece estar aqui.");
client.channels.cache.get(`925162059753205850`).send(`Madonis do caralho seu fdp, não me voltas a kickar do servidor.`);
}
}
} catch (error) {
console.log(error);
}
});