This commit is contained in:
Louis Mazin 2026-04-16 00:34:59 +02:00
parent 9a53a3fa08
commit 8677ad506a

View File

@ -31,38 +31,14 @@ const getMinecraftStatus = async () => {
}; };
}; };
const getPterodactylState = async (headers) => { const buildPanelEmbed = (status) => {
const panelUrl = process.env.PTERODACTYL_PANEL_URL;
const serverId = process.env.PTERODACTYL_SERVER_ID;
if (!headers || !panelUrl || !serverId) {
return "inconnu";
}
try {
const stateResponse = await fetch(`${panelUrl}/api/client/servers/${serverId}/resources`, {
method: "GET",
headers
});
if (!stateResponse.ok) {
return "inconnu";
}
const stateData = await stateResponse.json();
return stateData?.attributes?.current_state || "inconnu";
} catch (error) {
return "inconnu";
}
};
const buildPanelEmbed = (status, panelState) => {
const stateText = status.online ? "🟢 En ligne" : "🔴 Hors ligne"; const stateText = status.online ? "🟢 En ligne" : "🔴 Hors ligne";
const playersText = `${status.playersOnline}/${status.playersMax}`; 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.join(", ") : "Aucun joueur connecte";
const message = new EmbedBuilder() const message = new EmbedBuilder()
.setColor('#0099ff') .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## :speech_balloon: MOTD :\n### '+status.motd+'\n\n## :bust_in_silhouette: Liste des joueurs :\n### '+playersListText); .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);
return message; return message;
}; };
@ -91,7 +67,7 @@ const resolvePanelMessage = async (client, channelId, messageId) => {
return { channel, message: newMessage }; return { channel, message: newMessage };
}; };
const update = async (headers, client) => { const update = async (client) => {
try { try {
const channelId = process.env.DISPLAYER_CHANNEL_ID; const channelId = process.env.DISPLAYER_CHANNEL_ID;
const messageId = process.env.DISPLAYER_MESSAGE_ID; const messageId = process.env.DISPLAYER_MESSAGE_ID;
@ -102,8 +78,7 @@ const update = async (headers, client) => {
} }
const status = await getMinecraftStatus(); const status = await getMinecraftStatus();
const panelState = await getPterodactylState(headers); const embed = buildPanelEmbed(status, );
const embed = buildPanelEmbed(status, panelState);
const { message } = await resolvePanelMessage(client, channelId, messageId); const { message } = await resolvePanelMessage(client, channelId, messageId);