264 lines
5.5 KiB
JavaScript
264 lines
5.5 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
|
const { __glob } = require("../modules/global-variables");
|
|
const { LogType } = require('./sub-log');
|
|
const discord = require("./discord-bot")
|
|
|
|
const dlog = new LogType("Queue-List")
|
|
|
|
var next = new Array()
|
|
var previous = new Array()
|
|
var current = null;
|
|
var shuffle = false
|
|
|
|
module.exports.List = class {
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
getList() {
|
|
|
|
return next
|
|
}
|
|
|
|
destroy() {
|
|
|
|
next = new Array()
|
|
previous = new Array()
|
|
current = null
|
|
shuffle = false
|
|
}
|
|
|
|
setShuffle(state) {
|
|
|
|
shuffle = state
|
|
|
|
}
|
|
|
|
getShuffle() {
|
|
|
|
return shuffle
|
|
}
|
|
|
|
next() {
|
|
|
|
if(!shuffle) {
|
|
const song = next[0]
|
|
next.splice(0, 1)
|
|
return song
|
|
|
|
} else {
|
|
|
|
|
|
const randomIndex = Math.floor(Math.random() * next.length);
|
|
const song = next[randomIndex]
|
|
next.splice(randomIndex, 1)
|
|
return song
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
previous() {
|
|
|
|
const song = previous[0]
|
|
previous.splice(0, 1)
|
|
return song
|
|
|
|
}
|
|
|
|
setCurrent(song) {
|
|
|
|
current = song.queue.current
|
|
|
|
}
|
|
|
|
addCurrentToPrevious() {
|
|
|
|
previous.unshift(current)
|
|
|
|
}
|
|
|
|
haveSongs() {
|
|
|
|
if(next.length == 0) {
|
|
return false
|
|
|
|
} else{
|
|
return true
|
|
}
|
|
|
|
}
|
|
|
|
havePreviousSongs() {
|
|
|
|
if(previous.length == 0) {
|
|
return false
|
|
|
|
} else{
|
|
return true
|
|
}
|
|
|
|
}
|
|
|
|
getNextSong() {
|
|
|
|
const song = next[0]
|
|
return song
|
|
|
|
}
|
|
|
|
|
|
async add(song, interaction) {
|
|
|
|
dlog.log("Ajout d'un titre dans la liste de lecture : '" + song.title + "' de '" + song.author + "'")
|
|
next.push(song)
|
|
|
|
if(interaction) {
|
|
|
|
const embed = await new EmbedBuilder()
|
|
.setColor(0x15e6ed)
|
|
.setTitle('**Ajout dans la liste de lecture **: ' + song.title)
|
|
.setDescription('**Demandé par **' + interaction.member.user.username)
|
|
.addFields({name: "Auteur", value: song.author},
|
|
{name: "URL", value: song.uri})
|
|
.setThumbnail(song.thumbnail)
|
|
.setTimestamp();
|
|
|
|
interaction.reply({embeds: [embed]})
|
|
}
|
|
|
|
process.emit("MUSIC_UPDATE_STATE")
|
|
}
|
|
|
|
remove(song) {
|
|
|
|
dlog.log("Supression d'un titre dans la liste de lecture : '" + song.title + "' de '" + song.author + "'")
|
|
|
|
const index = next.indexOf(song)
|
|
next.splice(index, 1)
|
|
|
|
}
|
|
|
|
removeByIndex(index) {
|
|
|
|
dlog.log("Supression d'un titre dans la liste de lecture : '" + next[index].title + "' de '" + next[index].author + "'")
|
|
|
|
|
|
next.splice(index, 1)
|
|
|
|
process.emit("MUSIC_UPDATE_STATE")
|
|
}
|
|
|
|
moveUp(index) {
|
|
|
|
let elementToMove = next[index]
|
|
next.splice(index, 1)
|
|
next.unshift(elementToMove);
|
|
process.emit("MUSIC_UPDATE_STATE")
|
|
}
|
|
|
|
__previous_add(song) {
|
|
|
|
previous.unshift(song)
|
|
|
|
}
|
|
|
|
__previous_remove(song) {
|
|
|
|
const index = next.indexOf(song)
|
|
previous.splice(index, 1)
|
|
}
|
|
|
|
__next_add(song) {
|
|
|
|
next.unshift(song)
|
|
|
|
}
|
|
|
|
async playlistAdd(playlist, interaction) {
|
|
|
|
if(interaction) {
|
|
|
|
const client = interaction.client
|
|
|
|
var author = "Artiste inconnu !"
|
|
|
|
if(typeof playlist.author != "undefined" ) {
|
|
|
|
author == playlist.author.name
|
|
}
|
|
|
|
|
|
const embed = await new EmbedBuilder()
|
|
.setColor(0x15e6ed)
|
|
.setTitle('**Lecture de la playlist : **' + playlist.title)
|
|
.setDescription('**Demandé par **' + interaction.member.user.username)
|
|
.addFields({name: "Auteur", value: author},
|
|
{name: "URL", value:playlist.url},
|
|
{name: "Nombre de videos", value:playlist.video_count + " vidéos"})
|
|
.setThumbnail(playlist.thumbnail_url)
|
|
.setTimestamp();
|
|
|
|
interaction.reply({embeds: [embed]})
|
|
|
|
let player = client.manager.players.get(interaction.guild.id)
|
|
|
|
for(var song of playlist.videos) {
|
|
|
|
const song_finded = await client.manager.search(song.url)
|
|
next.push(song_finded.tracks[0])
|
|
|
|
}
|
|
|
|
if(!player.playing) {
|
|
|
|
player.play(next[0])
|
|
this.remove(next[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
var client = null
|
|
|
|
if(!client) {
|
|
|
|
client = discord.getClient()
|
|
}
|
|
|
|
let player = client.manager.players.get("137291455336022018")
|
|
|
|
if(!player) {
|
|
|
|
player = client.manager.create({
|
|
guild: "137291455336022018",
|
|
voiceChannel: discord.getMemberVoices().get(userId),
|
|
textChannel: "664355637685256203",
|
|
});
|
|
|
|
|
|
player.connect();
|
|
}
|
|
|
|
for(var song of playlist) {
|
|
|
|
const song_finded = await client.manager.search(song.url)
|
|
next.push(song_finded.tracks[0])
|
|
|
|
}
|
|
|
|
if(!player.playing) {
|
|
|
|
player.play(next[0])
|
|
this.remove(next[0])
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |