From fa001ec81204dd0b511ef940fd2371b9a89b13fd Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Thu, 16 Apr 2026 00:38:23 +0200 Subject: [PATCH] test --- index.js | 3 ++- src/pterodactyl/displayer.js | 49 ++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 9abfe2d..4824053 100644 --- a/index.js +++ b/index.js @@ -90,4 +90,5 @@ client.on(Events.InteractionCreate, async interaction => { client.login(process.env.DISCORD_TOKEN); -setInterval(() => { update(headers, client); }, 1000); \ No newline at end of file +const displayerIntervalMs = Number(process.env.DISPLAYER_INTERVAL_MS || 120000); +setInterval(() => { update(client); }, displayerIntervalMs); \ No newline at end of file diff --git a/src/pterodactyl/displayer.js b/src/pterodactyl/displayer.js index f49ad05..11c103d 100644 --- a/src/pterodactyl/displayer.js +++ b/src/pterodactyl/displayer.js @@ -1,4 +1,42 @@ const { EmbedBuilder } = require('discord.js'); + +let pinboardCursor = 0; + +const parsePinboardImageUrls = () => { + const raw = process.env.PINBOARD_IMAGE_URLS || ''; + return raw + .split(',') + .map(url => url.trim()) + .filter(url => /^https?:\/\//i.test(url)); +}; + +const selectPinboardWindow = (urls, maxCount) => { + if (urls.length === 0 || maxCount <= 0) { + return []; + } + + const count = Math.min(maxCount, urls.length); + const selected = []; + + for (let i = 0; i < count; i += 1) { + const index = (pinboardCursor + i) % urls.length; + selected.push(urls[index]); + } + + pinboardCursor = (pinboardCursor + count) % urls.length; + return selected; +}; + +const buildPinboardEmbeds = (urls) => { + const selectedUrls = selectPinboardWindow(urls, 4); + return selectedUrls.map((url, index) => ( + new EmbedBuilder() + .setColor('#f59e0b') + .setTitle(`Pin board ${index + 1}`) + .setImage(url) + )); +}; + const getMinecraftStatus = async () => { const address = process.env.MINECRAFT_SERVER_ADDRESS; @@ -34,8 +72,7 @@ const getMinecraftStatus = async () => { const buildPanelEmbed = (status) => { const stateText = status.online ? "🟒 En ligne" : "πŸ”΄ Hors ligne"; const playersText = `${status.playersOnline}/${status.playersMax}`; - console.log(status.playerList); - const playersListText = status.playerList.length > 0 ? status.playerList.join(", ") : "Aucun joueur connecte"; + const playersListText = status.playerList.length > 0 ? status.playerList.array.map(element => element.name).join(", ") : "Aucun joueur connecte"; const message = new EmbedBuilder() .setColor('#0099ff') .setDescription('# Informations sur le Serveur \n\n## :wireless: IP :\n### goofymon.louismazin.ovh\n\n## :repeat: Γ‰tat :\n### '+stateText+'\n\n## :busts_in_silhouette: Joueurs :\n### '+playersText+'\n\n## :video_game: Version :\n### '+status.version+'\n\n## :bust_in_silhouette: Liste des joueurs :\n### '+playersListText); @@ -78,16 +115,18 @@ const update = async (client) => { } const status = await getMinecraftStatus(); - const embed = buildPanelEmbed(status, ); + const panelEmbed = buildPanelEmbed(status); + const pinboardUrls = parsePinboardImageUrls(); + const pinboardEmbeds = buildPinboardEmbeds(pinboardUrls); const { message } = await resolvePanelMessage(client, channelId, messageId); await message.edit({ content: "", - embeds: [embed] + embeds: [panelEmbed, ...pinboardEmbeds] }); - console.log(`πŸ“Š Panneau Minecraft mis a jour (${status.playersOnline}/${status.playersMax})`); + console.log(`πŸ“Š Panneau Minecraft mis a jour (${status.playersOnline}/${status.playersMax}) | Images: ${pinboardEmbeds.length}`); } catch (error) { console.log(`❌ Erreur displayer: ${error.message}`); }