Version 0.6.3 - Ajout de l'Handle Playlist & Add on Current track

This commit is contained in:
Raphix
2023-08-29 18:25:28 +02:00
parent 36539ebe21
commit 59bebe392b
10 changed files with 512 additions and 154 deletions

View File

@ -178,7 +178,26 @@ module.exports.List = class {
}
async playlistAdd(playlist, interaction, userId) {
async fpPlaylistAdd(playlist, client) {
let player = client.manager.players.get("137291455336022018")
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])
}
}
async playlistAdd(playlist, interaction, userId, ) {
if(interaction) {

View File

@ -232,7 +232,7 @@ module.exports.SPECIAL_MJ = async function (client, userId) {
}
module.exports.addSong = async function (data, client, userId, quick) {
module.exports.addSong = async function (data, client, userId, quick, playlist) {
if(!client) {
@ -262,7 +262,15 @@ module.exports.addSong = async function (data, client, userId, quick) {
}
const songs = await client.manager.search(data.uri)
var songs = null
if(playlist) {
songs = await client.manager.search(data)
} else {
songs = await client.manager.search(data.uri)
}
if(quick) {
@ -283,6 +291,50 @@ module.exports.addSong = async function (data, client, userId, quick) {
process.emit("MUSIC_UPDATE_STATE")
}
module.exports.addSongsFromPlaylist = async function (data, client, userId, quick, playlist) {
if(!client) {
client = discord.getClient()
}
let player = client.manager.players.get("137291455336022018")
var memberVoices = discord.getMemberVoices()
var channelId = memberVoices.get(userId)
if(!channelId) {
channelId = "664355808250953739"
}
if(!player) {
player = client.manager.create({
guild: "137291455336022018",
voiceChannel: channelId,
textChannel: "664355637685256203",
});
player.connect();
}
var playlist = await checkPlaylist(data)
if(playlist) {
list.fpPlaylistAdd(playlist, client)
}
process.emit("MUSIC_UPDATE_STATE")
}
@ -444,6 +496,10 @@ const slog = new LogType("Search")
module.exports.search = async function (data, client) {
var answer = {
"results":null,
"playlist":false
}
if(!client) {
@ -452,8 +508,23 @@ module.exports.search = async function (data, client) {
slog.log("Recherche avec les mots clés : " + data)
const songs = await client.manager.search(data)
return songs
var splaylist = await checkPlaylist(data)
if(splaylist) {
answer.playlist = true
answer.results = splaylist
} else {
const songs = await client.manager.search(data)
answer.playlist = false
answer.results = songs
}
return answer
}

View File

@ -527,6 +527,112 @@ function IOConnection(io) {
})
socket.on("SEND/FP_ADD_SONG", async (data) => {
var cookies = socket.handshake.headers.cookie
if(cookies) {
cookies = cook.parse(cookies)
var token = cookies.token
if(auth.checkUser(token)) {
var user = auth.getUser(token)
var userId = user.user.id
subplayer.addSong(data, null, userId, false, true)
io.emit("ANSWER/SEND/FP_ADD_SONG/OK")
} else {
io.emit("ANSWER/SEND/FP_ADD_SONG", {"error":"USER_DONT_EXIST"})
}
} else {
io.emit("ANSWER/SEND/FP_ADD_SONG", {"error":"TOKEN_NOT_FINDED"})
}
})
socket.on("SEND/FP_ADD_SONG_NOW", async (data) => {
var cookies = socket.handshake.headers.cookie
if(cookies) {
cookies = cook.parse(cookies)
var token = cookies.token
if(auth.checkUser(token)) {
var user = auth.getUser(token)
var userId = user.user.id
subplayer.addSong(data, null, userId, true, true)
io.emit("ANSWER/SEND/FP_ADD_SONG_NOW/OK")
} else {
io.emit("ANSWER/SEND/FP_ADD_SONG_NOW", {"error":"USER_DONT_EXIST"})
}
} else {
io.emit("ANSWER/SEND/FP_ADD_SONG_NOW", {"error":"TOKEN_NOT_FINDED"})
}
})
socket.on("SEND/FP_PLAY_PLAYLIST", async (data) => {
var cookies = socket.handshake.headers.cookie
if(cookies) {
cookies = cook.parse(cookies)
var token = cookies.token
if(auth.checkUser(token)) {
var user = auth.getUser(token)
var userId = user.user.id
subplayer.addSongsFromPlaylist(data, null, userId, true)
io.emit("ANSWER/SEND/FP_PLAY_PLAYLIST/OK")
} else {
io.emit("ANSWER/SEND/FP_PLAY_PLAYLIST", {"error":"USER_DONT_EXIST"})
}
} else {
io.emit("ANSWER/SEND/FP_PLAY_PLAYLIST", {"error":"TOKEN_NOT_FINDED"})
}
})
socket.on("SEND/CREATE_PLAYLIST", async (data) => {