mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-23 05:01:54 +01:00
Status update for server statuses.
This commit is contained in:
@@ -5,11 +5,12 @@ A status bot and other features for protojx.
|
|||||||
|
|
||||||
| Description | Status |
|
| Description | Status |
|
||||||
|-------------|--------|
|
|-------------|--------|
|
||||||
| /status command | ✅ |
|
| /status command | 🌐 |
|
||||||
| Number of services down in the bot's status. | ➖ |
|
| Number of services down in the bot's status. | ✅ |
|
||||||
| Notification system in case of downtime. | ➖ |
|
| Notification system in case of downtime. | ➖ |
|
||||||
| Deployment workflow on Raspberry Pi. | ➖ |
|
| Deployment workflow on Raspberry Pi. | ➖ |
|
||||||
|
|
||||||
|
- 🌐 -> In production
|
||||||
- ✅ -> Done
|
- ✅ -> Done
|
||||||
- 🚧 -> Under development
|
- 🚧 -> Under development
|
||||||
- ➖ -> Not started
|
- ➖ -> Not started
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Client, Collection, Events, GatewayIntentBits, MessageFlags } from "dis
|
|||||||
import { configDotenv } from "dotenv";
|
import { configDotenv } from "dotenv";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import statusService from "./services/status.service";
|
||||||
|
|
||||||
configDotenv();
|
configDotenv();
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
|
|
||||||
client.once(Events.ClientReady, readyClient => {
|
client.once(Events.ClientReady, readyClient => {
|
||||||
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
||||||
|
statusService.setClient(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.TOKEN)
|
client.login(process.env.TOKEN)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import ping from "ping";
|
import ping from "ping";
|
||||||
import * as cron from 'cron';
|
import * as cron from 'cron';
|
||||||
|
import { ActivityType, Client } from "discord.js";
|
||||||
|
|
||||||
export class StatusService {
|
export class StatusService {
|
||||||
|
|
||||||
@@ -60,10 +61,13 @@ export class StatusService {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
private client : Client|null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const cronJob = new cron.CronJob('*/2 * * * *', async () => {
|
const cronJob = new cron.CronJob('*/2 * * * *', async () => {
|
||||||
try {
|
try {
|
||||||
await this.fetch();
|
await this.fetch();
|
||||||
|
await this.updateClientStatus();
|
||||||
console.log('Status check completed at:', new Date().toISOString());
|
console.log('Status check completed at:', new Date().toISOString());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error during status check:', error);
|
console.error('Error during status check:', error);
|
||||||
@@ -73,7 +77,23 @@ export class StatusService {
|
|||||||
console.log('Status monitoring started - checking every 2 minutes');
|
console.log('Status monitoring started - checking every 2 minutes');
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch(max = 1): Promise<Host[]> {
|
setClient(client : Client) {
|
||||||
|
this.client = client;
|
||||||
|
this.client.user?.setActivity({name: '💭 Server load and status...'})
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateClientStatus() {
|
||||||
|
if(this.client) {
|
||||||
|
const hosts = this.hosts.length;
|
||||||
|
const hostsAlive = this.hosts.filter((h) => h.alive).length;
|
||||||
|
|
||||||
|
this.client.user?.setActivity({name: (
|
||||||
|
hosts == hostsAlive ? '✅ All services are online.' : `📛 ${hosts - hostsAlive} service${hosts - hostsAlive > 1 ? 's' : ''} offline.`
|
||||||
|
), type: ActivityType.Watching});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetch(max = 1): Promise<Host[]> {
|
||||||
|
|
||||||
const hosts = this.hosts.filter((value, index) => index < max * 10 && index >= (max - 1) * 10);
|
const hosts = this.hosts.filter((value, index) => index < max * 10 && index >= (max - 1) * 10);
|
||||||
async function fetchAlive(host: Host) {
|
async function fetchAlive(host: Host) {
|
||||||
|
|||||||
Reference in New Issue
Block a user