This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
140 lines (123 loc) · 3.78 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
const Discord = require('discord.js');
const {
prefix,
token
} = require('./config.json');
const ytdl = require('ytdl-core');
const client = new Discord.Client();
const queue = new Map();
client.once('ready', () => {
console.log('A punt!');
});
client.once('reconnecting', () => {
console.log('Reconnectant!');
});
client.once('disconnect', () => {
console.log('Desconnectat!');
});
client.on('message', async message => {
if (message.author.bot) return;
const serverQueue = queue.get(message.guild.id);
console.log(message.content);
if (message.content.startsWith("<:drip:") || message.content.startsWith("<:astronaut:")) {
console.log("Drip");
execute(message, serverQueue, 0);
}
else if (message.content.startsWith("<:garota:")) {
console.log("Garota");
execute(message, serverQueue, 1);
}
else if (message.content.startsWith("<:hamburger:") || message.content.startsWith("🍔")) {
console.log("Obama hamburger sussy balls");
execute(message, serverQueue, 2);
}
else if (message.content.startsWith(`${prefix}stop`) || message.content.startsWith("😩")) {
stop(message, serverQueue);
}
//console.log(message.content);
});
function stop(message, serverQueue) {
if (!serverQueue)
return message.channel.send("No hay ninguna canción");
serverQueue.songs = [];
if (serverQueue.connection) serverQueue.connection.dispatcher.end();
}
async function execute(message, serverQueue, opcio) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return;
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"No tengo permisos para entrar o hablar en tu canal de voz :("
);
}
let songInfo;
let url;
switch (opcio) {
case 0:
url = "https://www.youtube.com/watch?v=grd-K33tOSM";
break;
case 1:
url = "https://www.youtube.com/watch?v=bl6x1m54yIM";
break;
default:
url = "https://www.youtube.com/watch?v=m-VUAUglqnU";
break;
}
songInfo = await ytdl.getInfo(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: 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 {
if (!message.guild.voice.channel) {
try {
var connection = await voiceChannel.join();
serverQueue.connection = connection;
play(message.guild, serverQueue.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return console.log(err);
//return message.channel.send(err);
}
}
}
}
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(serverQueue.volume / 5);
}
client.login(token);