test
This commit is contained in:
parent
93f5e64df7
commit
b22205a2fd
35
commands/afficher-lies.js
Normal file
35
commands/afficher-lies.js
Normal file
@ -0,0 +1,35 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { getAllLinks } = require('../database.js');
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
name: 'afficher-lies',
|
||||
description: 'Affiche la liste des comptes liés',
|
||||
},
|
||||
async execute(interaction) {
|
||||
const links = await getAllLinks();
|
||||
|
||||
if (!links || links.length === 0) {
|
||||
return interaction.reply({
|
||||
content: 'Aucun compte lié trouvé.',
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor('#00FF00')
|
||||
.setTitle('👥 Liste des comptes liés')
|
||||
.setDescription(links.map((link, index) => {
|
||||
const lastConn = link.lastConnection
|
||||
? `📅 Dernière connexion: <t:${Math.floor(new Date(link.lastConnection).getTime() / 1000)}:R>`
|
||||
: '📅 Dernière connexion: Jamais vu';
|
||||
|
||||
return `**${index + 1}.** <@${link.discordId}> ${link.discordUsername ? `(${link.discordUsername})` : ''}\n` +
|
||||
`└ 🎮 **${link.palworldName}** (Steam: \`${link.steamId}\`)\n` +
|
||||
`└ ${lastConn}`;
|
||||
}).join('\n\n'))
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
const axios = require('axios');
|
||||
const WebSocket = require('ws');
|
||||
const { verifyLinkCode, updateUserLinkWithUsername } = require('./database.js');
|
||||
const { verifyLinkCode, updateUserLinkWithUsername, updateLastConnection } = require('./database.js');
|
||||
|
||||
let ws = null;
|
||||
let reconnectTimeout = null;
|
||||
@ -25,12 +25,30 @@ const parseLogMessage = (log) => {
|
||||
console.log(`✅ Commande !lier détectée: ${playerName} avec le code ${code}`);
|
||||
|
||||
return {
|
||||
type: 'link',
|
||||
playerName: playerName,
|
||||
code: code,
|
||||
needsSteamId: true
|
||||
};
|
||||
}
|
||||
|
||||
// Détecter les déconnexions: [2025-12-09 18:55:19] [LOG] Nami left the server. (User id: gdk_2535420062888893)
|
||||
const disconnectRegex = /\[.*?\]\s*\[LOG\]\s*(.+?)\s+left the server\.\s*\(User id:\s*(.+?)\)/i;
|
||||
const disconnectMatch = log.match(disconnectRegex);
|
||||
|
||||
if (disconnectMatch) {
|
||||
const playerName = disconnectMatch[1].trim();
|
||||
const userId = disconnectMatch[2].trim();
|
||||
|
||||
console.log(`👋 Déconnexion détectée: ${playerName} (${userId})`);
|
||||
|
||||
return {
|
||||
type: 'disconnect',
|
||||
playerName: playerName,
|
||||
userId: userId
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -211,6 +229,7 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
|
||||
const linkData = parseLogMessage(log);
|
||||
|
||||
if (linkData) {
|
||||
if (linkData.type === 'link') {
|
||||
const playerData = await getSteamIdFromPlayerName(linkData.playerName);
|
||||
|
||||
if (playerData) {
|
||||
@ -219,6 +238,19 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
|
||||
} else {
|
||||
console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`);
|
||||
}
|
||||
} else if (linkData.type === 'disconnect') {
|
||||
// Extraire le Steam ID du userId (format: gdk_STEAMID)
|
||||
const steamIdMatch = linkData.userId.match(/gdk_(\d+)/);
|
||||
if (steamIdMatch) {
|
||||
const steamId = steamIdMatch[1];
|
||||
try {
|
||||
await updateLastConnection(steamId);
|
||||
console.log(`✅ Dernière connexion mise à jour pour ${linkData.playerName} (${steamId})`);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la mise à jour de la dernière connexion:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
database.js
12
database.js
@ -57,6 +57,7 @@ const createTables = async () => {
|
||||
player_id VARCHAR(50),
|
||||
palworld_username VARCHAR(100) NOT NULL,
|
||||
linked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
lastConnection TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_discord_id (discord_id),
|
||||
INDEX idx_steam_id (steam_id),
|
||||
INDEX idx_player_id (player_id)
|
||||
@ -165,6 +166,14 @@ const cleanExpiredCodes = async () => {
|
||||
);
|
||||
};
|
||||
|
||||
const updateLastConnection = async (steamId) => {
|
||||
const connection = getConnection();
|
||||
await connection.execute(
|
||||
'UPDATE user_links SET lastConnection = NOW() WHERE steam_id = ?',
|
||||
[steamId]
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
initDatabase,
|
||||
getConnection,
|
||||
@ -177,5 +186,6 @@ module.exports = {
|
||||
deleteUserLink,
|
||||
getPendingPlayer,
|
||||
hasActiveLinkCodes,
|
||||
cleanExpiredCodes
|
||||
cleanExpiredCodes,
|
||||
updateLastConnection
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user