Version 0.5.0 - Ajout de la recherche
This commit is contained in:
		@@ -12,13 +12,20 @@ const client = new Client({
 | 
			
		||||
    intents:[GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers],
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const membersVoices = new Map()
 | 
			
		||||
var membersVoices = new Map()
 | 
			
		||||
 | 
			
		||||
module.exports.getClient = function () {
 | 
			
		||||
 | 
			
		||||
    return client
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.getMemberVoices = function () {
 | 
			
		||||
 | 
			
		||||
    return membersVoices
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports.DiscordBot = class {
 | 
			
		||||
 | 
			
		||||
    constructor(config, dlog) {
 | 
			
		||||
@@ -257,4 +264,5 @@ function startErelaManager(dlog, config) {
 | 
			
		||||
 | 
			
		||||
    // THIS IS REQUIRED. Send raw events to Erela.js
 | 
			
		||||
    client.on("raw", d => client.manager.updateVoiceState(d));
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ const __glob = {
 | 
			
		||||
    PACKAGE: root + path.sep + "package.json",
 | 
			
		||||
    DATA:  root + path.sep + "data" + path.sep,
 | 
			
		||||
    NODES:  root + path.sep + "data" + path.sep + "nodes.json",
 | 
			
		||||
    README: root + path.sep + "README.md"
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const webroot = __glob.WEB_DIR + path.sep 
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ const { LogType } = require("./sub-log");
 | 
			
		||||
var { List } = require("./sub-list")
 | 
			
		||||
const discord = require("./discord-bot")
 | 
			
		||||
var ytfps = require("ytfps");
 | 
			
		||||
const { use } = require("../web/routes/login");
 | 
			
		||||
const packageJson = require(__glob.PACKAGE);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -177,7 +178,7 @@ module.exports.getState = function(client, interaction) {
 | 
			
		||||
        
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.SPECIAL_MJ = async function (client) {
 | 
			
		||||
module.exports.SPECIAL_MJ = async function (client, userId) {
 | 
			
		||||
 | 
			
		||||
    if(!client) {
 | 
			
		||||
 | 
			
		||||
@@ -186,12 +187,13 @@ module.exports.SPECIAL_MJ = async function (client) {
 | 
			
		||||
 | 
			
		||||
    let player = client.manager.players.get("137291455336022018")
 | 
			
		||||
 | 
			
		||||
    var memberVoices = discord.getMemberVoices()
 | 
			
		||||
 | 
			
		||||
    if(!player) { 
 | 
			
		||||
            
 | 
			
		||||
        player = client.manager.create({
 | 
			
		||||
            guild: "137291455336022018",
 | 
			
		||||
            voiceChannel: "664355734288465920",
 | 
			
		||||
            voiceChannel: memberVoices.get(userId),
 | 
			
		||||
            textChannel: "664355637685256203",
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
@@ -221,6 +223,61 @@ module.exports.SPECIAL_MJ = async function (client) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.addSong = async function (data, client, userId, quick) {
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    const songs = await client.manager.search(data.uri)
 | 
			
		||||
 | 
			
		||||
    if(quick) {
 | 
			
		||||
        
 | 
			
		||||
        player.play(songs.tracks[0])
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
        if(!player.playing && player.paused == false) {
 | 
			
		||||
 | 
			
		||||
            player.play(songs.tracks[0])
 | 
			
		||||
    
 | 
			
		||||
        } else {
 | 
			
		||||
            
 | 
			
		||||
            list.add(songs.tracks[0])
 | 
			
		||||
    
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
    process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.skip = function (client, interaction) {
 | 
			
		||||
 | 
			
		||||
    if(interaction) {
 | 
			
		||||
@@ -371,6 +428,25 @@ module.exports.changeShuffle = function (client) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    process.emit("MUSIC_UPDATE_STATE")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const slog = new LogType("Search")
 | 
			
		||||
 | 
			
		||||
module.exports.search = async function (data, client) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(!client) {
 | 
			
		||||
 | 
			
		||||
        client = discord.getClient()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    slog.log("Recherche avec les mots clés : " + data)
 | 
			
		||||
 | 
			
		||||
    const songs = await client.manager.search(data)
 | 
			
		||||
    return songs
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -246,7 +246,15 @@ function IOConnection(io) {
 | 
			
		||||
 | 
			
		||||
        GetRequest(io, socket, "SPECIAL/MJ", () => {
 | 
			
		||||
 | 
			
		||||
            subplayer.SPECIAL_MJ()
 | 
			
		||||
                var cookiesA = socket.handshake.headers.cookie
 | 
			
		||||
                cookiesA = cook.parse(cookiesA)
 | 
			
		||||
                var tokenA = cookiesA.token
 | 
			
		||||
 | 
			
		||||
                var userA = auth.getUser(tokenA)
 | 
			
		||||
                var userId = userA.user.id
 | 
			
		||||
                 
 | 
			
		||||
 | 
			
		||||
            subplayer.SPECIAL_MJ(null, userId)
 | 
			
		||||
            io.emit("ANSWER/GET/SPECIAL/MJ", "OK")
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
@@ -391,9 +399,113 @@ function IOConnection(io) {
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
        
 | 
			
		||||
        socket.on("SEND/SEARCH", async (data) => {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            var cookies = socket.handshake.headers.cookie
 | 
			
		||||
 | 
			
		||||
            if(cookies) {
 | 
			
		||||
 | 
			
		||||
                cookies = cook.parse(cookies)
 | 
			
		||||
                var token = cookies.token
 | 
			
		||||
                 
 | 
			
		||||
                if(auth.checkUser(token)) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                    const results = await subplayer.search(data)
 | 
			
		||||
                    
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/SEARCH", results)
 | 
			
		||||
                
 | 
			
		||||
                } else {
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/SEARCH", {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/SEND/SEARCH", {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        socket.on("SEND/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)
 | 
			
		||||
                    
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/ADD_SONG/OK")
 | 
			
		||||
                
 | 
			
		||||
                } else {
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/ADD_SONG", {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/SEND/ADD_SONG", {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        socket.on("SEND/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)
 | 
			
		||||
                    
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/ADD_SONG_NOW/OK")
 | 
			
		||||
                
 | 
			
		||||
                } else {
 | 
			
		||||
 | 
			
		||||
                    io.emit("ANSWER/SEND/ADD_SONG_NOW", {"error":"USER_DONT_EXIST"})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                io.emit("ANSWER/SEND/ADD_SONG_NOW", {"error":"TOKEN_NOT_FINDED"})
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
         
 | 
			
		||||
           
 | 
			
		||||
 | 
			
		||||
        })
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
       
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user