-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
84 lines (74 loc) · 2.84 KB
/
functions.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
/* eslint-disable no-useless-escape */
const { EmbedBuilder } = require("discord.js");
module.exports = {
formatDate: function (date) {
return new Intl.DateTimeFormat("us-en").format(date);
},
msToTime: function (duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
},
secondsToHms: function (seconds) {
seconds = Number(seconds);
var d = Math.floor(seconds / (3600 * 24));
var h = Math.floor((seconds % (3600 * 24)) / 3600);
var m = Math.floor((seconds % 3600) / 60);
var s = Math.floor(seconds % 60);
var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return dDisplay + hDisplay + mDisplay + sDisplay;
},
playsong: async function (client, interaction, base64) {
const { Rest } = require("lavacord");
const node = client.manager.idealNodes[0];
const serverQueue = client.queue[interaction.guild.id];
if (serverQueue.chanelid == 0) {
serverQueue.chanelid.push(interaction.channel.id);
}
if (base64.loadType == "track") {
serverQueue.queue.push(base64.data.encoded);
if (serverQueue.queue.length == 1) {
serverQueue.player.play(serverQueue.queue[0]);
}
} else if (base64.loadType == "search") {
serverQueue.queue.push(base64.data[0].encoded);
if (serverQueue.queue.length == 1) {
serverQueue.player.play(serverQueue.queue[0]);
}
}
},
searchsong: async function (client, search) {
const { Rest } = require("lavacord");
const regex =
/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/;
if (regex.test(search) == true) {
const node = client.manager.idealNodes[0];
return Rest.load(node, search).catch((err) => {
console.error(err);
return null;
});
} else {
const node = client.manager.idealNodes[0];
return Rest.load(node, "ytsearch:" + search).catch((err) => {
console.error(err);
return null;
});
}
},
decdodeURL: async function (client, b64) {
const { Rest } = require("lavacord");
const node = client.manager.idealNodes[0];
return Rest.decode(node, b46).catch((err) => {
console.error(err);
return null;
});
},
};