This repository was archived by the owner on Aug 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.js
215 lines (197 loc) · 10 KB
/
play.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
// @ts-nocheck
const langfile = require("../storage/translation/language.json")
"use strict"
const YTDL = require("ytdl-core");
const search = require("youtube-search");
var options1 = {
maxResults: 10,
type: 'video',
videoCategoryId: '10',
key: 'YoutubeAPI-Key'
};
var options2 = {
maxResults: 1,
type: 'video',
videoCategoryId: '10',
key: 'YoutubeAPI-Key'
};
let max_loop = 10
async function Play(connection, message, lan) {
var server = global.servers[message.guild.id];
if (!global.volume.has(message.guild.id)) { await global.volume.set(message.guild.id, 1) }
server.dispatcher = connection.playStream(YTDL(server.queue[0], { quality: "highestaudio", filter: "audioonly", highWaterMark: 1 << 25 }));
global.dispatcher = server.dispatcher
connection.player.setBitrate("auto");
await server.dispatcher.setVolumeLogarithmic(global.volume.get(message.guild.id))
YTDL.getInfo(server.queue[0], (err, info) => {
if (err) return message.reply(lan.err)
setTimeout(() => {
if (global.temp.has(message.guild.id)) {
if (global.temp.has(message.guild.id, "loop")) {
if (!global.temp.get(message.guild.id, "loop")) {
let i = 0;
message.channel.send(`${lan.play}: ${info.author.name} - ${info.title}`); i++; if (i <= max_loop) global.temp.set(message.guild.id, false, "loop"); message.channel.send(`<:deny:650472278706094100> **Song Loop disabled!**`)
}
} else { message.channel.send(`${lan.play}: ${info.author.name} - ${info.title}`); }
} else { message.channel.send(`${lan.play}: ${info.author.name} - ${info.title}`); }
}, 1000)
})
server.dispatcher.on("end", () => {
if (global.temp.has(message.guild.id)) { if (global.temp.has(message.guild.id, "loop")) { if (!global.temp.get(message.guild.id, "loop")) { server.queue.shift(); } else { } } } else { server.queue.shift(); }
if (server.queue[0]) {
Play(connection, message, lan);
}
else {
connection.disconnect();
global.volume.delete(message.guild.id)
message.channel.send(lan.finish);
}
});
}
let nl = 25
let bl = 5
const needed_permlvl = 1
module.exports.run = async (client, message, args) => {
if (client.permlvl < needed_permlvl) return message.reply("doesnt look like you have the perms to do this!")
if (!global.music) return message.reply("Music has been disabled by the Developers!")
if (!client.premium) {
}
var short = args.join("+")
let lan
if (client.language.get(message.guild.id) == "eng") {
lan = langfile.english.music.play
}
if (client.language.get(message.guild.id) == "ger") {
lan = langfile.german.music.play
}
if (client.language.get(message.guild.id) == "fr") {
lan = langfile.french.music.play
}
if (client.language.get(message.guild.id) == "cz") {
lan = langfile.czech.music.play
}
if (client.language.get(message.guild.id) == "ru") {
lan = langfile.russian.music.play
}
if (message.member.voiceChannel) {//commander is in voiceChannel
if (typeof args[0] == "undefined") {
message.channel.send(lan.undefined);
}
else {
if (message.guild.voiceConnection) {//I'm in voicechannel
if (message.member.voiceChannel.id === message.guild.voiceConnection.channel.id) {//ids of my Voicechannel and commander's one are same -> we are in the same voiceChannel
if (!global.servers[message.guild.id]) {//If this server isn't in my server list, I'll add it
global.servers[message.guild.id] = { queue: [] }//And create queue for it
}
if (YTDL.validateURL(args[0])) {//If commander entered valid YT url
global.servers[message.guild.id].queue.push(args[0]);//I add video url to queue
if (!global.servers[message.guild.id].queue[1]) {
Play(message.guild.voiceConnection, message, lan);
}
else {
message.channel.send(lan.add);
}
}
else {//I search the video on YouTube
//token 1
search(short, options1, (err, results) => {
if (err) { message.channel.send(client.clean(err), { code: "xl" }), client.temp.set("backup", true); return }
// if (err) return console.log(err);
if (!client.premium) {
let i = 0; global.servers[message.guild.id].queue.forEach(() => { i++ });
if (i >= nl) return message.channel.send(`<:deny:650472278706094100> **You Exeeded the ${nl} Song limit!**`)
}
global.servers[message.guild.id].queue.push(results[0].link);//I add video url to queue
if (!global.servers[message.guild.id].queue[1]) {
Play(message.guild.voiceConnection, message, lan);
}
else {
message.channel.send(lan.add);
}
});
if (client.temp.get("backup")) {
if (client.premium) {
let confirm = await client.awaitReply(message, "Using Backup API, Confirm?", 5000, false)
if (!confirm) { return } else { if (confirm != "yes") return }
message.reply("using Backup API!")
search(short, options2, (err, results) => {
if (err) message.channel.send(client.clean(err), { code: "xl" });
let i = 0; global.servers[message.guild.id].queue.forEach(() => { i++ });
if (i >= bl) return message.channel.send(`<:deny:650472278706094100> **You Exeeded the ${bl} Song Backup API Limit!**`)
global.servers[message.guild.id].queue.push(results[0].link);
if (!global.servers[message.guild.id].queue[1]) {
Play(message.guild.voiceConnection, message, lan);
}
else {
message.channel.send(lan.add);
}
})
} else { }
return
}
}
}
else {
message.channel.send(lan.channel);
}
}
else { //I join commanders voice channel
//----------------------
//TODODODODODODODOOD: dodělat vyhledávání i tady!
//----------------------
require("./join").run(client, message, args).then(() => {
if (!global.servers[message.guild.id]) {//If this server isn't in my server list, I'll add it
global.servers[message.guild.id] = { queue: [] }//And create queue for it
}
if (YTDL.validateURL(args[0])) {//If commander entered valid YT url
global.servers[message.guild.id].queue.push(args[0]);
// console.log(global.servers[message.guild.id].queue[0]);
Play(message.guild.voiceConnection, message, lan);
}
else {//I search the video on YouTube
let backup = false
search(short, options1, (err, results) => {
if (err) { message.channel.send(client.clean(err), { code: "xl" }); backup = true; return } //console.log(err);
global.servers[message.guild.id].queue.push(results[0].link);//I add video url to queue
if (!global.servers[message.guild.id].queue[1]) {
Play(message.guild.voiceConnection, message, lan);
}
else {
message.channel.send(lan.add);
}
});
if (backup) {
if (client.premium) {
search(short, options2, (err, results) => {
let confirm = client.awaitReply(message, "Using Backup API, Confirm?", 5000, false)
if (!confirm) { return } else { if (confirm != "yes") return }
message.reply("using Backup API!")
if (err) return message.channel.send(client.clean(err), { code: "xl" }) //console.log(err);
global.servers[message.guild.id].queue.push(results[0].link);//I add video url to queue
if (!global.servers[message.guild.id].queue[1]) {
Play(message.guild.voiceConnection, message, lan);
}
else {
message.channel.send(lan.add);
}
});
}
}
}
});
}
}
}
else {
message.channel.send(lan.nochannel);
}
}
module.exports.help = {
name: "play",
permlvl: 1,
description: "Play some Music.",
hidden: false,
aliases: ["p"],
usage: "play [Name/URL]",
category: "music"
}