From 2f11029b66b958cbb96a1b995ee17b19a3207659 Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Wed, 28 Jan 2026 12:38:41 +0100 Subject: [PATCH] oui --- commands/utility/afficher-inactifs.js | 123 ++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 commands/utility/afficher-inactifs.js diff --git a/commands/utility/afficher-inactifs.js b/commands/utility/afficher-inactifs.js new file mode 100644 index 0000000..8fd1d3e --- /dev/null +++ b/commands/utility/afficher-inactifs.js @@ -0,0 +1,123 @@ +const { SlashCommandBuilder, EmbedBuilder, MessageFlags } = require('discord.js'); +const { getAllLinks } = require('../../database.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('afficher-inactifs') + .setDescription('Afficher les membres inactifs ou absents du serveur'), + + async execute(interaction) { + try { + await interaction.deferReply({}); + + const links = await getAllLinks(); + + if (links.length === 0) { + return interaction.editReply({ + content: '📝 Aucun compte lié pour le moment.', + flags: MessageFlags.Ephemeral + }); + } + + const threeMonthsAgo = new Date(); + threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3); + + const inactiveMembers = []; + const notInServer = []; + + // Vérifier chaque lien + for (const link of links) { + // Vérifier si le membre est toujours sur le serveur + const member = await interaction.guild.members.fetch(link.discord_id).catch(() => null); + + if (!member) { + // Membre n'est plus sur le serveur + notInServer.push(link); + } else if (link.lastConnection) { + // Vérifier si inactif depuis plus de 3 mois + const lastConn = new Date(link.lastConnection); + if (lastConn < threeMonthsAgo) { + inactiveMembers.push(link); + } + } + } + + const embeds = []; + + // Embed pour les absents depuis + de 3 mois + if (inactiveMembers.length > 0) { + const embed = new EmbedBuilder() + .setColor(0xFF6B00) + .setTitle('⏰ Membres inactifs (+ de 3 mois)') + .setDescription(`Total: **${inactiveMembers.length}** membre(s) inactif(s)`) + .setTimestamp(); + + for (const link of inactiveMembers) { + const user = await interaction.client.users.fetch(link.discord_id).catch(() => null); + const discordName = user ? (user.globalName ? user.globalName : user.username) : link.discord_username; + const discordMention = `<@${link.discord_id}>`; + + // Calculer le temps depuis la dernière connexion + let lastConnectionText = ''; + if (link.lastConnection) { + const lastDate = new Date(link.lastConnection); + lastConnectionText = ``; + } + + embed.addFields({ + name: `👤 ${discordName} - 🎮 ${link.palworld_username}`, + value: `${discordMention} - Dernière connexion: ${lastConnectionText}` + }); + } + + embeds.push(embed); + } + + // Embed pour les membres qui ne sont plus sur le serveur + if (notInServer.length > 0) { + const embed = new EmbedBuilder() + .setColor(0xFF0000) + .setTitle('👻 Membres liés mais absents du serveur Discord') + .setDescription(`Total: **${notInServer.length}** membre(s) absent(s)`) + .setTimestamp(); + + for (const link of notInServer) { + const user = await interaction.client.users.fetch(link.discord_id).catch(() => null); + const discordName = user ? (user.globalName ? user.globalName : user.username) : link.discord_username; + const discordMention = `<@${link.discord_id}>`; + + // Calculer le temps depuis la dernière connexion + let lastConnectionText = 'Jamais connecté'; + if (link.lastConnection) { + const lastDate = new Date(link.lastConnection); + lastConnectionText = ``; + } + + embed.addFields({ + name: `👤 ${discordName} - 🎮 ${link.palworld_username}`, + value: `${discordMention} - Dernière connexion: ${lastConnectionText}` + }); + } + + embeds.push(embed); + } + + // Si aucun inactif + if (embeds.length === 0) { + return interaction.editReply({ + content: '✅ Aucun membre inactif ou absent du serveur !', + flags: MessageFlags.Ephemeral + }); + } + + await interaction.editReply({ embeds }); + + } catch (error) { + console.error('Erreur lors de la récupération des inactifs:', error); + await interaction.editReply({ + content: '❌ Une erreur est survenue lors de la récupération des membres inactifs.', + flags: MessageFlags.Ephemeral + }); + } + }, +};