From 0bd3408c8ed372a75562d0e7f39ae7645b88371f Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Tue, 13 Jan 2026 00:12:40 +0100 Subject: [PATCH] nice --- commands/utility/afficher-lies.js | 11 +---- commands/utility/info.js | 71 +++++++++++++++++++++++++++++++ consoleMonitor.js | 45 ++++++++++++-------- 3 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 commands/utility/info.js diff --git a/commands/utility/afficher-lies.js b/commands/utility/afficher-lies.js index 3d20c4f..6114b76 100644 --- a/commands/utility/afficher-lies.js +++ b/commands/utility/afficher-lies.js @@ -36,19 +36,12 @@ module.exports = { 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}>`; - const lastConn = link.lastConnection - ? `📅 Dernière connexion: ` - : '📅 Dernière connexion: Jamais vu'; embed.addFields({ name: `👤 ${discordName}`, value: `${discordMention} -🎮 Palworld: **${link.palworld_username}** -🆔 Steam ID: \`${link.steam_id}\` -🎯 Player ID: \`${link.player_id || 'N/A'}\` -${lastConn} -📅 Lié le: ${new Date(link.linked_at).toLocaleDateString('fr-FR')}`, - inline: false +🎮 Palworld: **${link.palworld_username}**`, + inline: true }); } } diff --git a/commands/utility/info.js b/commands/utility/info.js new file mode 100644 index 0000000..9fc9c69 --- /dev/null +++ b/commands/utility/info.js @@ -0,0 +1,71 @@ +const { SlashCommandBuilder, EmbedBuilder, MessageFlags } = require('discord.js'); +const { getUserLink } = require('../../database.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('info') + .setDescription('Afficher les informations détaillées d\'un compte lié') + .addUserOption(option => + option.setName('utilisateur') + .setDescription('L\'utilisateur Discord dont vous voulez voir les informations') + .setRequired(true)), + + async execute(interaction) { + try { + await interaction.deferReply({}); + + const targetUser = interaction.options.getUser('utilisateur'); + const link = await getUserLink(targetUser.id); + + if (!link) { + return interaction.editReply({ + content: `❌ Aucun compte lié trouvé pour ${targetUser.globalName || targetUser.username}.`, + flags: MessageFlags.Ephemeral + }); + } + + const lastConn = link.lastConnection + ? `` + : 'Jamais vu'; + + const linkedDate = ``; + + const embed = new EmbedBuilder() + .setColor(0x0099FF) + .setTitle('📋 Informations du compte lié') + .setThumbnail(targetUser.displayAvatarURL({ dynamic: true })) + .addFields( + { + name: '👤 Discord', + value: `**Nom:** ${targetUser.globalName || targetUser.username}\n**Mention:** <@${targetUser.id}>\n**ID:** \`${targetUser.id}\``, + inline: false + }, + { + name: '🎮 Palworld', + value: `**Pseudo:** ${link.palworld_username}\n**Player ID:** \`${link.player_id || 'N/A'}\``, + inline: true + }, + { + name: '🎯 Steam', + value: `**Steam ID:** \`${link.steam_id}\``, + inline: true + }, + { + name: '📅 Dates', + value: `**Lié le:** ${linkedDate}\n**Dernière connexion:** ${lastConn}`, + inline: false + } + ) + .setTimestamp(); + + await interaction.editReply({ embeds: [embed] }); + + } catch (error) { + console.error('Erreur lors de la récupération des informations:', error); + await interaction.editReply({ + content: '❌ Une erreur est survenue lors de la récupération des informations.', + flags: MessageFlags.Ephemeral + }); + } + }, +}; diff --git a/consoleMonitor.js b/consoleMonitor.js index 3123ef8..550f78e 100644 --- a/consoleMonitor.js +++ b/consoleMonitor.js @@ -325,25 +325,34 @@ const connectWebSocket = async (pterodactylToken, serverId) => { if (linkData) { if (linkData.type === 'link') { - const playerData = await getSteamIdFromPlayerName(linkData.playerName); - - if (playerData) { - await handleLinkCommand(linkData.playerName, playerData, linkData.code); - // Ne plus vérifier si on doit fermer le WebSocket - } else { - console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`); - } - } else if (linkData.type === 'disconnect') { - try { - const result = await updateLastConnection(linkData.userId); - if (result.changes > 0) { - console.log(`✅ Dernière connexion mise à jour pour ${linkData.playerName} (${linkData.userId})`); - } else { - console.log(`ℹ️ Aucun compte lié trouvé pour ${linkData.playerName} (${linkData.userId})`); + // Traiter de manière asynchrone sans bloquer le handler WebSocket + (async () => { + try { + const playerData = await getSteamIdFromPlayerName(linkData.playerName); + + if (playerData) { + await handleLinkCommand(linkData.playerName, playerData, linkData.code); + } else { + console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`); + } + } catch (error) { + console.error(`❌ Erreur lors du traitement de !lier pour ${linkData.playerName}:`, error); } - } catch (error) { - console.error('Erreur lors de la mise à jour de la dernière connexion:', error); - } + })(); + } else if (linkData.type === 'disconnect') { + // Traiter de manière asynchrone sans bloquer le handler WebSocket + (async () => { + try { + const result = await updateLastConnection(linkData.userId); + if (result.changes > 0) { + console.log(`✅ Dernière connexion mise à jour pour ${linkData.playerName} (${linkData.userId})`); + } else { + console.log(`ℹ️ Aucun compte lié trouvé pour ${linkData.playerName} (${linkData.userId})`); + } + } catch (error) { + console.error('Erreur lors de la mise à jour de la dernière connexion:', error); + } + })(); } } }