discord webhook logging

This commit is contained in:
Lea 2023-04-29 08:47:57 +02:00
parent 89fb5f2d2a
commit 928175abb0
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -6,7 +6,7 @@ import { exec } from 'child_process';
config();
const { DISCORD_TOKEN, REVOLT_TOKEN, DISCORD_CHANNEL, REVOLT_CHANNEL, PORT, RESTART_COMMAND_BOT, RESTART_COMMAND_BRIDGE } = process.env;
const { DISCORD_TOKEN, REVOLT_TOKEN, DISCORD_CHANNEL, REVOLT_CHANNEL, PORT, RESTART_COMMAND_BOT, RESTART_COMMAND_BRIDGE, RESTART_WEBHOOK } = process.env;
if (!DISCORD_TOKEN) throw '$DISCORD_TOKEN not set';
if (!REVOLT_TOKEN) throw '$REVOLT_TOKEN not set';
@ -76,7 +76,9 @@ const periodicCheck = async () => {
return response;
}
const whClient = RESTART_WEBHOOK ? new Discord.WebhookClient({ url: RESTART_WEBHOOK }) : null;
const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) => {
if (!status.watchdog.bot && !restarting.bot && RESTART_COMMAND_BOT) {
console.log('Restarting bot');
try {
@ -84,12 +86,16 @@ const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) =>
const result = exec(RESTART_COMMAND_BOT!);
result.stdout?.on('data', data => console.log(data));
result.stderr?.on('data', data => console.log(data));
result.on('exit', code => {
result.on('exit', async (code) => {
if (code != 0) {
console.log('Bot: Restart command seems to have failed!');
restarting.bot = false;
await whClient?.send(`Bot restart command failed with status ${code}`);
}
else await whClient?.send(`Bot restart command finished successfully!`);
});
await whClient?.send('Restarting bot');
} catch(e) {
console.log(e);
}
@ -102,12 +108,16 @@ const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) =>
const result = exec(RESTART_COMMAND_BRIDGE!);
result.stdout?.on('data', data => console.log(data));
result.stderr?.on('data', data => console.log(data));
result.on('exit', code => {
result.on('exit', async (code) => {
if (code != 0) {
console.log('Bridge: Restart command seems to have failed!');
restarting.bridge = false;
await whClient?.send(`Bridge restart command failed with status ${code}`);
}
else await whClient?.send(`Bridge restart command finished successfully!`);
});
await whClient?.send('Restarting bridge');
} catch(e) {
console.log(e);
}