test
This commit is contained in:
parent
8677ad506a
commit
fa001ec812
3
index.js
3
index.js
@ -90,4 +90,5 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
setInterval(() => { update(headers, client); }, 1000);
|
||||
const displayerIntervalMs = Number(process.env.DISPLAYER_INTERVAL_MS || 120000);
|
||||
setInterval(() => { update(client); }, displayerIntervalMs);
|
||||
@ -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}`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user