discord webhook logging
This commit is contained in:
parent
89fb5f2d2a
commit
928175abb0
16
src/index.ts
16
src/index.ts
|
@ -6,7 +6,7 @@ import { exec } from 'child_process';
|
||||||
|
|
||||||
config();
|
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 (!DISCORD_TOKEN) throw '$DISCORD_TOKEN not set';
|
||||||
if (!REVOLT_TOKEN) throw '$REVOLT_TOKEN not set';
|
if (!REVOLT_TOKEN) throw '$REVOLT_TOKEN not set';
|
||||||
|
@ -76,7 +76,9 @@ const periodicCheck = async () => {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const whClient = RESTART_WEBHOOK ? new Discord.WebhookClient({ url: RESTART_WEBHOOK }) : null;
|
||||||
const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) => {
|
const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) => {
|
||||||
|
|
||||||
if (!status.watchdog.bot && !restarting.bot && RESTART_COMMAND_BOT) {
|
if (!status.watchdog.bot && !restarting.bot && RESTART_COMMAND_BOT) {
|
||||||
console.log('Restarting bot');
|
console.log('Restarting bot');
|
||||||
try {
|
try {
|
||||||
|
@ -84,12 +86,16 @@ const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) =>
|
||||||
const result = exec(RESTART_COMMAND_BOT!);
|
const result = exec(RESTART_COMMAND_BOT!);
|
||||||
result.stdout?.on('data', data => console.log(data));
|
result.stdout?.on('data', data => console.log(data));
|
||||||
result.stderr?.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) {
|
if (code != 0) {
|
||||||
console.log('Bot: Restart command seems to have failed!');
|
console.log('Bot: Restart command seems to have failed!');
|
||||||
restarting.bot = false;
|
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) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
@ -102,12 +108,16 @@ const runRestarts = async (status: Awaited<ReturnType<typeof periodicCheck>>) =>
|
||||||
const result = exec(RESTART_COMMAND_BRIDGE!);
|
const result = exec(RESTART_COMMAND_BRIDGE!);
|
||||||
result.stdout?.on('data', data => console.log(data));
|
result.stdout?.on('data', data => console.log(data));
|
||||||
result.stderr?.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) {
|
if (code != 0) {
|
||||||
console.log('Bridge: Restart command seems to have failed!');
|
console.log('Bridge: Restart command seems to have failed!');
|
||||||
restarting.bridge = false;
|
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) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue