diff --git a/src/commands/utility/statut.command.ts b/src/commands/utility/statut.command.ts index e600ab1..f098265 100644 --- a/src/commands/utility/statut.command.ts +++ b/src/commands/utility/statut.command.ts @@ -19,57 +19,7 @@ const cmd : CommandDefinition = { ), async execute(interaction : ChatInputCommandInteraction) { await interaction.deferReply(); - - const hostTexts = statusService.hosts.map((s) => { - return {type: s.type, value: `- ${s.name} : ${s.alive ? `${process.env.EMOJI_STATUS_ONLINE} Online` : `${process.env.EMOJI_STATUS_OFFLINE} Offline`}`}; - }); - - const container = new ContainerBuilder() - .setAccentColor(0x0000ed) - .addTextDisplayComponents((text) => text.setContent('# Status of protojx servers')) - - const sections : {title: string, type: InfraType, thumbnail: string}[] = [ - { - title: 'Websites', - type: 'website', - thumbnail: 'https://protojx.com/assets/img/home2/agent.png' - }, - { - title: 'Ryzens', - type: 'ryzen', - thumbnail: 'https://iconape.com/wp-content/png_logo_vector/ryzen.png' - }, - { - title: 'Xeons', - type: 'xeon', - thumbnail: 'https://upload.wikimedia.org/wikipedia/commons/3/31/Intel-Xeon-Badge-2024.jpg' - }, - { - title: 'Games', - type: 'games', - thumbnail: 'https://protojx.com/assets/img/hero-img.png' - } - ] - - sections.map((sectionData) => { - container.addSeparatorComponents((s) => s) - container.addSectionComponents( - (section) => - section.addTextDisplayComponents( - (text) => - text.setContent('## '+sectionData.title+'\n'+hostTexts.filter((v) => v.type == sectionData.type).map((v) => v.value).join('\n')) - ) - .setThumbnailAccessory( - (acc) => - acc.setURL(sectionData.thumbnail) - ) - ) - }); - - const now = new Date(); - container.addTextDisplayComponents((text) => text.setContent(`${now.getDate()}-${now.getMonth() + 1}-${now.getFullYear()} ${(now.getHours()+'').padStart(2, "0")}:${(now.getMinutes()+'').padStart(2, "0")}`)) - - await interaction.editReply({components: [container], flags: MessageFlags.IsComponentsV2}); + await interaction.editReply({components: [statusService.getUpdatedContainer()], flags: MessageFlags.IsComponentsV2}); } } diff --git a/src/services/status.service.ts b/src/services/status.service.ts index 7a666e0..a0b1620 100644 --- a/src/services/status.service.ts +++ b/src/services/status.service.ts @@ -1,7 +1,7 @@ import ping from "ping"; import * as cron from 'cron'; -import { ActivityType, Client } from "discord.js"; -import { Host } from "../type"; +import { ActivityType, Client, ContainerBuilder } from "discord.js"; +import { Host, InfraType } from "../type"; import { loadEnvFile } from "process"; import { configDotenv } from "dotenv"; @@ -155,6 +155,59 @@ export class StatusService { return this.hosts; } + + public getUpdatedContainer() : ContainerBuilder { + const hostTexts = this.hosts.map((s) => { + return {type: s.type, value: `- ${s.name} : ${s.alive ? `${process.env.EMOJI_STATUS_ONLINE} Online` : `${process.env.EMOJI_STATUS_OFFLINE} Offline`}`}; + }); + + const container = new ContainerBuilder() + .setAccentColor(0x0000ed) + .addTextDisplayComponents((text) => text.setContent('# Status of protojx services')); + + const sections : {title: string, type: InfraType, thumbnail: string}[] = [ + { + title: 'Websites', + type: 'website', + thumbnail: 'https://protojx.com/assets/img/home2/agent.png' + }, + { + title: 'Ryzens', + type: 'ryzen', + thumbnail: 'https://iconape.com/wp-content/png_logo_vector/ryzen.png' + }, + { + title: 'Xeons', + type: 'xeon', + thumbnail: 'https://upload.wikimedia.org/wikipedia/commons/3/31/Intel-Xeon-Badge-2024.jpg' + }, + { + title: 'Games', + type: 'games', + thumbnail: 'https://protojx.com/assets/img/hero-img.png' + } + ] + + sections.map((sectionData) => { + container.addSeparatorComponents((s) => s) + container.addSectionComponents( + (section) => + section.addTextDisplayComponents( + (text) => + text.setContent('## '+sectionData.title+'\n'+hostTexts.filter((v) => v.type == sectionData.type).map((v) => v.value).join('\n')) + ) + .setThumbnailAccessory( + (acc) => + acc.setURL(sectionData.thumbnail) + ) + ) + }); + + const now = new Date(); + container.addTextDisplayComponents((text) => text.setContent(`${now.getDate()}-${now.getMonth() + 1}-${now.getFullYear()} ${(now.getHours()+'').padStart(2, "0")}:${(now.getMinutes()+'').padStart(2, "0")}`)); + + return container; + } } export default new StatusService(); \ No newline at end of file