Version 1.1.0 - Refactor + Intergration Backend
This commit is contained in:
8
backend/package-lock.json → package-lock.json
generated
8
backend/package-lock.json → package-lock.json
generated
@@ -24,7 +24,7 @@
|
|||||||
"libsodium-wrappers": "^0.7.15",
|
"libsodium-wrappers": "^0.7.15",
|
||||||
"loguix": "^1.4.2",
|
"loguix": "^1.4.2",
|
||||||
"mime-types": "^3.0.1",
|
"mime-types": "^3.0.1",
|
||||||
"nodemon": "^3.1.9",
|
"nodemon": "^3.1.10",
|
||||||
"pm2": "^5.4.3",
|
"pm2": "^5.4.3",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"soundcloud.ts": "^0.6.3",
|
"soundcloud.ts": "^0.6.3",
|
||||||
@@ -4544,9 +4544,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nodemon": {
|
"node_modules/nodemon": {
|
||||||
"version": "3.1.9",
|
"version": "3.1.10",
|
||||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.9.tgz",
|
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.10.tgz",
|
||||||
"integrity": "sha512-hdr1oIb2p6ZSxu3PB2JWWYS7ZQ0qvaZsc3hK8DR8f02kRzc8rjYmxAIvdz+aYC+8F2IjNaB7HMcSDg8nQpJxyg==",
|
"integrity": "sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "^3.5.2",
|
"chokidar": "^3.5.2",
|
@@ -35,7 +35,7 @@
|
|||||||
"libsodium-wrappers": "^0.7.15",
|
"libsodium-wrappers": "^0.7.15",
|
||||||
"loguix": "^1.4.2",
|
"loguix": "^1.4.2",
|
||||||
"mime-types": "^3.0.1",
|
"mime-types": "^3.0.1",
|
||||||
"nodemon": "^3.1.9",
|
"nodemon": "^3.1.10",
|
||||||
"pm2": "^5.4.3",
|
"pm2": "^5.4.3",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"soundcloud.ts": "^0.6.3",
|
"soundcloud.ts": "^0.6.3",
|
@@ -6,15 +6,18 @@ const { LogType } = require("loguix")
|
|||||||
const config = require("../utils/Database/Configuration")
|
const config = require("../utils/Database/Configuration")
|
||||||
const metric = require("webmetrik")
|
const metric = require("webmetrik")
|
||||||
const { Player } = require("../player/Player")
|
const { Player } = require("../player/Player")
|
||||||
const {refreshAllUserInformation} = require("../server/auth/User")
|
const {refreshAllUserInformation, clearNeedUpdateForUsers} = require("../server/auth/User")
|
||||||
|
|
||||||
const dlog = new LogType("Discord")
|
const dlog = new LogType("Discord")
|
||||||
|
const glog = new LogType("GuildUpdater")
|
||||||
dlog.log("Initialisation du Bot Discord")
|
dlog.log("Initialisation du Bot Discord")
|
||||||
|
|
||||||
const membersVoices = new Map()
|
const membersVoices = new Map()
|
||||||
const timers = new Map()
|
const timers = new Map()
|
||||||
const guilds = new Map()
|
const guilds = new Map()
|
||||||
|
|
||||||
|
var operational = false
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents:[GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers],
|
intents:[GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers],
|
||||||
})
|
})
|
||||||
@@ -33,6 +36,19 @@ function getMembersVoices() {
|
|||||||
return membersVoices
|
return membersVoices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isReady() {
|
||||||
|
return operational
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGuildMembers(guildId) {
|
||||||
|
const guild = client.guilds.cache.get(guildId)
|
||||||
|
if(!guild) {
|
||||||
|
dlog.error("Guild not found: " + guildId)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return guild.members.cache.map(member => member.user.id)
|
||||||
|
}
|
||||||
|
|
||||||
function getChannel(guildId, channelId) {
|
function getChannel(guildId, channelId) {
|
||||||
return client.guilds.cache.get(guildId).channels.cache.get(channelId)
|
return client.guilds.cache.get(guildId).channels.cache.get(channelId)
|
||||||
}
|
}
|
||||||
@@ -42,38 +58,43 @@ function init() {
|
|||||||
client.once('ready', async () => {
|
client.once('ready', async () => {
|
||||||
dlog.log("Connexion au Bot Discord réussi ! Connecté en tant que : " + client.user.tag)
|
dlog.log("Connexion au Bot Discord réussi ! Connecté en tant que : " + client.user.tag)
|
||||||
|
|
||||||
// Add all guilds to the guilds map
|
for (const guild of client.guilds.cache.values()) {
|
||||||
await client.guilds.cache.forEach(async guild => {
|
const missingPermissions = checkRequiredPermission(guild.members.me)
|
||||||
|
if (missingPermissions.length > 0) {
|
||||||
|
dlog.error("Le bot n'a pas les permissions nécessaires pour rejoindre la guilde : " + guild.name)
|
||||||
|
dlog.error("Permissions manquantes : " + missingPermissions.join(", "))
|
||||||
|
await guild.leave()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var guildMember = await guild.members.fetch()
|
var guildMember = await guild.members.fetch()
|
||||||
guildMember = guildMember.map(member => member.user.id)
|
guildMember = guildMember.map(member => member.user.id)
|
||||||
|
guilds.set(guild.id, {
|
||||||
await guilds.set(guild.id, {
|
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
name: guild.name,
|
name: guild.name,
|
||||||
members: guildMember,
|
members: guildMember,
|
||||||
})
|
})
|
||||||
|
glog.log("Guilde instanciée (démarrage) : " + guild.name + " (" + guild.id + ")")
|
||||||
|
}
|
||||||
|
|
||||||
|
await refreshAllUserInformation()
|
||||||
|
|
||||||
})
|
|
||||||
refreshAllUserInformation()
|
|
||||||
const Activity = require("./Activity")
|
const Activity = require("./Activity")
|
||||||
Activity.idleActivity()
|
Activity.idleActivity()
|
||||||
|
|
||||||
const CommandUpdater = require("./CommandUpdater")
|
const CommandUpdater = require("./CommandUpdater")
|
||||||
CommandUpdater.init()
|
CommandUpdater.init()
|
||||||
|
|
||||||
const commandManager = client.application.commands;
|
const commandManager = client.application.commands
|
||||||
|
|
||||||
if (!commandManager) {
|
if (!commandManager) {
|
||||||
dlog.error('Command manager not available.');
|
dlog.error('Command manager not available.')
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
commandManager.set([])
|
||||||
commandManager.set([]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dlog.step.end("d_init")
|
dlog.step.end("d_init")
|
||||||
|
operational = true
|
||||||
});
|
})
|
||||||
|
|
||||||
client.on("interactionCreate", (interaction) => {
|
client.on("interactionCreate", (interaction) => {
|
||||||
|
|
||||||
@@ -100,13 +121,36 @@ function init() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// If a new guild is added, we will add it to the guilds map
|
// If a new guild is added, we will add it to the guilds map
|
||||||
client.on("guildCreate", (guild) => {
|
client.on("guildCreate", async (guild) => {
|
||||||
|
|
||||||
|
const guildMember = guild.members.cache.get(client.user.id);
|
||||||
|
if (guildMember) {
|
||||||
|
const missingPermissions = checkRequiredPermission(guildMember)
|
||||||
|
if(missingPermissions.length > 0) {
|
||||||
|
dlog.error("Le bot n'a pas les permissions nécessaires pour rejoindre la guilde : " + guild.name)
|
||||||
|
guild.leave()
|
||||||
|
return
|
||||||
|
}
|
||||||
dlog.log("Nouvelle guilde ajoutée : " + guild.name)
|
dlog.log("Nouvelle guilde ajoutée : " + guild.name)
|
||||||
|
var allMembersOfGuild = await guild.members.fetch()
|
||||||
|
allMembersOfGuild = allMembersOfGuild.map(member => member.user.id)
|
||||||
guilds.set(guild.id, {
|
guilds.set(guild.id, {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
name: guild.name,
|
name: guild.name,
|
||||||
members: guild.members.cache.map(member => member.user.username),
|
members: allMembersOfGuild,
|
||||||
})
|
})
|
||||||
|
glog.log("Guilde ajoutée : " + guild.name + " (" + guild.id + ")")
|
||||||
|
clearNeedUpdateForUsers()
|
||||||
|
process.emit("USERS_UPDATE")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on("guildDelete", (guild) => {
|
||||||
|
dlog.log("Guilde supprimée : " + guild.name)
|
||||||
|
guilds.delete(guild.id)
|
||||||
|
glog.log("Guilde supprimée : " + guild.name + " (" + guild.id + ")")
|
||||||
|
clearNeedUpdateForUsers()
|
||||||
|
process.emit("USERS_UPDATE")
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on("voiceStateUpdate", (oldMember, newMember) => {
|
client.on("voiceStateUpdate", (oldMember, newMember) => {
|
||||||
@@ -152,6 +196,25 @@ function init() {
|
|||||||
client.login(config.getToken())
|
client.login(config.getToken())
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {init, getClient, getGuilds, getMembersVoices, getChannel}
|
function checkRequiredPermission(guildMember) {
|
||||||
|
const requiredPermissions = [
|
||||||
|
'CreateInstantInvite', 'AddReactions',
|
||||||
|
'Stream', 'ViewChannel',
|
||||||
|
'SendMessages', 'SendTTSMessages',
|
||||||
|
'EmbedLinks', 'AttachFiles',
|
||||||
|
'ReadMessageHistory', 'UseExternalEmojis',
|
||||||
|
'Connect', 'Speak',
|
||||||
|
'UseVAD', 'ChangeNickname',
|
||||||
|
'UseApplicationCommands', 'RequestToSpeak',
|
||||||
|
'CreatePublicThreads', 'CreatePrivateThreads',
|
||||||
|
'UseExternalStickers', 'SendMessagesInThreads',
|
||||||
|
'UseEmbeddedActivities', 'UseSoundboard',
|
||||||
|
'UseExternalSounds', 'SendVoiceMessages',
|
||||||
|
'SendPolls', 'UseExternalApps'
|
||||||
|
]
|
||||||
|
return requiredPermissions.filter(permission => !guildMember.permissions.has(permission));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {init, getClient, getGuilds, getMembersVoices, getChannel, getGuildMembers, isReady}
|
||||||
|
|
||||||
|
|
@@ -22,7 +22,12 @@ if(!config.getMediaGuildId() || !config.getMediaChannelId()) {
|
|||||||
var channel = null
|
var channel = null
|
||||||
|
|
||||||
discordBot.getClient().on("ready", () => {
|
discordBot.getClient().on("ready", () => {
|
||||||
|
try {
|
||||||
channel = discordBot.getChannel(config.getMediaGuildId(), config.getMediaChannelId())
|
channel = discordBot.getChannel(config.getMediaGuildId(), config.getMediaChannelId())
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if(!channel) {
|
if(!channel) {
|
||||||
wlog.warn("Le canal multimédia n'existe pas, vérifiez le fichier de configuration.")
|
wlog.warn("Le canal multimédia n'existe pas, vérifiez le fichier de configuration.")
|
||||||
wlog.step.error("init_db","Impossible d'initialiser la base de données multimédia, vérifiez le fichier de configuration.")
|
wlog.step.error("init_db","Impossible d'initialiser la base de données multimédia, vérifiez le fichier de configuration.")
|
@@ -240,6 +240,8 @@ class Player {
|
|||||||
process.emit("PLAYERS_UPDATE")
|
process.emit("PLAYERS_UPDATE")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
const { LogType } = require('loguix')
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@@ -1,6 +1,7 @@
|
|||||||
const {LogType} = require('loguix')
|
const {LogType} = require('loguix')
|
||||||
const wlog = new LogType("Server")
|
const wlog = new LogType("Server")
|
||||||
|
|
||||||
|
const fs = require("fs")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const {Server} = require('socket.io')
|
const {Server} = require('socket.io')
|
||||||
const {createServer} = require('http')
|
const {createServer} = require('http')
|
||||||
@@ -12,7 +13,7 @@ const discordBot = require("../discord/Bot")
|
|||||||
const discordAuth = require("../server/auth/DiscordAuth")
|
const discordAuth = require("../server/auth/DiscordAuth")
|
||||||
const {Report} = require("../discord/ReportSender")
|
const {Report} = require("../discord/ReportSender")
|
||||||
const Finder = require("../player/Finder")
|
const Finder = require("../player/Finder")
|
||||||
const fs = require("fs")
|
|
||||||
const {__glob} = require("../utils/GlobalVars")
|
const {__glob} = require("../utils/GlobalVars")
|
||||||
const playlists = require("../playlists/PlaylistManager")
|
const playlists = require("../playlists/PlaylistManager")
|
||||||
const history = require("../playlists/History")
|
const history = require("../playlists/History")
|
||||||
@@ -32,6 +33,8 @@ const allConnectedUsers = new Array()
|
|||||||
const guildConnectedUsers = new Map()
|
const guildConnectedUsers = new Map()
|
||||||
const UsersBySocket = new Map()
|
const UsersBySocket = new Map()
|
||||||
|
|
||||||
|
//TODO: Refactor this file to implement the fact that server can be joined and leaved and all the events are now handled, so guildId is not required for every event
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
wlog.step.init("server_init", "Initialisation du serveur Socket.IO")
|
wlog.step.init("server_init", "Initialisation du serveur Socket.IO")
|
||||||
@@ -60,6 +63,7 @@ function init() {
|
|||||||
|
|
||||||
process.on("USERS_UPDATE", () => {
|
process.on("USERS_UPDATE", () => {
|
||||||
if(io) {
|
if(io) {
|
||||||
|
updateGuildConnectedUsers()
|
||||||
// Get all players and send them to client subscribed to the guild
|
// Get all players and send them to client subscribed to the guild
|
||||||
for(var guild of discordBot.getGuilds().keys()) {
|
for(var guild of discordBot.getGuilds().keys()) {
|
||||||
if(guildConnectedUsers.has(guild)) {
|
if(guildConnectedUsers.has(guild)) {
|
||||||
@@ -68,17 +72,17 @@ function init() {
|
|||||||
wlog.log("Envoi de la liste des utilisateurs connectés (" + guildConnectedUsers.get(guild).length +") à la guilde : " + guild + " à tous les utilisateurs connectés")
|
wlog.log("Envoi de la liste des utilisateurs connectés (" + guildConnectedUsers.get(guild).length +") à la guilde : " + guild + " à tous les utilisateurs connectés")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
io.sockets.emit("/USER/READY")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
io.on("connection", async (socket) => {
|
io.on("connection", async (socket) => {
|
||||||
var socketUser;
|
var socketUser;
|
||||||
|
|
||||||
// Make sure Discord Bot is loaded and make an interruption until it is loaded
|
// Make sure Discord Bot is loaded and make an interruption until it is loaded
|
||||||
while(!discordBot.getClient().isReady()) {
|
while(!await discordBot.isReady()) {
|
||||||
wlog.warn("Attente de traitement : "+ socket.id + " : Le bot Discord n'est pas encore chargé, attente de 3 seconde... (Avoid Rate Limit)")
|
wlog.warn("Attente de traitement : "+ socket.id + " : Le bot Discord n'est pas encore chargé, attente de 0.5 seconde... (Avoid Rate Limit)")
|
||||||
await new Promise(resolve => setTimeout(resolve, 3000))
|
await new Promise(resolve => setTimeout(resolve, 500))
|
||||||
}
|
}
|
||||||
|
|
||||||
wlog.log(`Connexion d'un client : ${socket.id}`)
|
wlog.log(`Connexion d'un client : ${socket.id}`)
|
||||||
@@ -102,6 +106,7 @@ function init() {
|
|||||||
var token = socket.handshake.auth.token
|
var token = socket.handshake.auth.token
|
||||||
var sessionId = socket.handshake.auth.sessionId
|
var sessionId = socket.handshake.auth.sessionId
|
||||||
var auth_code = socket.handshake.auth.auth_code
|
var auth_code = socket.handshake.auth.auth_code
|
||||||
|
var inLogin = false
|
||||||
|
|
||||||
if(sessionId) {
|
if(sessionId) {
|
||||||
if(!session.checkSession(sessionId)) {
|
if(!session.checkSession(sessionId)) {
|
||||||
@@ -126,7 +131,8 @@ function init() {
|
|||||||
}
|
}
|
||||||
const newToken = await loggedUser.createToken()
|
const newToken = await loggedUser.createToken()
|
||||||
socket.emit("NEW_TOKEN", newToken)
|
socket.emit("NEW_TOKEN", newToken)
|
||||||
socket.disconnect()
|
token = newToken
|
||||||
|
inLogin = true
|
||||||
wlog.log("Utilisateur Discord associé à la session : " + sessionId + " récupéré avec succès")
|
wlog.log("Utilisateur Discord associé à la session : " + sessionId + " récupéré avec succès")
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -134,6 +140,7 @@ function init() {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
wlog.warn("Code d'authentification manquant pour le client :" + socket.id)
|
wlog.warn("Code d'authentification manquant pour le client :" + socket.id)
|
||||||
|
socket.emit("AUTH_ERROR", "Code manquant invalide")
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -142,6 +149,7 @@ function init() {
|
|||||||
|
|
||||||
if(!token) {
|
if(!token) {
|
||||||
wlog.warn("Token manquant pour le client :" + socket.id)
|
wlog.warn("Token manquant pour le client :" + socket.id)
|
||||||
|
socket.emit("AUTH_ERROR", "Token invalide")
|
||||||
sendSession()
|
sendSession()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -150,31 +158,42 @@ function init() {
|
|||||||
|
|
||||||
if(!socketUser) {
|
if(!socketUser) {
|
||||||
wlog.warn("Token invalide pour le client :" + socket.id)
|
wlog.warn("Token invalide pour le client :" + socket.id)
|
||||||
|
socket.emit("AUTH_ERROR", "Token invalide")
|
||||||
sendSession()
|
sendSession()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if(!socketUser.auth) {
|
if(!socketUser.auth) {
|
||||||
wlog.warn("L'utilisateur '" + socketUser.identity.username + "' n'a pas d'authentification Discord Valide")
|
wlog.warn("L'utilisateur '" + socketUser.identity.username + "' n'a pas d'authentification Discord Valide")
|
||||||
socketUser.clearToken()
|
socketUser.clearToken()
|
||||||
socket.emit("AUTH_ERROR", "AUTH_ERROR")
|
socket.emit("AUTH_ERROR", "L'authentification Discord de l'utilisateur n'est pas valide")
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!inLogin) {
|
||||||
|
if(socketUser.needUpdate()) {
|
||||||
if (!(await users.updateGuilds(socketUser.identity.id)) || !(await users.updateIdentity(socketUser.identity.id))) {
|
if (!(await users.updateGuilds(socketUser.identity.id)) || !(await users.updateIdentity(socketUser.identity.id))) {
|
||||||
wlog.error("Erreur lors de la mise à jour des informations de l'utilisateur : " + socketUser.identity.id);
|
wlog.error("Erreur lors de la mise à jour des informations de l'utilisateur : " + socketUser.identity.id);
|
||||||
socket.emit("UPDATE_ERROR", "Error updating user information");
|
socket.emit("AUTH_ERROR", "Mise à jour des informations de l'utilisateur impossible");
|
||||||
wlog.log("Déconnexion de l'utilisateur : " + socketUser.identity.username + " (" + socketUser.identity.id + ") - Socket : " + socket.id)
|
wlog.log("Déconnexion de l'utilisateur : " + socketUser.identity.username + " (" + socketUser.identity.id + ") - Socket : " + socket.id)
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
socketUser.justUpdated()
|
||||||
|
} else {
|
||||||
|
wlog.log("Pas de mise à jour des informations de l'utilisateur : " + socketUser.identity.id + " car l'utilisateur vient de se connecter")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wlog.log("L'utilisateur '" + socketUser.identity.username + "' s'est connecté via la session : " + sessionId)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
socketUser = users.getUserByToken(token)
|
socketUser = users.getUserByToken(token)
|
||||||
|
|
||||||
if(socketUser) {
|
if(socketUser) {
|
||||||
|
if(allConnectedUsers.includes(socketUser.identity)) {
|
||||||
if(allConnectedUsers.includes(socketUser.identity.id)) {
|
|
||||||
wlog.warn("L'utilisateur '" + socketUser.identity.username + "' est déjà connecté sur un autre appareil")
|
wlog.warn("L'utilisateur '" + socketUser.identity.username + "' est déjà connecté sur un autre appareil")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -189,7 +208,7 @@ function init() {
|
|||||||
|
|
||||||
if(socketUser.isFullBanned()) {
|
if(socketUser.isFullBanned()) {
|
||||||
wlog.warn("Utilisateur banni : " + socketUser.identity.username + " (" + socketUser.identity.id + ") - Socket : " + socket.id)
|
wlog.warn("Utilisateur banni : " + socketUser.identity.username + " (" + socketUser.identity.id + ") - Socket : " + socket.id)
|
||||||
socket.emit("BANNED")
|
socket.emit("AUTH_ERROR", "Vous êtes banni du serveur")
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
}
|
}
|
||||||
if(socketUser.isAdmin()) {
|
if(socketUser.isAdmin()) {
|
||||||
@@ -197,6 +216,7 @@ function init() {
|
|||||||
wlog.log("Utilisateur admin identifié : " + socketUser.identity.username + " (" + socketUser.identity.id + ")")
|
wlog.log("Utilisateur admin identifié : " + socketUser.identity.username + " (" + socketUser.identity.id + ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IOAnswer("/USER/READY", true)
|
||||||
// USERS
|
// USERS
|
||||||
|
|
||||||
// CHECKED : 24/04/2025
|
// CHECKED : 24/04/2025
|
||||||
@@ -204,9 +224,31 @@ function init() {
|
|||||||
var guildPresents = new Array();
|
var guildPresents = new Array();
|
||||||
var guildsOfBot = discordBot.getGuilds()
|
var guildsOfBot = discordBot.getGuilds()
|
||||||
for(var guild of guildsOfBot) {
|
for(var guild of guildsOfBot) {
|
||||||
|
|
||||||
if(guild[1].members.includes(socketUser.identity.id)) {
|
if(guild[1].members.includes(socketUser.identity.id)) {
|
||||||
guildPresents.push(guild[1].id)
|
const guildData = socketUser.guilds.find(g => g.id == guild[0])
|
||||||
|
guildData['members'] = new Array()
|
||||||
|
guildData.serverMember = guild[1].members.length
|
||||||
|
for(var user of guild[1].members) {
|
||||||
|
const userData = users.getUserById(user)
|
||||||
|
if(userData && userData.identity.id != socketUser.identity.id && allConnectedUsers.includes(userData.identity)) {
|
||||||
|
guildData.members.push({
|
||||||
|
id: userData.identity.id,
|
||||||
|
username: userData.identity.username,
|
||||||
|
avatar: userData.identity.avatar,
|
||||||
|
isAdmin: userData.isAdmin(),
|
||||||
|
isOwner: userData.isOwner(guild[0]),
|
||||||
|
isMod: userData.isMod(guild[0]),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send if the bot is connected to the guild
|
||||||
|
if(players.getPlayer(guild[0]) && players.getPlayer(guild[0]).isConnected()) {
|
||||||
|
guildData.connected = true
|
||||||
|
} else {
|
||||||
|
guildData.connected = false
|
||||||
|
}
|
||||||
|
guildPresents.push(guildData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IOAnswer("/USER/INFO", {
|
IOAnswer("/USER/INFO", {
|
||||||
@@ -225,6 +267,7 @@ function init() {
|
|||||||
//CHECKED : 24/04/2025
|
//CHECKED : 24/04/2025
|
||||||
IORequest("/USER/SIGNOUT", () => {
|
IORequest("/USER/SIGNOUT", () => {
|
||||||
socketUser.removeToken(token)
|
socketUser.removeToken(token)
|
||||||
|
IOAnswer("/USER/SIGNOUT", true)
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -660,7 +703,7 @@ function init() {
|
|||||||
if(userSocket) {
|
if(userSocket) {
|
||||||
const socket = io.sockets.sockets.get(userSocket)
|
const socket = io.sockets.sockets.get(userSocket)
|
||||||
if(socket) {
|
if(socket) {
|
||||||
socket.emit("DELETED")
|
socket.emit("AUTH_ERROR", "Votre compte a été supprimé")
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -677,8 +720,11 @@ function init() {
|
|||||||
}
|
}
|
||||||
IOAnswer("/ADMIN/PLAYER/GETALLSTATE", states)
|
IOAnswer("/ADMIN/PLAYER/GETALLSTATE", states)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CHECKED : 24/04/2025
|
// CHECKED : 24/04/2025
|
||||||
IORequest("/OWNER/USERS/SWITCH_MOD", (data) => {
|
IORequest("/OWNER/USERS/SWITCH_MOD", (data) => {
|
||||||
if(!data["userId"] || !data["guildId"]) return IOAnswer("/OWNER/USERS/SWITCH_MOD", false)
|
if(!data["userId"] || !data["guildId"]) return IOAnswer("/OWNER/USERS/SWITCH_MOD", false)
|
||||||
@@ -871,6 +917,25 @@ function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateGuildConnectedUsers() {
|
||||||
|
guildConnectedUsers.clear()
|
||||||
|
// Get from discordBot
|
||||||
|
const guilds = discordBot.getGuilds()
|
||||||
|
for(var guild of guilds) {
|
||||||
|
const members = discordBot.getGuildMembers(guild[0])
|
||||||
|
if(!members) continue
|
||||||
|
for(var member of members) {
|
||||||
|
const user = users.getUserById(member)
|
||||||
|
if(user && allConnectedUsers.includes(user.identity)) {
|
||||||
|
if(!guildConnectedUsers.has(guild[0])) {
|
||||||
|
guildConnectedUsers.set(guild[0], new Array())
|
||||||
|
}
|
||||||
|
guildConnectedUsers.get(guild[0]).push(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@@ -17,7 +17,7 @@ async function getDiscordUser(sessionId, auth_code) {
|
|||||||
params.append("client_secret", getClientSecret());
|
params.append("client_secret", getClientSecret());
|
||||||
params.append("grant_type", "authorization_code");
|
params.append("grant_type", "authorization_code");
|
||||||
params.append("code", auth_code);
|
params.append("code", auth_code);
|
||||||
params.append("redirect_uri", getWebsiteLink() + "/callback");
|
params.append("redirect_uri", getWebsiteLink() + "/redirect");
|
||||||
params.append("scope", "identify guilds");
|
params.append("scope", "identify guilds");
|
||||||
|
|
||||||
fetch("https://discord.com/api/oauth2/token", {
|
fetch("https://discord.com/api/oauth2/token", {
|
||||||
@@ -112,6 +112,7 @@ function getUserGuilds(accessToken) {
|
|||||||
}).then(guildsResp => guildsResp.json()).then(guilds => {
|
}).then(guildsResp => guildsResp.json()).then(guilds => {
|
||||||
if (guilds.error) {
|
if (guilds.error) {
|
||||||
dlog.error("Erreur lors de la récupération des guildes de l'utilisateur Discord : " + guilds.error + " : " + guilds.error_description);
|
dlog.error("Erreur lors de la récupération des guildes de l'utilisateur Discord : " + guilds.error + " : " + guilds.error_description);
|
||||||
|
dlog.log(accessToken.token_type + " " + accessToken.access_token )
|
||||||
resolve(null);
|
resolve(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@@ -158,8 +158,36 @@ class User {
|
|||||||
return this.labels.includes(ownerLabel);
|
return this.labels.includes(ownerLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
justUpdated() {
|
||||||
|
const userInUserList = userList.find(user => user.identity.id === this.identity.id);
|
||||||
|
if (!userInUserList) {
|
||||||
|
clog.warn(`Utilisateur ${this.identity.username} non trouvé dans la liste des utilisateurs.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
userInUserList.labels = userInUserList.labels.filter(label => !label.startsWith("UPDATED["));
|
||||||
|
userInUserList.labels.push("UPDATED[" + new Date().toISOString() + "]");
|
||||||
|
saveUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
needUpdate() {
|
||||||
|
const userInUserList = userList.find(user => user.identity.id === this.identity.id);
|
||||||
|
if (!userInUserList) {
|
||||||
|
clog.warn(`Utilisateur ${this.identity.username} non trouvé dans la liste des utilisateurs.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const lastUpdate = userInUserList.labels.find(label => label.startsWith("UPDATED["));
|
||||||
|
if (lastUpdate) {
|
||||||
|
const date = new Date(lastUpdate.replace("UPDATED[", "").replace("]", ""));
|
||||||
|
const now = new Date();
|
||||||
|
const diff = now - date;
|
||||||
|
// Check for 30 seconds
|
||||||
|
clog.log(`Dernière mise à jour de l'utilisateur ${this.identity.username} : ${date.toISOString()} (${diff} ms) - Besoin de mise à jour : ${diff > 30000}`);
|
||||||
|
// If the difference is greater than 30 seconds, we need to update
|
||||||
|
return diff > 30000; // 30 seconds
|
||||||
|
}
|
||||||
|
clog.log(`Aucune mise à jour n'a été effectuée pour l'utilisateur ${this.identity.username}.`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +269,7 @@ async function updateGuilds(id) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
saveUsers();
|
saveUsers();
|
||||||
|
|
||||||
return user.guilds;
|
return user.guilds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,6 +537,14 @@ function saveUsers() {
|
|||||||
return loadUsers();
|
return loadUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearNeedUpdateForUsers() {
|
||||||
|
userList.forEach(user => {
|
||||||
|
user.labels = user.labels.filter(label => !label.startsWith("UPDATED["));
|
||||||
|
});
|
||||||
|
saveUsers();
|
||||||
|
clog.log("Nettoyage des mises à jour nécessaires pour tous les utilisateurs.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {User}
|
module.exports = {User}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -528,5 +565,6 @@ module.exports = {
|
|||||||
updateCredientials,
|
updateCredientials,
|
||||||
refreshAllUserInformation,
|
refreshAllUserInformation,
|
||||||
updateGuilds,
|
updateGuilds,
|
||||||
updateIdentity
|
updateIdentity,
|
||||||
|
clearNeedUpdateForUsers
|
||||||
};
|
};
|
Reference in New Issue
Block a user