mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-21 09:48:56 +01:00
feat(status): refactor status command to utilize centralized container generation in status service
This commit is contained in:
@@ -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();
|
||||
Reference in New Issue
Block a user