oui
This commit is contained in:
parent
4c804e4d39
commit
2f11029b66
123
commands/utility/afficher-inactifs.js
Normal file
123
commands/utility/afficher-inactifs.js
Normal file
@ -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 = `<t:${Math.floor(lastDate.getTime() / 1000)}:R>`;
|
||||
}
|
||||
|
||||
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 = `<t:${Math.floor(lastDate.getTime() / 1000)}:R>`;
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user