Version 2.0.0 - Refonte complète du Bot
This commit is contained in:
		@@ -6,8 +6,6 @@ const { __glob } = require("./global-variables")
 | 
			
		||||
const { LogType } = require("loguix")
 | 
			
		||||
const { List } = require("./sub-list")
 | 
			
		||||
const nodeFinder = require("./nodes-finder")
 | 
			
		||||
const subplayer = require("./sub-player")
 | 
			
		||||
const nodemon = require("nodemon")
 | 
			
		||||
const metric = require("webmetrik") 
 | 
			
		||||
 | 
			
		||||
const client = new Client({
 | 
			
		||||
@@ -153,25 +151,6 @@ function init(dlog, config) {
 | 
			
		||||
function startErelaManager(dlog, config) {
 | 
			
		||||
 | 
			
		||||
    const elog = new LogType("Lavalink-Manager")
 | 
			
		||||
 | 
			
		||||
    client.on("voiceStateUpdate", (oldMember, newMember) => {
 | 
			
		||||
 | 
			
		||||
        membersVoices.set(newMember.id, newMember.channelId)
 | 
			
		||||
 | 
			
		||||
        let player = client.manager.players.get(oldMember.guild.id)
 | 
			
		||||
 | 
			
		||||
        if(player) {
 | 
			
		||||
 | 
			
		||||
            client.channels.fetch(player.options.voiceChannel).then(channel => {
 | 
			
		||||
 | 
			
		||||
                if(channel.members.size <= 1) {
 | 
			
		||||
 | 
			
		||||
                    player.destroy()
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    const nodes = nodeFinder.getNodes()
 | 
			
		||||
    
 | 
			
		||||
    client.manager = new Manager({
 | 
			
		||||
@@ -191,19 +170,22 @@ function startErelaManager(dlog, config) {
 | 
			
		||||
 | 
			
		||||
        membersVoices.set(newMember.id, newMember.channelId)
 | 
			
		||||
 | 
			
		||||
        /* SECURITY DISABLED
 | 
			
		||||
        let player = client.manager.players.get(oldMember.guild.id)
 | 
			
		||||
        
 | 
			
		||||
            if(player) {
 | 
			
		||||
                
 | 
			
		||||
                    client.channels.fetch(player.options.voiceChannel).then(channel => {
 | 
			
		||||
 | 
			
		||||
        if(player) {
 | 
			
		||||
                        if(channel.members.size <= 1) {
 | 
			
		||||
 | 
			
		||||
            client.channels.fetch(player.options.voiceChannel).then(channel => {
 | 
			
		||||
 | 
			
		||||
                if(channel.members.size <= 1) {
 | 
			
		||||
 | 
			
		||||
                    player.destroy()
 | 
			
		||||
                    plog.log("[Automatic Task] Player supprimé dans : " + channel.name)
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
                            player.destroy()
 | 
			
		||||
                            plog.log("[Automatic Task] Player supprimé dans : " + channel.name)
 | 
			
		||||
                        }
 | 
			
		||||
                    })
 | 
			
		||||
         
 | 
			
		||||
            }*/
 | 
			
		||||
      
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -261,9 +243,8 @@ function startErelaManager(dlog, config) {
 | 
			
		||||
            if(await list.haveSongs()) {
 | 
			
		||||
                
 | 
			
		||||
                await player.play(list.next())
 | 
			
		||||
 | 
			
		||||
                console.log("Lecture de la musique suivante")
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -295,17 +276,4 @@ function startErelaManager(dlog, config) {
 | 
			
		||||
    client.on("raw", d => client.manager.updateVoiceState(d));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function closeClient()  {
 | 
			
		||||
    console.log("Fermeture du client Discord")
 | 
			
		||||
    if(client) {
 | 
			
		||||
        let player = await client.manager.players.get("137291455336022018")
 | 
			
		||||
        if(player) {
 | 
			
		||||
            await player.destroy()
 | 
			
		||||
        }
 | 
			
		||||
        client.destroy()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,10 +17,10 @@ const __glob = {
 | 
			
		||||
    NODES:  root + path.sep + "data" + path.sep + "nodes.json",
 | 
			
		||||
    README: root + path.sep + "README.md",
 | 
			
		||||
    PLAYLIST:  root + path.sep + "data" + path.sep + "playlist.json",
 | 
			
		||||
    RADIO:  root + path.sep + "data" + path.sep + "radios.json",
 | 
			
		||||
    LOGS: root + path.sep + "src" + path.sep + "modules" + path.sep + "logs",
 | 
			
		||||
    METRIC_FILE: root + path.sep + "data" + path.sep + "metrics.json",
 | 
			
		||||
    PICTURE_DIR: root + path.sep + "data" + path.sep + "pictures",
 | 
			
		||||
    PREVIOUS_FILE: root + path.sep + "data" + path.sep + "previous.json",
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const webroot = __glob.WEB_DIR + path.sep 
 | 
			
		||||
 
 | 
			
		||||
@@ -91,6 +91,7 @@ module.exports.addNodes = function (data) {
 | 
			
		||||
    nlog.step.init("add_nodes", "Ajout d'un nouveau noeud dans la base de donnée de nodes : " + data.host)
 | 
			
		||||
    try {
 | 
			
		||||
        var nodes_data = readNodesFile()
 | 
			
		||||
        data.retryAmount = 1
 | 
			
		||||
        nodes_data.push(data)
 | 
			
		||||
        saveNodesFile(nodes_data) 
 | 
			
		||||
        nlog.step.end("add_nodes")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
const { __glob, __web } = require("./global-variables");
 | 
			
		||||
const { LogType } = require('loguix');
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
const { log } = require("console");
 | 
			
		||||
 | 
			
		||||
const alog = new LogType("Authentification")
 | 
			
		||||
 | 
			
		||||
@@ -60,13 +61,14 @@ module.exports.getDiscordUser = function (code, session) {
 | 
			
		||||
                    reject("NOT_IN_CLP")
 | 
			
		||||
                } else if(typeof userInfo.user == "undefined") {
 | 
			
		||||
                    reject("MIGRATE_ACCOUNT_ONLY")
 | 
			
		||||
                } else {
 | 
			
		||||
                }  else {
 | 
			
		||||
 | 
			
		||||
                    // Replace existing user from the DB file if exist
 | 
			
		||||
                    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
                    for (const user of userDB) {
 | 
			
		||||
                        if(user.user.id == userInfo.user.id) {	
 | 
			
		||||
                            userInfo.token = user.token
 | 
			
		||||
                    for (const userFromDB of userDB) {
 | 
			
		||||
                        if(userFromDB.user.id == userInfo.user.id) {	
 | 
			
		||||
                            userInfo.token = userFromDB.token
 | 
			
		||||
                            user.banned = userFromDB.banned
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                                               
 | 
			
		||||
@@ -74,10 +76,20 @@ module.exports.getDiscordUser = function (code, session) {
 | 
			
		||||
 | 
			
		||||
                    if(userInfo.user.id == "486943594893017119") {
 | 
			
		||||
                        user.admin = true;
 | 
			
		||||
                        user.banned = false;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                    Object.assign(user, userInfo);
 | 
			
		||||
                    resolve(user);
 | 
			
		||||
 | 
			
		||||
                    if(user.banned) {
 | 
			
		||||
                        reject("ACCOUNT_BANNED")
 | 
			
		||||
                        alog.log("Tentative de connexion d'un utilisateur banni : " + user.user.username)
 | 
			
		||||
                    } else {
 | 
			
		||||
                        resolve(user);
 | 
			
		||||
                    }
 | 
			
		||||
           
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }).catch(error => reject(error)) 
 | 
			
		||||
@@ -122,11 +134,16 @@ module.exports.removeSession = function (session) {
 | 
			
		||||
 | 
			
		||||
module.exports.checkUser = function (token) {
 | 
			
		||||
    
 | 
			
		||||
    var users = this.getUsers() 
 | 
			
		||||
    for(var user of users) {
 | 
			
		||||
            
 | 
			
		||||
        if(user[1].token.includes(token)) {
 | 
			
		||||
    
 | 
			
		||||
            return true
 | 
			
		||||
        if(user.token.includes(token)) {
 | 
			
		||||
        
 | 
			
		||||
            if(user.banned) {
 | 
			
		||||
                return false
 | 
			
		||||
            } else {
 | 
			
		||||
                return true
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -136,11 +153,17 @@ module.exports.checkUser = function (token) {
 | 
			
		||||
 | 
			
		||||
module.exports.getUser = function (token) {
 | 
			
		||||
    
 | 
			
		||||
        var users = this.getUsers() 
 | 
			
		||||
        for(var user of users) {
 | 
			
		||||
                
 | 
			
		||||
            if(user[1].token.includes(token)) {
 | 
			
		||||
        
 | 
			
		||||
                return user[1]
 | 
			
		||||
            if(user.token.includes(token)) {
 | 
			
		||||
                if(user.banned) {
 | 
			
		||||
                    return null
 | 
			
		||||
                } else {
 | 
			
		||||
                    return user
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
           
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
@@ -148,7 +171,7 @@ module.exports.getUser = function (token) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.getUsers = function () {
 | 
			
		||||
module.exports.getUsers = function() {
 | 
			
		||||
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
    return userDB
 | 
			
		||||
@@ -156,7 +179,7 @@ module.exports.getUsers = function () {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.getSimpleUsers = function () {
 | 
			
		||||
module.exports.getSimpleUsers = function() {
 | 
			
		||||
 | 
			
		||||
    var userList = new Array()
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
@@ -172,7 +195,7 @@ module.exports.getSimpleUsers = function () {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.getSimpleUser = function (token) {
 | 
			
		||||
module.exports.getSimpleUser = function(token) {
 | 
			
		||||
 | 
			
		||||
    const user = this.getUser(token)
 | 
			
		||||
 | 
			
		||||
@@ -184,8 +207,46 @@ module.exports.getSimpleUser = function (token) {
 | 
			
		||||
    return ({"username": user.user.username, "global_name":user.user.global_name, "avatar": user.user.avatar, "id": user.user.id, "admin": user.admin, "picture": user.picture})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.getOOBE = function(userId) {
 | 
			
		||||
    
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
        for (const user of userDB) {
 | 
			
		||||
            if(user.user.id == userId) {
 | 
			
		||||
               if(!user.oobe) {
 | 
			
		||||
                return true
 | 
			
		||||
               }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.addUser = function (user) {
 | 
			
		||||
module.exports.setOOBE = function(userId) {
 | 
			
		||||
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
    var selectedUser = null
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    for(var user of userDB) {
 | 
			
		||||
 | 
			
		||||
        if(userId == user.user.id) {
 | 
			
		||||
 | 
			
		||||
            selectedUser = user
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(!selectedUser) {
 | 
			
		||||
        return
 | 
			
		||||
    }
 | 
			
		||||
    userDB[userDB.indexOf(selectedUser)].oobe = true
 | 
			
		||||
 | 
			
		||||
    saveUsersFile(userDB)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.addUser = async function(user) {
 | 
			
		||||
    
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
    
 | 
			
		||||
@@ -203,46 +264,56 @@ module.exports.addUser = function (user) {
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
    if(selectedUser != null) {
 | 
			
		||||
    if(selectedUser) {
 | 
			
		||||
 | 
			
		||||
        userDB[selectedUser].token = user.token
 | 
			
		||||
        if(user.user.id == "486943594893017119") {
 | 
			
		||||
            userDB[selectedUser].banned = false
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        userDB.push(user)        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    saveUsersFile( userDB)
 | 
			
		||||
    var OPdest = __glob.PICTURE_DIR + "/" + user.user.id + ".png"
 | 
			
		||||
    if (fs.existsSync(OPdest)) {
 | 
			
		||||
        fs.rmSync(OPdest);
 | 
			
		||||
    }
 | 
			
		||||
    checkAllPictures()
 | 
			
		||||
    await checkAllPictures()
 | 
			
		||||
    updateUsers()
 | 
			
		||||
    alog.log("Ajout de " + user.user.username + " en tant qu'utilisateur avec le token : " + user.token)
 | 
			
		||||
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
module.exports.removeUser = function (token) {
 | 
			
		||||
module.exports.removeUser = function(id) {
 | 
			
		||||
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
    var selectedUser = null
 | 
			
		||||
    for (const user of userDB) {
 | 
			
		||||
        if(user.token == token) {
 | 
			
		||||
 | 
			
		||||
            selectedUser = user
 | 
			
		||||
 | 
			
		||||
    for(var user of userDB) {
 | 
			
		||||
 | 
			
		||||
        if(id == user.user.id) {
 | 
			
		||||
 | 
			
		||||
            selectedUser = userDB.indexOf(user)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    const index = userDB.indexOf(selectedUser)
 | 
			
		||||
    alog.log("Supression de " + selectedUser.user.username + " en tant qu'utilisateur avec le token : " + selectedUser.token)
 | 
			
		||||
 | 
			
		||||
    userDB.splice(index, 1)
 | 
			
		||||
    }
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
    alog.log("Supression de " + userDB[selectedUser].user.username + " en tant qu'utilisateur avec le token : " + userDB[selectedUser].token)
 | 
			
		||||
 | 
			
		||||
    userDB.splice(selectedUser, 1)
 | 
			
		||||
    saveUsersFile(userDB)
 | 
			
		||||
 | 
			
		||||
    updateUsers()
 | 
			
		||||
    
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
module.exports.removeToken = function (token) {
 | 
			
		||||
module.exports.removeToken = function(token) {
 | 
			
		||||
    
 | 
			
		||||
        const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
        var selectedUser = null
 | 
			
		||||
@@ -253,7 +324,7 @@ module.exports.removeToken = function (token) {
 | 
			
		||||
                selectedUser = user
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        const index = userDB.indexOf(selectedUser)
 | 
			
		||||
        
 | 
			
		||||
        alog.log("Supression du token de " + selectedUser.user.username + " en tant qu'utilisateur avec le token : " + selectedUser.token)
 | 
			
		||||
    
 | 
			
		||||
        const tokens = selectedUser.token
 | 
			
		||||
@@ -265,17 +336,17 @@ module.exports.removeToken = function (token) {
 | 
			
		||||
        
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.setAdmin = function (user) {
 | 
			
		||||
module.exports.setAdmin = function(id) {
 | 
			
		||||
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
 | 
			
		||||
    var selectedUser = null
 | 
			
		||||
 | 
			
		||||
    for(var userI of userDB) {
 | 
			
		||||
    for(var user of userDB) {
 | 
			
		||||
 | 
			
		||||
        if(user.user.id == userI.user.id) {
 | 
			
		||||
        if(id == user.user.id) {
 | 
			
		||||
 | 
			
		||||
            selectedUser = userDB.indexOf(userI)
 | 
			
		||||
            selectedUser = userDB.indexOf(user)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
@@ -295,10 +366,45 @@ module.exports.setAdmin = function (user) {
 | 
			
		||||
    saveUsersFile(userDB)
 | 
			
		||||
 | 
			
		||||
    updateUsers()
 | 
			
		||||
    alog.log("Ajout de " + user.user.username + " en tant qu'administrateur avec le token : " + user.token)
 | 
			
		||||
    alog.log("Ajout de " + userDB[selectedUser].user.username + " en tant qu'administrateur !")
 | 
			
		||||
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
module.exports.setBan = function(id) {
 | 
			
		||||
 | 
			
		||||
    const userDB = readUsersFile(__glob.USERS)
 | 
			
		||||
 | 
			
		||||
    var selectedUser = null
 | 
			
		||||
 | 
			
		||||
    for(var user of userDB) {
 | 
			
		||||
 | 
			
		||||
        if(id == user.user.id) {
 | 
			
		||||
 | 
			
		||||
            selectedUser = userDB.indexOf(user)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(!userDB[selectedUser].banned) {
 | 
			
		||||
 | 
			
		||||
        userDB[selectedUser].banned = true
 | 
			
		||||
        console.log("[Personnal Quote] - New Ban")
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        userDB[selectedUser].banned = false
 | 
			
		||||
        console.log("[Personnal Quote] - Remove Ban")
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    saveUsersFile(userDB)
 | 
			
		||||
 | 
			
		||||
    updateUsers()
 | 
			
		||||
    alog.log("Ajout de " + userDB[selectedUser].user.username + " en tant que banni !")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function updateUsers() {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,29 +2,76 @@ const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
 | 
			
		||||
const { __glob } = require("../modules/global-variables");
 | 
			
		||||
const { LogType } = require('loguix');
 | 
			
		||||
const discord = require("./discord-bot")
 | 
			
		||||
const fs = require('fs')
 | 
			
		||||
 | 
			
		||||
const dlog = new LogType("Queue-List")
 | 
			
		||||
 | 
			
		||||
var next = new Array()
 | 
			
		||||
var previous = new Array()
 | 
			
		||||
var current = null;
 | 
			
		||||
var shuffle = false
 | 
			
		||||
 | 
			
		||||
if(!fs.existsSync(__glob.PREVIOUS_FILE)) {
 | 
			
		||||
    fs.writeFileSync(__glob.PREVIOUS_FILE, JSON.stringify(new Array(), null, 2))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
    getList() {
 | 
			
		||||
 | 
			
		||||
        return next
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getPreviousList() {
 | 
			
		||||
        return getPreviousFile()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getCurrent() {
 | 
			
		||||
        return current
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    removeAll() {
 | 
			
		||||
        next = new Array()
 | 
			
		||||
        process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    destroy() {
 | 
			
		||||
 | 
			
		||||
        next = new Array()
 | 
			
		||||
        previous = new Array()
 | 
			
		||||
        current = null
 | 
			
		||||
        shuffle = false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    playQueue(data) {
 | 
			
		||||
        // Play the song with the index in the queue and delete it from the queue
 | 
			
		||||
 | 
			
		||||
        var index = data[0]
 | 
			
		||||
        var list = data[1]
 | 
			
		||||
 | 
			
		||||
        if(list == "next") {
 | 
			
		||||
 | 
			
		||||
            const song = next[index]
 | 
			
		||||
            next.splice(index, 1)
 | 
			
		||||
     
 | 
			
		||||
            return song
 | 
			
		||||
        } else if(list == "previous") {
 | 
			
		||||
   
 | 
			
		||||
            const song = getPreviousFile()[index]
 | 
			
		||||
        
 | 
			
		||||
            return song
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    changeQueue(index) {
 | 
			
		||||
        //PREVIOUS TO NEXT
 | 
			
		||||
 | 
			
		||||
        const song = getPreviousFile()[index]
 | 
			
		||||
        next.push(song)
 | 
			
		||||
 | 
			
		||||
        process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
 | 
			
		||||
    }   
 | 
			
		||||
 | 
			
		||||
    setShuffle(state) {
 | 
			
		||||
     
 | 
			
		||||
        shuffle = state
 | 
			
		||||
@@ -55,10 +102,15 @@ module.exports.List = class {
 | 
			
		||||
       
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    previous() {
 | 
			
		||||
 | 
			
		||||
        const song = previous[0]
 | 
			
		||||
        previous.splice(0, 1)
 | 
			
		||||
        const song = getPreviousFile()[0]
 | 
			
		||||
        var previousList = getPreviousFile()
 | 
			
		||||
        previousList.splice(0, 1)
 | 
			
		||||
        savePreviousFile(previousList)
 | 
			
		||||
 | 
			
		||||
        return song
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
@@ -70,8 +122,12 @@ module.exports.List = class {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    addCurrentToPrevious() {
 | 
			
		||||
 | 
			
		||||
        previous.unshift(current)
 | 
			
		||||
        if(current) {
 | 
			
		||||
            var previousList = getPreviousFile()
 | 
			
		||||
            previousList.unshift(current)
 | 
			
		||||
            savePreviousFile(previousList)
 | 
			
		||||
        }
 | 
			
		||||
       
 | 
			
		||||
 
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -88,7 +144,8 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
    havePreviousSongs() {
 | 
			
		||||
 | 
			
		||||
        if(previous.length == 0) {
 | 
			
		||||
        var previousList = getPreviousFile()
 | 
			
		||||
        if(previousList.length == 0) {
 | 
			
		||||
            return false
 | 
			
		||||
 | 
			
		||||
        } else{
 | 
			
		||||
@@ -97,6 +154,8 @@ module.exports.List = class {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    getNextSong() {
 | 
			
		||||
 | 
			
		||||
        const song = next[0]
 | 
			
		||||
@@ -106,6 +165,11 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    async add(song, interaction) {
 | 
			
		||||
 | 
			
		||||
        if(!song) {
 | 
			
		||||
            process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        dlog.log("Ajout d'un titre dans la liste de lecture : '" + song.title + "' de '" + song.author + "'")
 | 
			
		||||
        next.push(song)
 | 
			
		||||
@@ -155,21 +219,29 @@ module.exports.List = class {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    __previous_add(song) {
 | 
			
		||||
 | 
			
		||||
        previous.unshift(song)
 | 
			
		||||
        if(song) {
 | 
			
		||||
            var previousList = getPreviousFile()
 | 
			
		||||
            previousList.unshift(song)
 | 
			
		||||
            savePreviousFile(previousList)
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    __previous_remove(song) {
 | 
			
		||||
 | 
			
		||||
        const index = next.indexOf(song)
 | 
			
		||||
        previous.splice(index, 1)
 | 
			
		||||
        if(song) {
 | 
			
		||||
            var previousList = getPreviousFile()
 | 
			
		||||
            previousList.splice(previousList.indexOf(song), 1)
 | 
			
		||||
            savePreviousFile(previousList)
 | 
			
		||||
        }
 | 
			
		||||
      
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    __next_add(song) {
 | 
			
		||||
 | 
			
		||||
        next.unshift(song)
 | 
			
		||||
 | 
			
		||||
        if(song) {
 | 
			
		||||
            next.unshift(song)
 | 
			
		||||
        }
 | 
			
		||||
      
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async replaceList(data) {
 | 
			
		||||
@@ -188,7 +260,7 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async playlistAdd(playlist, interaction, userId, ) {
 | 
			
		||||
    async playlistAdd(playlist, interaction, userId, quick ) {
 | 
			
		||||
 | 
			
		||||
        var client = discord.getClient()
 | 
			
		||||
        let player = client.manager.players.get("137291455336022018")
 | 
			
		||||
@@ -221,13 +293,24 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            var numberExecuted = 0
 | 
			
		||||
            for(var song of playlist.videos) {
 | 
			
		||||
                if(song.uri) {
 | 
			
		||||
                    song.url = song.uri
 | 
			
		||||
                } 
 | 
			
		||||
                const song_finded = await client.manager.search(song.url)
 | 
			
		||||
                // Avoid if song not found
 | 
			
		||||
                if(!song_finded.tracks[0]) {
 | 
			
		||||
                    numberExecuted += 1 
 | 
			
		||||
                    continue
 | 
			
		||||
                }
 | 
			
		||||
                next.push(song_finded.tracks[0])
 | 
			
		||||
                process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
                numberExecuted++
 | 
			
		||||
                if(numberExecuted == playlist.videos.length) {
 | 
			
		||||
                    
 | 
			
		||||
                    process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
                }
 | 
			
		||||
              
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if(!player) { 
 | 
			
		||||
@@ -256,6 +339,11 @@ module.exports.List = class {
 | 
			
		||||
                player.play(next[0])
 | 
			
		||||
                this.remove(next[0])
 | 
			
		||||
             
 | 
			
		||||
            } else {
 | 
			
		||||
                if(quick) {
 | 
			
		||||
                    player.play(next[0])
 | 
			
		||||
                    this.remove(next[0])
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
          
 | 
			
		||||
@@ -266,3 +354,24 @@ module.exports.List = class {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * @returns {Array} 
 | 
			
		||||
 */
 | 
			
		||||
function getPreviousFile() {
 | 
			
		||||
    return JSON.parse(fs.readFileSync(__glob.PREVIOUS_FILE, 'utf8'))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function savePreviousFile(db) {
 | 
			
		||||
 | 
			
		||||
    // Add a security to avoid a too big file
 | 
			
		||||
    if(db.length > 25) {
 | 
			
		||||
        db.splice(25, db.length - 25)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    fs.writeFileSync(__glob.PREVIOUS_FILE, (JSON.stringify(db, null, 2)))
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -9,6 +9,12 @@ const { Metric } = require("webmetrik");
 | 
			
		||||
 | 
			
		||||
const list = new List()
 | 
			
		||||
 | 
			
		||||
module.exports.getSong = async function (url) {
 | 
			
		||||
    var client = discord.getClient()
 | 
			
		||||
    const songs = await client.manager.search(url)
 | 
			
		||||
    return songs.tracks[0]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.play = async function (client, interaction) {
 | 
			
		||||
 | 
			
		||||
    if(interaction) {
 | 
			
		||||
@@ -187,12 +193,12 @@ module.exports.getState = function(client, interaction) {
 | 
			
		||||
        
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.playPlaylist = function (id, data) {
 | 
			
		||||
module.exports.playPlaylist = function (id, data, quick) {
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    const playlist = {}
 | 
			
		||||
    playlist.videos = data
 | 
			
		||||
    list.playlistAdd(playlist, null, id)
 | 
			
		||||
    list.playlistAdd(playlist, null, id, quick)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -241,6 +247,10 @@ module.exports.addSong = async function (data, userId, quick, playlist) {
 | 
			
		||||
        
 | 
			
		||||
        player.play(songs.tracks[0])
 | 
			
		||||
 | 
			
		||||
        if(list.getCurrent()) {
 | 
			
		||||
 | 
			
		||||
            list.__previous_add(list.getCurrent())
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        if(!player.playing && player.paused == false) {
 | 
			
		||||
@@ -260,15 +270,20 @@ module.exports.addSong = async function (data, userId, quick, playlist) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.addSongsFromPlaylist = async function (data, userId) {
 | 
			
		||||
module.exports.addSongsFromPlaylist = async function (data, userId, quick) {
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
    var playlist = await checkPlaylist(data)
 | 
			
		||||
 | 
			
		||||
    if(playlist) {
 | 
			
		||||
 | 
			
		||||
        list.playlistAdd(playlist, null, userId)
 | 
			
		||||
        if(quick) {
 | 
			
		||||
            list.removeAll()
 | 
			
		||||
            list.playlistAdd(playlist, null, userId, true)
 | 
			
		||||
        } else {
 | 
			
		||||
            list.playlistAdd(playlist, null, userId)
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
@@ -329,6 +344,7 @@ module.exports.skip = function (client, interaction) {
 | 
			
		||||
        if(player) {
 | 
			
		||||
 | 
			
		||||
            player.stop()
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
@@ -668,11 +684,13 @@ module.exports.updateMusicState = function (client, action) {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        data["queue"] = list.getList();
 | 
			
		||||
        
 | 
			
		||||
        data["isOnline"] = true
 | 
			
		||||
       
 | 
			
		||||
    }  
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    data["previous"] = list.getPreviousList();
 | 
			
		||||
 | 
			
		||||
    if(action == "end") {
 | 
			
		||||
 | 
			
		||||
        data["current"] = null;
 | 
			
		||||
@@ -738,6 +756,26 @@ module.exports.leave = function (client, interaction) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.moveOut = function(userId) {
 | 
			
		||||
    var memberVoices = discord.getMemberVoices()
 | 
			
		||||
    var channelId = memberVoices.get(userId)
 | 
			
		||||
 | 
			
		||||
    console.log(channelId)
 | 
			
		||||
 | 
			
		||||
    if(channelId) {
 | 
			
		||||
        
 | 
			
		||||
        var client = discord.getClient()
 | 
			
		||||
        var player = client.manager.players.get("137291455336022018")
 | 
			
		||||
        if(player) { 
 | 
			
		||||
                   
 | 
			
		||||
            player.voiceChannel = channelId
 | 
			
		||||
            player.connect()
 | 
			
		||||
           
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FINI
 | 
			
		||||
 | 
			
		||||
async function checkPlaylist (song_name) {
 | 
			
		||||
@@ -754,6 +792,8 @@ async function checkPlaylist (song_name) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function playStats(username) {
 | 
			
		||||
    var userMusicPlayed = new Metric("userMusicPlayed_" + username, "Nombre de musiques jouées par l'utilisateur : " + username)
 | 
			
		||||
    userMusicPlayed.setValue(userMusicPlayed.getValue() + 1)
 | 
			
		||||
 
 | 
			
		||||
@@ -3,49 +3,113 @@ const { __glob } = require("../modules/global-variables");
 | 
			
		||||
const { LogType } = require("loguix");
 | 
			
		||||
const subplayer = require("./sub-player")
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
const { randomUUID } = require("crypto");
 | 
			
		||||
const { url } = require("inspector");
 | 
			
		||||
var playlists = {}
 | 
			
		||||
const plog = new LogType("Playlist-Manager")
 | 
			
		||||
 | 
			
		||||
check()
 | 
			
		||||
 | 
			
		||||
module.exports.getUser = function (id) {
 | 
			
		||||
 | 
			
		||||
module.exports.getUser = function (userId) {
 | 
			
		||||
    check()
 | 
			
		||||
    if(!playlists[id]) {
 | 
			
		||||
        plog.log("Ajout de l'utilisateur \"" + id  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[id] = {}
 | 
			
		||||
    var allPlaylist = new Object()
 | 
			
		||||
    // Inject "shared" playlist object in allPlaylist
 | 
			
		||||
 | 
			
		||||
    if(playlists[userId]) {
 | 
			
		||||
        // Copy the keys of the user playlist to the allPlaylist object
 | 
			
		||||
        for(var key in playlists[userId]) {
 | 
			
		||||
            allPlaylist[key] = playlists[userId][key]
 | 
			
		||||
        }
 | 
			
		||||
        // Copy the keys of the shared playlist to the allPlaylist object
 | 
			
		||||
        for(var key in playlists["shared"]) {
 | 
			
		||||
            allPlaylist[key] = playlists["shared"][key]
 | 
			
		||||
        }
 | 
			
		||||
    }   
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
    
 | 
			
		||||
    if(!playlists[userId]) {
 | 
			
		||||
        plog.log("Ajout de l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[userId] = {}
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
        return playlists[id]
 | 
			
		||||
        
 | 
			
		||||
        return allPlaylist
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + id  + "\" existe déjà dans la base de donnée Playlist !")
 | 
			
		||||
        return playlists[id]
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" existe déjà dans la base de donnée Playlist !")
 | 
			
		||||
        
 | 
			
		||||
        return allPlaylist
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.addPlaylist = function (id, name) {
 | 
			
		||||
module.exports.addPlaylist = function (userId, data) {
 | 
			
		||||
    check()
 | 
			
		||||
    if(!playlists[id][name]) {
 | 
			
		||||
        plog.log("Ajout de la playlist à l'utilisateur \"" + id  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[id][name] = []
 | 
			
		||||
    var name = data.name
 | 
			
		||||
    var source = data.source
 | 
			
		||||
    var content = []
 | 
			
		||||
 | 
			
		||||
    if(source == "shared") {
 | 
			
		||||
        userId = "shared"
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var alreadyExist = false
 | 
			
		||||
 | 
			
		||||
    for(var pIndex in playlists[userId]) {
 | 
			
		||||
        if(playlists[userId][pIndex].title == name) {
 | 
			
		||||
            alreadyExist = true
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if(!alreadyExist) {
 | 
			
		||||
        plog.log("Ajout de la playlist '" + name + "' à l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        var id = randomUUID().toString()
 | 
			
		||||
 | 
			
		||||
        if(source == "youtube") {
 | 
			
		||||
            content = data.url
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        playlists[userId][id] = {
 | 
			
		||||
            "title": name,
 | 
			
		||||
            "source": data.source,
 | 
			
		||||
            "content": content
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + id  + "\" à déjà une playlist avec le nom "+ name + " dans la base de donnée Playlist !")
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" à déjà une playlist avec le nom " +  name + " dans la base de donnée Playlist !")
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("PLAYLIST_REFRESH")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.copyPlaylist = function (id, from, dest) {
 | 
			
		||||
    this.getUser(dest)
 | 
			
		||||
module.exports.copyPlaylist = function (userId, from, dest) {
 | 
			
		||||
    check()
 | 
			
		||||
    let playlistDest = playlists[dest][from]
 | 
			
		||||
    if(!playlistDest) {
 | 
			
		||||
        plog.log("Ajout de la playlist à l'utilisateur \"" + id  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[dest][from] = playlists[id][from]
 | 
			
		||||
    this.getUser(dest)
 | 
			
		||||
 | 
			
		||||
    userId = checkSharedMusic(from, userId)
 | 
			
		||||
 | 
			
		||||
    var alreadyExist = false
 | 
			
		||||
 | 
			
		||||
    for(var pIndex in playlists[dest]) {
 | 
			
		||||
        if(playlists[dest][pIndex].title == playlists[userId][from].title) {
 | 
			
		||||
            alreadyExist = true
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var id = randomUUID().toString()
 | 
			
		||||
 
 | 
			
		||||
    if(!alreadyExist) {
 | 
			
		||||
        plog.log("Ajout de la playlist à l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[dest][id] = playlists[userId][from]
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
    } else {
 | 
			
		||||
@@ -54,68 +118,134 @@ module.exports.copyPlaylist = function (id, from, dest) {
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("PLAYLIST_REFRESH")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.removePlaylist = function (id, name) {
 | 
			
		||||
module.exports.removePlaylist = function (userId, id) {
 | 
			
		||||
    check()
 | 
			
		||||
    if(playlists[id][name]) {
 | 
			
		||||
        plog.log("Supression de la playlist à l'utilisateur \"" + id  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        delete playlists[id][name]
 | 
			
		||||
 | 
			
		||||
    userId = checkSharedMusic(id, userId)
 | 
			
		||||
 | 
			
		||||
    if(playlists[userId][id]) {
 | 
			
		||||
        plog.log("Supression de la playlist à l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
 | 
			
		||||
        delete playlists[userId][id]
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + id  + "\" n'a pas une playlist avec le nom "+ name + " dans la base de donnée Playlist !")
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" n'a pas une playlist avec l'identifiant  "+ id + " dans la base de donnée Playlist !")
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    process.emit("PLAYLIST_REFRESH")
 | 
			
		||||
 | 
			
		||||
module.exports.addSong = function (id, name, song) {
 | 
			
		||||
    check()
 | 
			
		||||
    if(playlists[id][name]) {
 | 
			
		||||
        
 | 
			
		||||
        plog.log("Ajout d'une chanson dans la playlist '" + name + "' à l'utilisateur \"" + id  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        
 | 
			
		||||
        playlists[id][name].push(song)
 | 
			
		||||
        
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + id  + "\" n'a pas une playlist avec le nom "+ name + " dans la base de donnée Playlist !")
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.removeSong = function (id, name, song ) {
 | 
			
		||||
module.exports.renamePlaylist = function (userId, id, newName) {
 | 
			
		||||
    check()
 | 
			
		||||
    if(playlists[id][name]) {
 | 
			
		||||
        plog.log("Supression d'une chanson dans la playlist '" + name + "' à l'utilisateur \"" + id  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[id][name].splice(playlists[id][name].indexOf(song), 1)
 | 
			
		||||
 | 
			
		||||
    userId = checkSharedMusic(id, userId)
 | 
			
		||||
 | 
			
		||||
    if(playlists[userId][id]) {
 | 
			
		||||
        plog.log("Renommage de la playlist à l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        playlists[userId][id].title = newName
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + id  + "\" n'a pas une playlist avec le nom "+ name + " dans la base de donnée Playlist !")
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" n'a pas une playlist avec l'identifiant  "+ id + " dans la base de donnée Playlist !")
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("PLAYLIST_REFRESH")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
module.exports.addSong = async function (userId, id, urlSong) {
 | 
			
		||||
    check()
 | 
			
		||||
 | 
			
		||||
    userId = checkSharedMusic(id, userId)
 | 
			
		||||
 | 
			
		||||
    if(playlists[userId][id]) {
 | 
			
		||||
    
 | 
			
		||||
        // Check if it's not a youtube playlist 
 | 
			
		||||
 | 
			
		||||
        if(playlists[userId][id].source != "youtube") {
 | 
			
		||||
            
 | 
			
		||||
            plog.log("Ajout d'une chanson dans la playlist '" + id + "' à l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
                
 | 
			
		||||
            var song = await subplayer.getSong(urlSong)
 | 
			
		||||
          
 | 
			
		||||
            playlists[userId][id].content.push(song)
 | 
			
		||||
            
 | 
			
		||||
            fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
 | 
			
		||||
        } else {
 | 
			
		||||
                
 | 
			
		||||
            plog.log("La playlist '" + id + "' à l'utilisateur \"" + userId  + "\" est une playlist youtube, vous ne pouvez pas ajouter de chanson à une playlist youtube !")
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" n'a pas une playlist avec le nom "+ id + " dans la base de donnée Playlist !")
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("PLAYLIST_REFRESH")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.playPlaylist = function (id, name) {
 | 
			
		||||
 | 
			
		||||
module.exports.removeSong = function (userId, id, identifier ) {
 | 
			
		||||
    check()
 | 
			
		||||
    if(playlists[id][name]) {
 | 
			
		||||
        plog.log("Ajout de la playlist à l'utilisateur \"" + id  + "\" dans la liste de lecture !")
 | 
			
		||||
 | 
			
		||||
    userId = checkSharedMusic(id, userId)
 | 
			
		||||
 | 
			
		||||
    if(playlists[userId][id]) {
 | 
			
		||||
        plog.log("Supression d'une chanson dans la playlist '" + id + "' à l'utilisateur \"" + userId  + "\" dans la base de donnée Playlist !")
 | 
			
		||||
        
 | 
			
		||||
        subplayer.playPlaylist(id, playlists[id][name])
 | 
			
		||||
        // Check with the identifier the song to remove
 | 
			
		||||
        
 | 
			
		||||
        for(var song of playlists[userId][id].content) {
 | 
			
		||||
            if(song.identifier == identifier) {
 | 
			
		||||
                playlists[userId][id].content.splice(playlists[userId][id].content.indexOf(song), 1)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + id  + "\" n'a pas une playlist avec le nom "+ name + " dans la base de donnée Playlist !")
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" n'a pas une playlist avec le nom "+ id + " dans la base de donnée Playlist !")
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("PLAYLIST_REFRESH")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.playPlaylist = function (userId, id, quick) {
 | 
			
		||||
    check()
 | 
			
		||||
 | 
			
		||||
    userId = checkSharedMusic(id, userId)
 | 
			
		||||
 | 
			
		||||
    if(playlists[userId][id]) {
 | 
			
		||||
        plog.log("Ajout de la playlist à l'utilisateur \"" + userId  + "\" dans la liste de lecture !")
 | 
			
		||||
        
 | 
			
		||||
        subplayer.playPlaylist(id, playlists[userId][id].content, quick)
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        plog.log("L'utilisateur \"" + userId  + "\" n'a pas une playlist avec le nom "+ id + " dans la base de donnée Playlist !")
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -127,6 +257,20 @@ function check() {
 | 
			
		||||
        playlists = JSON.parse(fs.readFileSync(__glob.PLAYLIST))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify(playlists, null, 2))
 | 
			
		||||
        fs.writeFileSync(__glob.PLAYLIST, JSON.stringify({
 | 
			
		||||
            "shared": {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }, null, 2))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function checkSharedMusic(id, originalUserId) {
 | 
			
		||||
    for(var playlist in playlists["shared"]) {
 | 
			
		||||
        if(playlist == id) {
 | 
			
		||||
            return "shared"  
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return originalUserId
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +0,0 @@
 | 
			
		||||
const { __glob } = require("../modules/global-variables");
 | 
			
		||||
const { LogType } = require("loguix");
 | 
			
		||||
var { List } = require("./sub-list")
 | 
			
		||||
const discord = require("./discord-bot")
 | 
			
		||||
const subplayer = require("./sub-player")
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
const { type } = require("os");
 | 
			
		||||
var radios = []
 | 
			
		||||
const plog = new LogType("Radio-Manager")
 | 
			
		||||
 | 
			
		||||
checkRadioFile()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.get = function () {
 | 
			
		||||
 | 
			
		||||
    checkRadioFile()
 | 
			
		||||
    return radios
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.add = function (data) {
 | 
			
		||||
    
 | 
			
		||||
    var radios_data = readRadioFile()
 | 
			
		||||
            
 | 
			
		||||
    radios_data.push(data)
 | 
			
		||||
    fs.writeFileSync(__glob.RADIO, JSON.stringify(radios_data, null, 2))
 | 
			
		||||
    
 | 
			
		||||
    return radios
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.remove = function(data) {
 | 
			
		||||
 | 
			
		||||
            var radios_data = readRadioFile()
 | 
			
		||||
 | 
			
		||||
            var radIndex = -1
 | 
			
		||||
 | 
			
		||||
            for(var radio of radios_data) {
 | 
			
		||||
 | 
			
		||||
                if(data.uri == radio.uri) {
 | 
			
		||||
 | 
			
		||||
                    radIndex = radios_data.indexOf(radio)
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            radios_data.splice(radIndex, 1)
 | 
			
		||||
            
 | 
			
		||||
           saveRadioFile(radios_data)
 | 
			
		||||
           
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function saveRadioFile(data) {
 | 
			
		||||
 | 
			
		||||
    fs.writeFileSync(__glob.RADIO, JSON.stringify(data, null, 2))
 | 
			
		||||
}   
 | 
			
		||||
 | 
			
		||||
function readRadioFile() {
 | 
			
		||||
 | 
			
		||||
    if(fs.existsSync(__glob.RADIO)) {
 | 
			
		||||
            
 | 
			
		||||
        return JSON.parse(fs.readFileSync(__glob.RADIO))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function checkRadioFile() {
 | 
			
		||||
 | 
			
		||||
    if(fs.existsSync(__glob.RADIO)) {
 | 
			
		||||
 | 
			
		||||
        radios = JSON.parse(fs.readFileSync(__glob.RADIO))
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        fs.writeFileSync(__glob.RADIO, JSON.stringify(radios, null, 2))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -5,7 +5,7 @@ const auth = require("./sub-auth");
 | 
			
		||||
const cook = require("cookie")
 | 
			
		||||
const wlog = new LogType("Web")
 | 
			
		||||
const subplayer = require('./sub-player');
 | 
			
		||||
const subradio = require("./sub-radio.js")
 | 
			
		||||
 | 
			
		||||
const { List } = require("./sub-list")
 | 
			
		||||
const subplaylist = require("./sub-playlist")
 | 
			
		||||
const nodesfinder = require("./nodes-finder")
 | 
			
		||||
@@ -13,6 +13,14 @@ const { Server } = require("socket.io")
 | 
			
		||||
var fs = require("fs")
 | 
			
		||||
var path = require("path")
 | 
			
		||||
const { Metric } = require("webmetrik");
 | 
			
		||||
const markdownit = require("markdown-it")({
 | 
			
		||||
    html: true,
 | 
			
		||||
    linkify: true,
 | 
			
		||||
    typographer: true
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const Genius = require("genius-lyrics");
 | 
			
		||||
const GClient = new Genius.Client("OHOV9c0B4uuyfWTK2w2YRliC9iyPjjF2Kk6ijCtZ2RtqfkZ2JpntnO2fwraF1A5h");
 | 
			
		||||
 | 
			
		||||
module.exports.WebServer = class {
 | 
			
		||||
 | 
			
		||||
@@ -170,20 +178,18 @@ function IOConnection(io) {
 | 
			
		||||
    
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    process.on("UPDATE_RADIO", () => {
 | 
			
		||||
 | 
			
		||||
    process.on("PLAYLIST_REFRESH", () => {
 | 
			
		||||
        if(io) {
 | 
			
		||||
 | 
			
		||||
            const radioList = subradio.get()
 | 
			
		||||
            AlwaysRequest("ALL_RADIO", radioList)
 | 
			
		||||
        }    
 | 
			
		||||
 | 
			
		||||
            AlwaysRequest("PLAYLIST_REFRESH", "OK")
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    process.on("MUSIC_UPDATE_STATE", () => {
 | 
			
		||||
        if(io) {
 | 
			
		||||
            const data = subplayer.updateMusicState()
 | 
			
		||||
            AlwaysRequest("MUSIC_STATE", data)
 | 
			
		||||
        
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
@@ -201,7 +207,12 @@ function IOConnection(io) {
 | 
			
		||||
            const online_users_data = auth.getSimpleUser(token)
 | 
			
		||||
                
 | 
			
		||||
            if(online_users_data) {
 | 
			
		||||
                usersOnline.push(online_users_data)
 | 
			
		||||
                // Check if user is already connected and if not push it
 | 
			
		||||
                if(!usersOnline.find(item => item.username == online_users_data.username)) {
 | 
			
		||||
                    usersOnline.push(online_users_data)
 | 
			
		||||
     
 | 
			
		||||
                }
 | 
			
		||||
        
 | 
			
		||||
                alog.log(online_users_data.username + " - Connexion du serveur avec le socket : " + socket.id + " - " + socket.handshake.address + " - " + socket.handshake.headers["user-agent"])
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -271,15 +282,7 @@ function IOConnection(io) {
 | 
			
		||||
            GetRequest("DISCONNECT", () => {
 | 
			
		||||
                subplayer.leave()
 | 
			
		||||
                GetAnswer("DISCONNECT", "OK")
 | 
			
		||||
                sendUserNotification("à déconnecté le Bot de son salon vocal !")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            GetRequest("RESTART", () => {
 | 
			
		||||
                const pm2 = require('pm2');
 | 
			
		||||
                pm2.restart('SubSonics - Bot Discord')
 | 
			
		||||
                sendUserNotification("à redémarré le Bot !")
 | 
			
		||||
                GetAnswer("RESTART", "OK")
 | 
			
		||||
            
 | 
			
		||||
          
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            GetRequest("NODES", () => {
 | 
			
		||||
@@ -292,11 +295,26 @@ function IOConnection(io) {
 | 
			
		||||
                AlwaysRequest("ALL_CONNECTED_USER", usersOnline)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            GetRequest("ALL_RADIO", async () => {
 | 
			
		||||
                GetAnswer("ALL_RADIO", "OK")
 | 
			
		||||
                AlwaysRequest("ALL_RADIO", await subradio.get())
 | 
			
		||||
            GetRequest("README", () => {   
 | 
			
		||||
                var content = markdownit.render(fs.readFileSync(__glob.README).toString()) 
 | 
			
		||||
                GetAnswer("README", content)
 | 
			
		||||
              
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            GetRequest("OOBE_CHECK", () => {
 | 
			
		||||
                GetAnswer("OOBE_CHECK", auth.getOOBE(user.user.id))
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            GetRequest("OOBE_VALID", () => {
 | 
			
		||||
                auth.setOOBE(user.user.id)
 | 
			
		||||
                GetAnswer("OOBE_VALID", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
            GetRequest("MOVEOUT", () => {
 | 
			
		||||
                subplayer.moveOut(user.user.id)
 | 
			
		||||
                GetAnswer("MOVEOUT", "OK")
 | 
			
		||||
            })
 | 
			
		||||
            
 | 
			
		||||
            PostRequest("SEEK", (data) => {
 | 
			
		||||
                subplayer.seek(data)
 | 
			
		||||
@@ -308,12 +326,34 @@ function IOConnection(io) {
 | 
			
		||||
                PostAnswer("VOLUME", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("PLAY_QUEUE", (data) => { 
 | 
			
		||||
                var sublist = new List()  
 | 
			
		||||
                subplayer.addSong(sublist.playQueue(data), user.user.id, true)
 | 
			
		||||
                PostAnswer("PLAY_QUEUE", "OK")
 | 
			
		||||
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("CHANGE_QUEUE", (data) => {
 | 
			
		||||
                var sublist = new List()
 | 
			
		||||
                sublist.changeQueue(data)
 | 
			
		||||
                PostAnswer("CHANGE_QUEUE", "OK")
 | 
			
		||||
           
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("DELETE_QUEUE", (data) => {
 | 
			
		||||
                var sublist = new List()
 | 
			
		||||
                sublist.removeByIndex(data)
 | 
			
		||||
 | 
			
		||||
                PostAnswer("DELETE_QUEUE", "OK")
 | 
			
		||||
                sendUserNotification("à supprimé un titre de la file d'attente !")
 | 
			
		||||
 
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("DELETE_ALL_QUEUE", () => {
 | 
			
		||||
                var sublist = new List()
 | 
			
		||||
                sublist.removeAll()
 | 
			
		||||
 | 
			
		||||
                PostAnswer("DELETE_QUEUE", "OK")
 | 
			
		||||
        
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("MOVE_QUEUE", (data) => {
 | 
			
		||||
@@ -321,7 +361,7 @@ function IOConnection(io) {
 | 
			
		||||
                sublist.moveUp(data)
 | 
			
		||||
 | 
			
		||||
                PostAnswer("MOVE_QUEUE", "OK")
 | 
			
		||||
                sendUserNotification("à déplacé un titre de la file d'attente !")
 | 
			
		||||
      
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("MOVE_QUEUE_BY_ENTIRE", (data) => {
 | 
			
		||||
@@ -329,7 +369,7 @@ function IOConnection(io) {
 | 
			
		||||
                sublist.replaceList(data)
 | 
			
		||||
 | 
			
		||||
                PostAnswer("MOVE_QUEUE_BY_ENTIRE", "OK")
 | 
			
		||||
                sendUserNotification("à déplacé un titre tout au début de la file d'attente : <strong>" + data.title + "</strong> !")
 | 
			
		||||
            
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("REPORT", (data) => {
 | 
			
		||||
@@ -337,7 +377,7 @@ function IOConnection(io) {
 | 
			
		||||
                data.username = user
 | 
			
		||||
                subplayer.report(null, null, data)
 | 
			
		||||
                PostAnswer("REPORT", "OK")
 | 
			
		||||
                sendUserNotification("à signalé un bug et a été envoyé !")
 | 
			
		||||
             
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("SEARCH", async (data) => {
 | 
			
		||||
@@ -348,38 +388,46 @@ function IOConnection(io) {
 | 
			
		||||
            PostRequest("ADD_SONG", async (data) => {
 | 
			
		||||
                subplayer.addSong(data, user.user.id)
 | 
			
		||||
                PostAnswer("ADD_SONG", "OK")
 | 
			
		||||
                sendUserNotification("à ajouté un titre à la file d'attente : <strong>" + data.title + "</strong> !")
 | 
			
		||||
             
 | 
			
		||||
                playStats(user.user.username)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("ADD_SONG_NOW", async (data) => {
 | 
			
		||||
                subplayer.addSong(data, user.user.id, true)
 | 
			
		||||
                PostAnswer("ADD_SONG_NOW", "OK")
 | 
			
		||||
                sendUserNotification("à lancé un titre : <strong>" + data.title + "</strong> !")
 | 
			
		||||
                
 | 
			
		||||
                playStats(user.user.username)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("FP_ADD_SONG", async (data) => {
 | 
			
		||||
                subplayer.addSong(data, user.user.id, false, true)
 | 
			
		||||
                PostAnswer("FP_ADD_SONG", "OK")
 | 
			
		||||
                sendUserNotification("à ajouté un titre à la file d'attente : <strong>" + data.title + "</strong> !")
 | 
			
		||||
              
 | 
			
		||||
                playStats(user.user.username)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("FP_ADD_SONG_NOW", async (data) => {
 | 
			
		||||
                subplayer.addSong(data, user.user.id, true, true)
 | 
			
		||||
                PostAnswer("FP_ADD_SONG_NOW", "OK")
 | 
			
		||||
                sendUserNotification("à lancé une titre : <strong>" + data.title + "</strong> !")
 | 
			
		||||
               
 | 
			
		||||
                playStats(user.user.username)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("PLAY_PLAYLIST", async (data) => {
 | 
			
		||||
                subplaylist.playPlaylist(user.user.id, data)
 | 
			
		||||
                PostAnswer("PLAY_PLAYLIST", "OK")
 | 
			
		||||
                sendUserNotification("à ajouté une playlist à la file d'attente !")
 | 
			
		||||
               
 | 
			
		||||
                playStats(user.user.username)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("PLAY_PLAYLIST_NOW", async (data) => {
 | 
			
		||||
                subplaylist.playPlaylist(user.user.id, data, true)
 | 
			
		||||
                PostAnswer("PLAY_PLAYLIST_NOW", "OK")
 | 
			
		||||
 | 
			
		||||
                playStats(user.user.username)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            PostRequest("CREATE_PLAYLIST", async (data) => {
 | 
			
		||||
                subplaylist.addPlaylist(user.user.id, data)
 | 
			
		||||
                socket.emit("DO_UPDATE_PLAYLIST")
 | 
			
		||||
@@ -393,31 +441,70 @@ function IOConnection(io) {
 | 
			
		||||
                PostAnswer("DELETE_PLAYLIST", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("FP_PLAY_PLAYLIST", async (data) => {  
 | 
			
		||||
                subplayer.addSongsFromPlaylist(data, user.user.id)
 | 
			
		||||
                PostAnswer("FP_PLAY_PLAYLIST", "OK")
 | 
			
		||||
                sendUserNotification("à ajouté une playlist à la file d'attente !")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("SEND_PLAYLIST", async (data) => {
 | 
			
		||||
                subplaylist.copyPlaylist(user.user.id, data.key, data.dest)
 | 
			
		||||
                socket.emit("DO_UPDATE_PLAYLIST")
 | 
			
		||||
                PostAnswer("SEND_PLAYLIST", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("RENAME_PLAYLIST", async (data) => {
 | 
			
		||||
                subplaylist.renamePlaylist(user.user.id, data.id, data.name)
 | 
			
		||||
                socket.emit("DO_UPDATE_PLAYLIST")
 | 
			
		||||
                PostAnswer("RENAME_PLAYLIST", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("ADD_SONG_TO_PLAYLIST", async (data) => {
 | 
			
		||||
                subplaylist.addSong(user.user.id, data.data, data.song)
 | 
			
		||||
                subplaylist.addSong(user.user.id, data.id, data.url)
 | 
			
		||||
                socket.emit("DO_UPDATE_PLAYLIST")
 | 
			
		||||
                PostAnswer("ADD_SONG_TO_PLAYLIST", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("DELETE_SONG_TO_PLAYLIST", async (data) => {
 | 
			
		||||
                subplaylist.removeSong(user.user.id, data.data, data.song)
 | 
			
		||||
                subplaylist.removeSong(user.user.id, data.id, data.identifier)
 | 
			
		||||
                socket.emit("DO_UPDATE_PLAYLIST")
 | 
			
		||||
                PostAnswer("DELETE_SONG_TO_PLAYLIST", "OK")
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            PostRequest("FP_PLAY_PLAYLIST", async (data) => {  
 | 
			
		||||
                subplayer.addSongsFromPlaylist(data, user.user.id)
 | 
			
		||||
                PostAnswer("FP_PLAY_PLAYLIST", "OK")
 | 
			
		||||
               
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("FP_PLAY_PLAYLIST_NOW", async (data) => {  
 | 
			
		||||
                subplayer.addSongsFromPlaylist(data, user.user.id, true)
 | 
			
		||||
                PostAnswer("FP_PLAY_PLAYLIST", "OK")
 | 
			
		||||
          
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            PostRequest("LYRICS", async (data) => {
 | 
			
		||||
                const searches = await GClient.songs.search(data);
 | 
			
		||||
              
 | 
			
		||||
                if(!searches) {
 | 
			
		||||
                    PostAnswer("LYRICS", null)
 | 
			
		||||
                    return
 | 
			
		||||
                }
 | 
			
		||||
                const firstSong = searches[0];
 | 
			
		||||
                if(!firstSong) {
 | 
			
		||||
                    PostAnswer("LYRICS", null)
 | 
			
		||||
                    return
 | 
			
		||||
                    
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                const lyrics = await firstSong.lyrics();
 | 
			
		||||
                if(!lyrics) {
 | 
			
		||||
                    PostAnswer("LYRICS", null)
 | 
			
		||||
                    return
 | 
			
		||||
                }
 | 
			
		||||
              
 | 
			
		||||
                PostAnswer("LYRICS", lyrics)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
          
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            if(user.admin == true) {
 | 
			
		||||
                GetRequest("LOGS", () => {
 | 
			
		||||
                    const logs_data = new Array()
 | 
			
		||||
@@ -455,37 +542,6 @@ function IOConnection(io) {
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                PostRequest("RADIO/ADD", async (data) => {
 | 
			
		||||
                    const music_data = await (await subplayer.search(data)).results.tracks[0]
 | 
			
		||||
 | 
			
		||||
                    var radioContains = null
 | 
			
		||||
                    
 | 
			
		||||
                    for(var title of subradio.get()) {
 | 
			
		||||
 | 
			
		||||
                        if(title.uri == music_data.uri) {
 | 
			
		||||
 | 
			
		||||
                            radioContains = true
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
 | 
			
		||||
                    if(!radioContains) {
 | 
			
		||||
 | 
			
		||||
                        subradio.add(music_data)
 | 
			
		||||
                        console.log("[Radio] - ADD : " + data)
 | 
			
		||||
 | 
			
		||||
                    } else {
 | 
			
		||||
 | 
			
		||||
                        subradio.remove(music_data)
 | 
			
		||||
                        console.log("[Radio] - REMOVE : " + data)
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    PostAnswer("RADIO/ADD", "OK")
 | 
			
		||||
                    process.emit("UPDATE_RADIO")
 | 
			
		||||
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
                PostRequest("USERS/ADMIN", (data) => {
 | 
			
		||||
                    auth.setAdmin(data)
 | 
			
		||||
                    PostAnswer("USERS/ADMIN", "OK")
 | 
			
		||||
@@ -493,13 +549,29 @@ function IOConnection(io) {
 | 
			
		||||
                    AdminRequest("USERS", users_data)
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
                PostRequest("USERS/BAN", (data) => {
 | 
			
		||||
                    auth.setBan(data)
 | 
			
		||||
                    PostAnswer("USERS/BAN", "OK")
 | 
			
		||||
                    const users_data = auth.getUsers()
 | 
			
		||||
                    AdminRequest("USERS", users_data)
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
                PostRequest("USERS/DELETE", (data) => {
 | 
			
		||||
                    auth.removeUser(data.token)
 | 
			
		||||
                    auth.removeUser(data)
 | 
			
		||||
                    PostAnswer("USERS/DELETE", "OK")
 | 
			
		||||
                    const users_data = auth.getUsers()
 | 
			
		||||
                    AdminRequest("USERS", users_data)
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
                GetRequest("RESTART", () => {
 | 
			
		||||
                    const pm2 = require('pm2');
 | 
			
		||||
                    pm2.restart('Subsonics')
 | 
			
		||||
             
 | 
			
		||||
                    GetAnswer("RESTART", "OK")
 | 
			
		||||
                
 | 
			
		||||
                })
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -538,10 +610,7 @@ function IOConnection(io) {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        function sendUserNotification(text) {
 | 
			
		||||
 | 
			
		||||
            io.sockets.emit("NOTIFICATION", {"image_src": "https://cdn.discordapp.com/avatars/" + user.user.id + "/" + user.user.avatar, "text": user.user.global_name + " (" + user.user.username + ") " + text})
 | 
			
		||||
        }
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
@@ -562,10 +631,7 @@ function IOConnection(io) {
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function sendNotification(image_src, text) {
 | 
			
		||||
        io.sockets.emit("NOTIFICATION", {"image_src": image_src, "text": text})
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
    function playStats(username) {
 | 
			
		||||
        var userMusicPlayed = new Metric("userMusicPlayed_" + username, "Nombre de musiques jouées par l'utilisateur : " + username)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user