Version 0.3.0 - Ajout de l'interface Web - First Steps to it
This commit is contained in:
@ -6,6 +6,7 @@ const { __glob } = require("./global-variables")
|
||||
const { LogType } = require("../modules/sub-log")
|
||||
const { List } = require("./sub-list")
|
||||
const nodeFinder = require("./nodes-finder")
|
||||
const subplayer = require("./sub-player")
|
||||
|
||||
const client = new Client({
|
||||
intents:[GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers],
|
||||
@ -13,6 +14,11 @@ const client = new Client({
|
||||
|
||||
const membersVoices = new Map()
|
||||
|
||||
module.exports.getClient = function () {
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
module.exports.DiscordBot = class {
|
||||
|
||||
constructor(config, dlog) {
|
||||
@ -192,6 +198,9 @@ function startErelaManager(dlog, config) {
|
||||
client.channels.fetch(player.options.voiceChannel).then(channel => {
|
||||
plog.log("Nouveau Player instancié dans : " + channel.name)
|
||||
})
|
||||
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
|
||||
})
|
||||
|
||||
@ -201,13 +210,16 @@ function startErelaManager(dlog, config) {
|
||||
client.channels.fetch(player.options.voiceChannel).then(channel => {
|
||||
plog.log("Player supprimé dans : " + channel.name)
|
||||
})
|
||||
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
|
||||
})
|
||||
|
||||
client.manager.on("trackStart", (song) => {
|
||||
plog.log("Lecture de '" + song.queue.current.title + "' de '" + song.queue.current.author + "'")
|
||||
list.setCurrent(song)
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
})
|
||||
|
||||
|
||||
@ -222,6 +234,9 @@ function startErelaManager(dlog, config) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
})
|
||||
|
||||
// Emitted whenever a node connects
|
||||
@ -235,6 +250,7 @@ function startErelaManager(dlog, config) {
|
||||
|
||||
})
|
||||
|
||||
|
||||
// THIS IS REQUIRED. Send raw events to Erela.js
|
||||
client.on("raw", d => client.manager.updateVoiceState(d));
|
||||
}
|
@ -5,12 +5,14 @@ const root = path.resolve(__dirname, '../../')
|
||||
const __glob = {
|
||||
CONFIG: root + path.sep + "data" + path.sep + "config.json",
|
||||
USERS: root + path.sep + "data" + path.sep + "users.json",
|
||||
BETA_USERS: root + path.sep + "data" + path.sep + "betas.json",
|
||||
ROOT: root,
|
||||
WEB_DIR: root + path.sep + "src" + path.sep + "web",
|
||||
COMMANDS: root + path.sep + "src" + path.sep + "commands",
|
||||
SUBLOG: root + path.sep + "src" + path.sep + "modules" + path.sep + "sub-log.js",
|
||||
SUBPLAYER: root + path.sep + "src" + path.sep + "modules" + path.sep + "sub-player.js",
|
||||
SUBLIST: root + path.sep + "src" + path.sep + "modules" + path.sep + "sub-list.js",
|
||||
DISCORDBOT: root + path.sep + "src" + path.sep + "modules" + path.sep + "discord-bot.js",
|
||||
PACKAGE: root + path.sep + "package.json",
|
||||
DATA: root + path.sep + "data" + path.sep,
|
||||
NODES: root + path.sep + "data" + path.sep + "nodes.json",
|
||||
@ -21,7 +23,8 @@ const __web = {
|
||||
|
||||
ROUTER: webroot + "routes" + path.sep,
|
||||
PUBLIC: webroot + "public",
|
||||
TEMPLATES: webroot + "templates"
|
||||
TEMPLATES: webroot + "templates",
|
||||
ICON: webroot + "public" + path.sep + "images" + path.sep + "logo.ico"
|
||||
}
|
||||
|
||||
module.exports = { __glob, __web };
|
||||
|
@ -1,5 +1,5 @@
|
||||
const { resolve } = require("path");
|
||||
const { __glob } = require("../modules/global-variables");
|
||||
const { __glob, __web } = require("../modules/global-variables");
|
||||
const { LogType } = require('./sub-log');
|
||||
const fs = require("fs")
|
||||
|
||||
@ -7,6 +7,9 @@ const alog = new LogType("Authentification")
|
||||
|
||||
var users = new Map()
|
||||
var sessions = new Array()
|
||||
var betausers = new Array()
|
||||
|
||||
var packageJson = JSON.parse(fs.readFileSync(__glob.PACKAGE))
|
||||
|
||||
updateUsers()
|
||||
|
||||
@ -78,11 +81,31 @@ module.exports.getDiscordUser = function (code, session) {
|
||||
reject("MIGRATE_ACCOUNT_ONLY")
|
||||
|
||||
} else {
|
||||
user.auth = authorizationKey
|
||||
Object.assign(user, userInfo)
|
||||
|
||||
if(packageJson.beta_on == false) {
|
||||
user.auth = authorizationKey
|
||||
Object.assign(user, userInfo)
|
||||
|
||||
|
||||
resolve(user)
|
||||
|
||||
} else {
|
||||
|
||||
if(betausers.includes(userInfo.user.id)) {
|
||||
|
||||
user.beta = true
|
||||
Object.assign(user, userInfo)
|
||||
|
||||
|
||||
resolve(user)
|
||||
|
||||
|
||||
resolve(user)
|
||||
} else {
|
||||
|
||||
reject("NOT_IN_BETA")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -172,18 +195,31 @@ module.exports.removeUser = function (token) {
|
||||
|
||||
function updateUsers() {
|
||||
|
||||
|
||||
if(!fs.existsSync(__glob.BETA_USERS)){
|
||||
|
||||
fs.writeFileSync(__glob.BETA_USERS, '[]')
|
||||
}
|
||||
|
||||
if(!fs.existsSync(__glob.USERS)){
|
||||
|
||||
fs.writeFileSync(__glob.USERS, '[]')
|
||||
}
|
||||
|
||||
|
||||
const userDB = JSON.parse(fs.readFileSync(__glob.USERS))
|
||||
const betausersDB = JSON.parse(fs.readFileSync(__glob.BETA_USERS))
|
||||
|
||||
for (const user of userDB) {
|
||||
|
||||
users.set(user.token, user)
|
||||
}
|
||||
|
||||
for (const id of betausersDB) {
|
||||
|
||||
betausers.push(id)
|
||||
}
|
||||
|
||||
alog.log("Actualisation de " + userDB.length + " utilisateurs depuis : " + __glob.USERS)
|
||||
alog.log("Actualisation de " + betausersDB.length + " utilisateurs bêtas depuis : " + __glob.BETA_USERS)
|
||||
}
|
@ -14,6 +14,11 @@ module.exports.List = class {
|
||||
|
||||
}
|
||||
|
||||
getList() {
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
next = new Array()
|
||||
|
@ -2,7 +2,9 @@ const { SlashCommandBuilder, EmbedBuilder, DefaultWebSocketManagerOptions } = re
|
||||
const { __glob } = require("../modules/global-variables");
|
||||
const { LogType } = require("./sub-log");
|
||||
const { List } = require("./sub-list")
|
||||
var ytfps = require("ytfps")
|
||||
const discord = require("./discord-bot")
|
||||
var ytfps = require("ytfps");
|
||||
|
||||
|
||||
const list = new List()
|
||||
|
||||
@ -70,7 +72,8 @@ module.exports.play = async function (client, interaction) {
|
||||
// [A FINIR POUR WEB]
|
||||
}
|
||||
|
||||
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
|
||||
}
|
||||
|
||||
@ -116,9 +119,29 @@ module.exports.pause = function (client, interaction) {
|
||||
|
||||
} else {
|
||||
|
||||
// [A FINIR POUR WEB]
|
||||
if(!client) {
|
||||
|
||||
client = discord.getClient()
|
||||
}
|
||||
|
||||
let player = client.manager.players.get("137291455336022018")
|
||||
|
||||
if(player) {
|
||||
|
||||
if(player.playing) {
|
||||
player.pause(true)
|
||||
} else {
|
||||
|
||||
player.pause(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
|
||||
}
|
||||
|
||||
module.exports.getState = function(client, interaction) {
|
||||
@ -149,6 +172,7 @@ module.exports.getState = function(client, interaction) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -193,12 +217,41 @@ module.exports.skip = function (client, interaction) {
|
||||
|
||||
} else {
|
||||
|
||||
// [A FINIR POUR WEB]
|
||||
if(!client) {
|
||||
|
||||
client = discord.getClient()
|
||||
}
|
||||
|
||||
let player = client.manager.players.get("137291455336022018")
|
||||
|
||||
if(list.haveSongs()) {
|
||||
player.stop()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
}
|
||||
|
||||
module.exports.seek = function (data) {
|
||||
|
||||
|
||||
|
||||
client = discord.getClient()
|
||||
|
||||
|
||||
let player = client.manager.players.get("137291455336022018")
|
||||
|
||||
player.seek(data)
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports.previous = function (client, interaction) {
|
||||
|
||||
if(interaction) {
|
||||
@ -238,8 +291,91 @@ module.exports.previous = function (client, interaction) {
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(!client) {
|
||||
|
||||
client = discord.getClient()
|
||||
}
|
||||
|
||||
let player = client.manager.players.get("137291455336022018")
|
||||
|
||||
if(list.havePreviousSongs()){
|
||||
list.__next_add(player.queue.current)
|
||||
player.play(list.previous())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
}
|
||||
|
||||
const clog = new LogType("Actualisation")
|
||||
|
||||
module.exports.updateMusicState = function (client, action) {
|
||||
|
||||
if(!client) {
|
||||
|
||||
client = discord.getClient()
|
||||
}
|
||||
|
||||
let player = client.manager.players.get("137291455336022018")
|
||||
var currentTitle = "null"
|
||||
|
||||
const data = {
|
||||
"playing": 0,
|
||||
"current":null,
|
||||
"isOnline": false,
|
||||
"queue": null,
|
||||
"loop": false,
|
||||
"durationNow": null,
|
||||
"durationAll": null,
|
||||
"volume": null
|
||||
}
|
||||
|
||||
if(player) {
|
||||
|
||||
data["current"] = player.queue.current
|
||||
|
||||
if(player.queueRepeat == true) {
|
||||
|
||||
data["loop"] = true
|
||||
}
|
||||
|
||||
data["volume"] = player.volume * 10
|
||||
|
||||
|
||||
if(player.queue.current) {
|
||||
data["durationNow"] = player.position
|
||||
data["durationAll"] = player.queue.current.duration
|
||||
currentTitle = player.queue.current.title
|
||||
}
|
||||
|
||||
|
||||
if(player.playing == true && player.paused == false) {
|
||||
|
||||
data["playing"] = 1
|
||||
} else {
|
||||
data["playing"] = 0
|
||||
|
||||
}
|
||||
|
||||
data["queue"] = list.getList();
|
||||
data["isOnline"] = true
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(action == "end") {
|
||||
|
||||
data["current"] = null;
|
||||
data["isOnline"] = false
|
||||
}
|
||||
|
||||
clog.log("Actualisation de tous les clients - Titre : " + currentTitle)
|
||||
return data
|
||||
|
||||
|
||||
}
|
||||
|
||||
// FINI
|
||||
@ -284,7 +420,9 @@ module.exports.leave = function (client, interaction) {
|
||||
|
||||
}
|
||||
|
||||
process.emit("MUSIC_UPDATE_STATE")
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ const log = require("./sub-log");
|
||||
const auth = require("./sub-auth");
|
||||
const cook = require("cookie")
|
||||
const wlog = new LogType("Web")
|
||||
|
||||
const subplayer = require(__glob.SUBPLAYER);
|
||||
module.exports.WebServer = class {
|
||||
|
||||
constructor() {
|
||||
@ -23,6 +23,7 @@ function init() {
|
||||
const path = require('path');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const http = require("http");
|
||||
const favicon = require('express-favicon');
|
||||
|
||||
const app = express();
|
||||
|
||||
@ -49,7 +50,7 @@ function init() {
|
||||
app.use('/', indexRouter);
|
||||
app.use('/login', loginRouter);
|
||||
app.use("/internal", internalRouter)
|
||||
|
||||
app.use(favicon(__web.ICON));
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
next(createError(404));
|
||||
@ -134,15 +135,26 @@ function IOConnection(io) {
|
||||
|
||||
const alog = log.getInstance("Authentification")
|
||||
|
||||
process.on("MUSIC_UPDATE_STATE", () => {
|
||||
|
||||
const data = subplayer.updateMusicState()
|
||||
|
||||
io.sockets.emit("/ALWAYS/MUSIC_STATE", data)
|
||||
|
||||
})
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
|
||||
wlog.log("[SOCKET] - Nouvelle session : " + socket.id)
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
|
||||
|
||||
wlog.log("[SOCKET] - Fin de session : " + socket.id)
|
||||
|
||||
})
|
||||
|
||||
// SPECIAL
|
||||
|
||||
socket.on("GET/DISCORD_LOGIN_LINK", () => {
|
||||
|
||||
|
||||
@ -160,8 +172,54 @@ function IOConnection(io) {
|
||||
io.emit("ANSWER/GET/DISCORD_LOGIN_LINK", discordlink )
|
||||
})
|
||||
|
||||
GetRequest(socket, "USER_INFO", () => {
|
||||
var cookies = socket.handshake.headers.cookie
|
||||
cookies = cook.parse(cookies)
|
||||
var token = cookies.token
|
||||
|
||||
|
||||
socket.on("GET/USER_INFO", () => {
|
||||
const user = auth.getUser(token)
|
||||
alog.log("Envoi des informations Discord de '" + user.user.username + "' à '" + socket.id + "'" )
|
||||
socket.emit("ANSWER/GET/USER_INFO",user)
|
||||
})
|
||||
|
||||
GetRequest(socket, "MUSIC_STATE", () => {
|
||||
var cookies = socket.handshake.headers.cookie
|
||||
cookies = cook.parse(cookies)
|
||||
var token = cookies.token
|
||||
|
||||
|
||||
const data = subplayer.updateMusicState()
|
||||
const user = auth.getUser(token)
|
||||
socket.emit("ANSWER/GET/MUSIC_STATE", "Bienvenue " + user.user.username + " ! ")
|
||||
io.sockets.emit("/ALWAYS/MUSIC_STATE", data)
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
GetRequest(socket, "PAUSE", () => {
|
||||
|
||||
subplayer.pause()
|
||||
io.emit("ANSWER/GET/PAUSE", "OK")
|
||||
})
|
||||
|
||||
|
||||
GetRequest(socket, "BACKWARD", () => {
|
||||
|
||||
subplayer.previous()
|
||||
io.emit("ANSWER/GET/BACKWARD", "OK")
|
||||
})
|
||||
|
||||
GetRequest(socket, "FORWARD", () => {
|
||||
|
||||
subplayer.skip()
|
||||
io.emit("ANSWER/GET/FORWARD", "OK")
|
||||
})
|
||||
|
||||
// SEND REQUEST
|
||||
|
||||
socket.on("SEND/SEEK", (data) => {
|
||||
|
||||
|
||||
var cookies = socket.handshake.headers.cookie
|
||||
@ -173,24 +231,67 @@ function IOConnection(io) {
|
||||
|
||||
if(auth.checkUser(token)) {
|
||||
|
||||
const user = auth.getUser(token)
|
||||
alog.log("Envoi des informations Discord de '" + user.user.username + "' à '" + socket.id + "'" )
|
||||
socket.emit("ANSWER/GET/USER_INFO",user)
|
||||
subplayer.seek(data)
|
||||
|
||||
} else {
|
||||
|
||||
io.emit("ANSWER/GET/USER_INFO", {"error":"USER_DONT_EXIST"})
|
||||
io.emit("ANSWER/SEND/SEEK", {"error":"USER_DONT_EXIST"})
|
||||
}
|
||||
} else {
|
||||
io.emit("ANSWER/GET/USER_INFO", {"error":"TOKEN_NOT_FINDED"})
|
||||
io.emit("ANSWER/SEND/SEEK", {"error":"TOKEN_NOT_FINDED"})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function GetRequest (socket, name, func) {
|
||||
|
||||
|
||||
socket.on("GET/" + name, () => {
|
||||
|
||||
|
||||
var cookies = socket.handshake.headers.cookie
|
||||
|
||||
if(cookies) {
|
||||
|
||||
cookies = cook.parse(cookies)
|
||||
var token = cookies.token
|
||||
|
||||
if(auth.checkUser(token)) {
|
||||
|
||||
func()
|
||||
|
||||
} else {
|
||||
|
||||
io.emit("ANSWER/GET/" + name, {"error":"USER_DONT_EXIST"})
|
||||
}
|
||||
} else {
|
||||
io.emit("ANSWER/GET/" + name, {"error":"TOKEN_NOT_FINDED"})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user