Version 0.4.1 - Ajout de la liste de lecture et du Rapport de Bug
This commit is contained in:
		@@ -215,20 +215,24 @@ function startErelaManager(dlog, config) {
 | 
			
		||||
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    client.manager.on("trackStart",async (player) => {
 | 
			
		||||
        plog.log("Lecture de '" + player.queue.current.title + "' de '" + player.queue.current.author + "'")
 | 
			
		||||
        await  list.setCurrent(player)
 | 
			
		||||
        await player.seek(0)
 | 
			
		||||
        process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
    client.manager.on("trackStart", async (player) => {
 | 
			
		||||
 | 
			
		||||
        if(player) {
 | 
			
		||||
            plog.log("Lecture de '" + player.queue.current.title + "' de '" + player.queue.current.author + "'")
 | 
			
		||||
            await list.setCurrent(player)
 | 
			
		||||
            await player.seek(0)
 | 
			
		||||
            process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
        }
 | 
			
		||||
       
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    client.manager.on("queueEnd", async () => {
 | 
			
		||||
        let player = client.manager.players.get("137291455336022018")
 | 
			
		||||
        let player = await client.manager.players.get("137291455336022018")
 | 
			
		||||
        if(player) { 
 | 
			
		||||
 | 
			
		||||
            await list.passCurrent()
 | 
			
		||||
            if(list.haveSongs()) {
 | 
			
		||||
            await list.addCurrentToPrevious()
 | 
			
		||||
            if(await list.haveSongs()) {
 | 
			
		||||
                await player.play(list.next())
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ const dlog = new LogType("Queue-List")
 | 
			
		||||
var next = new Array()
 | 
			
		||||
var previous = new Array()
 | 
			
		||||
var current = null;
 | 
			
		||||
var shuffle = false
 | 
			
		||||
 | 
			
		||||
module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
@@ -24,12 +25,39 @@ module.exports.List = class {
 | 
			
		||||
        next = new Array()
 | 
			
		||||
        previous = new Array()
 | 
			
		||||
        current = null
 | 
			
		||||
        shuffle = false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setShuffle(state) {
 | 
			
		||||
     
 | 
			
		||||
        shuffle = state
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getShuffle() {
 | 
			
		||||
 | 
			
		||||
        return shuffle
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    next() {
 | 
			
		||||
        const song = next[0]
 | 
			
		||||
        next.splice(0, 1)
 | 
			
		||||
        return song
 | 
			
		||||
 | 
			
		||||
        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() {
 | 
			
		||||
@@ -46,7 +74,7 @@ module.exports.List = class {
 | 
			
		||||
  
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    passCurrent() {
 | 
			
		||||
    addCurrentToPrevious() {
 | 
			
		||||
 | 
			
		||||
        previous.unshift(current)
 | 
			
		||||
 
 | 
			
		||||
@@ -100,6 +128,8 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
            interaction.reply({embeds: [embed]})
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    remove(song) {
 | 
			
		||||
@@ -111,6 +141,24 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,10 @@
 | 
			
		||||
const { SlashCommandBuilder, EmbedBuilder, DefaultWebSocketManagerOptions } = require("discord.js");
 | 
			
		||||
const { SlashCommandBuilder, EmbedBuilder, DefaultWebSocketManagerOptions, discordSort } = require("discord.js");
 | 
			
		||||
const { __glob } = require("../modules/global-variables");
 | 
			
		||||
const { LogType } = require("./sub-log");
 | 
			
		||||
const { List } = require("./sub-list")
 | 
			
		||||
var { List } = require("./sub-list")
 | 
			
		||||
const discord = require("./discord-bot")
 | 
			
		||||
var ytfps = require("ytfps");
 | 
			
		||||
const packageJson = require(__glob.PACKAGE);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const list = new List()
 | 
			
		||||
@@ -200,11 +201,22 @@ module.exports.SPECIAL_MJ = async function (client) {
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    const songs = await client.manager.search("Earth MJ")
 | 
			
		||||
    const songs2 = await client.manager.search("They don't care About Us")
 | 
			
		||||
    const songs2 = await client.manager.search("https://www.youtube.com/watch?v=_mwsc6xqb3w")
 | 
			
		||||
    const songs3 = await client.manager.search("https://www.youtube.com/watch?v=IdjgmRa3k-g")
 | 
			
		||||
 | 
			
		||||
    player.play(songs.tracks[0])
 | 
			
		||||
    if(!player.playing) {
 | 
			
		||||
        player.play(songs.tracks[0])
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
        
 | 
			
		||||
        list.add(songs.tracks[0])
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
    list.add(songs2.tracks[0])
 | 
			
		||||
    list.add(songs3.tracks[0])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -336,6 +348,31 @@ module.exports.loop = function (client) {
 | 
			
		||||
 | 
			
		||||
} 
 | 
			
		||||
 | 
			
		||||
module.exports.changeShuffle = function (client) {
 | 
			
		||||
 | 
			
		||||
    const shuffle = list.getShuffle()
 | 
			
		||||
 | 
			
		||||
    if(!client) {
 | 
			
		||||
 | 
			
		||||
        client = discord.getClient()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let player = client.manager.players.get("137291455336022018")
 | 
			
		||||
 | 
			
		||||
    if(player) {
 | 
			
		||||
 | 
			
		||||
        if(shuffle == true) {
 | 
			
		||||
            list.setShuffle(false)
 | 
			
		||||
        } else {
 | 
			
		||||
 | 
			
		||||
            list.setShuffle(true)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -399,7 +436,82 @@ module.exports.previous = function (client, interaction) {
 | 
			
		||||
 | 
			
		||||
const clog = new LogType("Actualisation")
 | 
			
		||||
 | 
			
		||||
module.exports.report = async function (client, interaction, data) {
 | 
			
		||||
 | 
			
		||||
    if(!client) {
 | 
			
		||||
 | 
			
		||||
        client = discord.getClient()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var level = null
 | 
			
		||||
    var desc = null
 | 
			
		||||
 | 
			
		||||
    if(interaction) {
 | 
			
		||||
 | 
			
		||||
        level = interaction.options.getString("level")
 | 
			
		||||
        desc = interaction.options.getString("desc")
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
    if(data) {
 | 
			
		||||
        level = data.level
 | 
			
		||||
        desc = data.desc
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
    var embed = new EmbedBuilder()
 | 
			
		||||
        .setDescription('**Version **' + packageJson.version)
 | 
			
		||||
        .setTimestamp();
 | 
			
		||||
 | 
			
		||||
    if(interaction) {
 | 
			
		||||
 | 
			
		||||
        embed.setTitle('Report de ' + interaction.member.user.username )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(data) {
 | 
			
		||||
        embed.setTitle('Report de ' + data.username.user.username )
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var levelString = null
 | 
			
		||||
 | 
			
		||||
    if(level == "Majeur") {
 | 
			
		||||
 | 
			
		||||
            levelString = "Urgent"
 | 
			
		||||
            embed.setColor(0xc20f02)
 | 
			
		||||
    } else if(level == "Mineur") {
 | 
			
		||||
            levelString = "Mineur"
 | 
			
		||||
            embed.setColor(0xdcff17)
 | 
			
		||||
            
 | 
			
		||||
    } else {
 | 
			
		||||
            levelString = "Suggestion"
 | 
			
		||||
            embed.setColor(0xffffff)
 | 
			
		||||
          
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    embed.addFields({name: "Niveau", value: levelString},{name: "Description", value: desc})
 | 
			
		||||
 | 
			
		||||
    const channel = await client.channels.fetch('1102177962817749033')
 | 
			
		||||
 | 
			
		||||
    channel.send({embeds: [embed]})
 | 
			
		||||
    channel.send({content: "<@486943594893017119>"})
 | 
			
		||||
 | 
			
		||||
    if(interaction) {
 | 
			
		||||
 | 
			
		||||
        const membed = new EmbedBuilder()
 | 
			
		||||
        .setColor(0x00ff66)
 | 
			
		||||
        .setTitle('Rapport de Bug envoyé !')
 | 
			
		||||
       
 | 
			
		||||
        interaction.reply({embeds: [membed]})
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.updateMusicState = function (client, action) {
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if(!client) {
 | 
			
		||||
 | 
			
		||||
@@ -414,6 +526,7 @@ module.exports.updateMusicState = function (client, action) {
 | 
			
		||||
        "current":null,
 | 
			
		||||
        "isOnline": false,
 | 
			
		||||
        "queue": null,
 | 
			
		||||
        "shuffle": false,
 | 
			
		||||
        "loop": false,
 | 
			
		||||
        "durationNow": null,
 | 
			
		||||
        "durationAll": null,
 | 
			
		||||
@@ -422,6 +535,14 @@ module.exports.updateMusicState = function (client, action) {
 | 
			
		||||
 | 
			
		||||
    if(player) {
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        const shuffle = list.getShuffle()
 | 
			
		||||
 | 
			
		||||
        if(shuffle) {
 | 
			
		||||
 | 
			
		||||
            data["shuffle"] = true
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        data["current"] = player.queue.current
 | 
			
		||||
  
 | 
			
		||||
        if(player.queueRepeat == true) {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ const auth = require("./sub-auth");
 | 
			
		||||
const cook = require("cookie")
 | 
			
		||||
const wlog = new LogType("Web")
 | 
			
		||||
const subplayer = require(__glob.SUBPLAYER);
 | 
			
		||||
const { List } = require("./sub-list")
 | 
			
		||||
module.exports.WebServer = class {
 | 
			
		||||
 | 
			
		||||
    constructor() {
 | 
			
		||||
@@ -172,7 +173,7 @@ function IOConnection(io) {
 | 
			
		||||
            io.emit("ANSWER/GET/DISCORD_LOGIN_LINK", discordlink )
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        GetRequest(socket, "USER_INFO", () => {  
 | 
			
		||||
        GetRequest(io, socket, "USER_INFO", () => {  
 | 
			
		||||
            var cookies = socket.handshake.headers.cookie
 | 
			
		||||
            cookies = cook.parse(cookies)
 | 
			
		||||
            var token = cookies.token
 | 
			
		||||
@@ -183,7 +184,7 @@ function IOConnection(io) {
 | 
			
		||||
            socket.emit("ANSWER/GET/USER_INFO",user)
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        GetRequest(socket, "MUSIC_STATE", () => {  
 | 
			
		||||
        GetRequest(io, socket, "MUSIC_STATE", () => {  
 | 
			
		||||
            var cookies = socket.handshake.headers.cookie
 | 
			
		||||
            cookies = cook.parse(cookies)
 | 
			
		||||
            var token = cookies.token
 | 
			
		||||
@@ -198,43 +199,56 @@ function IOConnection(io) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        GetRequest(socket, "PAUSE", () => {
 | 
			
		||||
        GetRequest(io, socket, "PAUSE", () => {
 | 
			
		||||
            
 | 
			
		||||
            subplayer.pause()
 | 
			
		||||
            io.emit("ANSWER/GET/PAUSE", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        GetRequest(socket, "BACKWARD", () => {
 | 
			
		||||
        GetRequest(io, socket, "BACKWARD", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.previous()
 | 
			
		||||
            io.emit("ANSWER/GET/BACKWARD", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
        
 | 
			
		||||
        GetRequest(socket, "FORWARD", () => {
 | 
			
		||||
        GetRequest(io, socket, "FORWARD", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.skip()
 | 
			
		||||
            io.emit("ANSWER/GET/FORWARD", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        GetRequest(socket, "LOOP", () => {
 | 
			
		||||
        GetRequest(io, socket, "LOOP", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.loop()
 | 
			
		||||
            io.emit("ANSWER/GET/LOOP", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        GetRequest(io, socket, "SHUFFLE", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.changeShuffle()
 | 
			
		||||
            io.emit("ANSWER/GET/SHUFFLE", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        GetRequest(socket, "DISCONNECT", () => {
 | 
			
		||||
        GetRequest(io, socket, "DISCONNECT", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.leave()
 | 
			
		||||
            io.emit("ANSWER/GET/DISCONNECT", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        GetRequest(socket, "SPECIAL/MJ", () => {
 | 
			
		||||
        GetRequest(io, socket, "SPECIAL/MJ", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.SPECIAL_MJ()
 | 
			
		||||
            io.emit("ANSWER/GET/SPECIAL/MJ", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -293,6 +307,91 @@ function IOConnection(io) {
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        socket.on("SEND/DELETE_QUEUE", (data) => {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            var cookies = socket.handshake.headers.cookie
 | 
			
		||||
 | 
			
		||||
            if(cookies) {
 | 
			
		||||
 | 
			
		||||
                cookies = cook.parse(cookies)
 | 
			
		||||
                var token = cookies.token
 | 
			
		||||
                 
 | 
			
		||||
                if(auth.checkUser(token)) {
 | 
			
		||||
 | 
			
		||||
                    var sublist = new List()
 | 
			
		||||
                    sublist.removeByIndex(data)
 | 
			
		||||
                
 | 
			
		||||
                } else {
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/DELETE_QUEUE", {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/SEND/DELETE_QUEUE", {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        socket.on("SEND/MOVE_QUEUE", (data) => {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            var cookies = socket.handshake.headers.cookie
 | 
			
		||||
 | 
			
		||||
            if(cookies) {
 | 
			
		||||
 | 
			
		||||
                cookies = cook.parse(cookies)
 | 
			
		||||
                var token = cookies.token
 | 
			
		||||
                 
 | 
			
		||||
                if(auth.checkUser(token)) {
 | 
			
		||||
 | 
			
		||||
                    var sublist = new List()
 | 
			
		||||
                    sublist.moveUp(data)
 | 
			
		||||
                
 | 
			
		||||
                } else {
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/DELETE_QUEUE", {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/SEND/DELETE_QUEUE", {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        socket.on("SEND/REPORT", (data) => {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            var cookies = socket.handshake.headers.cookie
 | 
			
		||||
 | 
			
		||||
            if(cookies) {
 | 
			
		||||
 | 
			
		||||
                cookies = cook.parse(cookies)
 | 
			
		||||
                var token = cookies.token
 | 
			
		||||
                 
 | 
			
		||||
                if(auth.checkUser(token)) {
 | 
			
		||||
 | 
			
		||||
                    data.username = auth.getUser(token)
 | 
			
		||||
                    subplayer.report(null, null, data)
 | 
			
		||||
                
 | 
			
		||||
                } else {
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/REPORT", {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/SEND/REPORT", {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
        
 | 
			
		||||
    })
 | 
			
		||||
@@ -302,7 +401,7 @@ function IOConnection(io) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function GetRequest (socket, name, func) {
 | 
			
		||||
function GetRequest (io, socket, name, func) {
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
        socket.on("GET/" + name, () => {
 | 
			
		||||
@@ -324,7 +423,7 @@ function GetRequest (socket, name, func) {
 | 
			
		||||
                    io.emit("ANSWER/GET/" + name, {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/GET/" + name, {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
                    io.emit("ANSWER/GET/" + name, {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user