From 401ae56113cd036ce6cbccf0ae7572362f5f7e95 Mon Sep 17 00:00:00 2001 From: thedrewen Date: Tue, 25 Nov 2025 10:37:00 +0100 Subject: [PATCH] feat(status): enhance status command with image attachment and update query logic --- src/commands/utility/statut.command.ts | 6 ++++-- src/services/status.service.ts | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/commands/utility/statut.command.ts b/src/commands/utility/statut.command.ts index 796adea..ecefca5 100644 --- a/src/commands/utility/statut.command.ts +++ b/src/commands/utility/statut.command.ts @@ -1,4 +1,4 @@ -import { ApplicationIntegrationType, ChatInputCommandInteraction, InteractionContextType, MessageFlags, SlashCommandBuilder } from "discord.js"; +import { ApplicationIntegrationType, AttachmentBuilder, ChatInputCommandInteraction, InteractionContextType, MessageFlags, SlashCommandBuilder } from "discord.js"; import statusService from "../../services/status.service"; import { CommandDefinition} from "../../type"; @@ -17,7 +17,9 @@ const cmd : CommandDefinition = { ), async execute(interaction : ChatInputCommandInteraction) { await interaction.deferReply(); - await interaction.editReply({components: [await statusService.getUpdatedContainer()], flags: MessageFlags.IsComponentsV2}); + let status = await statusService.getStatusImageBar('154.16.254.10'); + const attachment = new AttachmentBuilder(status, {name: 'status.png'}); + await interaction.editReply({components: [await statusService.getUpdatedContainer()], flags: MessageFlags.IsComponentsV2, files: [attachment]}); } } diff --git a/src/services/status.service.ts b/src/services/status.service.ts index c9fc059..03f227e 100644 --- a/src/services/status.service.ts +++ b/src/services/status.service.ts @@ -195,7 +195,7 @@ export class StatusService { public async getStatusImageBar(host: string) { const datas = await this.hostsLogRepo.createQueryBuilder() - .where('created_at > :date', {date: dayjs().subtract(1, 'week').toDate()}).getMany(); + .where('host = :host AND created_at > :date', {host, date: dayjs().subtract(1, 'week').toDate()}).getMany(); const uptimes : { up: boolean, date: Dayjs }[] = datas.map((log) => { @@ -256,7 +256,7 @@ export class StatusService { ctx.fillRect(value.min, 0, value.max - value.min, canvas.height); }); - return canvas.toDataURL(); + return canvas.toBuffer('image/png'); } private async updateClientStatus() { @@ -403,11 +403,10 @@ export class StatusService { }); container.addSeparatorComponents((s) => s); - - let status = await this.getStatusImageBar('154.16.254.10'); + container.addTextDisplayComponents((t) => t.setContent('This is a status bar to test : (Ryzen7)')) container.addMediaGalleryComponents((m) => m - .addItems((i) => i.setURL(status)) - ) + .addItems((i) => i.setURL('attachment://status.png')) + ); container.addTextDisplayComponents((text) => text.setContent(`:globe_with_meridians: Website Status : https://statut.protojx.com/\n${live ? 'Last update : ' : ''} - Receive automatic notifications when there is an outage with /follow !`));