feat(status): enhance status command with image attachment and update query logic

This commit is contained in:
2025-11-25 10:37:00 +01:00
parent e41be1e1f0
commit 401ae56113
2 changed files with 9 additions and 8 deletions

View File

@@ -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 statusService from "../../services/status.service";
import { CommandDefinition} from "../../type"; import { CommandDefinition} from "../../type";
@@ -17,7 +17,9 @@ const cmd : CommandDefinition = {
), ),
async execute(interaction : ChatInputCommandInteraction) { async execute(interaction : ChatInputCommandInteraction) {
await interaction.deferReply(); 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]});
} }
} }

View File

@@ -195,7 +195,7 @@ export class StatusService {
public async getStatusImageBar(host: string) { public async getStatusImageBar(host: string) {
const datas = await this.hostsLogRepo.createQueryBuilder() 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) => { 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); ctx.fillRect(value.min, 0, value.max - value.min, canvas.height);
}); });
return canvas.toDataURL(); return canvas.toBuffer('image/png');
} }
private async updateClientStatus() { private async updateClientStatus() {
@@ -403,11 +403,10 @@ export class StatusService {
}); });
container.addSeparatorComponents((s) => s); container.addSeparatorComponents((s) => s);
container.addTextDisplayComponents((t) => t.setContent('This is a status bar to test : (Ryzen7)'))
let status = await this.getStatusImageBar('154.16.254.10');
container.addMediaGalleryComponents((m) => m 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 : ' : ''}<t:${dayjs().unix()}:f> - Receive automatic notifications when there is an outage with /follow !`)); container.addTextDisplayComponents((text) => text.setContent(`:globe_with_meridians: Website Status : https://statut.protojx.com/\n${live ? 'Last update : ' : ''}<t:${dayjs().unix()}:f> - Receive automatic notifications when there is an outage with /follow !`));