maintenance-bot/index.js

39 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-05-27 14:13:46 +02:00
import settings from "./libs/settings.js"
import getNotifier from "./libs/getNotifier.js"
import getLogger from "./libs/logger.js"
2022-05-28 15:03:43 +02:00
import getChecker from "./libs/getChecker.js"
2022-05-27 14:13:46 +02:00
const log = getLogger("MAIN", "blue")
log("Starting up maintenance-bot...")
2022-05-28 15:03:43 +02:00
log("Finding enabled notifiers and checkers...")
2022-05-27 14:13:46 +02:00
const enabledNotifiers = Object.keys(settings.notifiers).filter(notifier => settings.notifiers[notifier].enabled)
2022-05-28 15:03:43 +02:00
const enabledCheckers = Object.keys(settings.checkers).filter(checker => settings.checkers[checker].enabled)
log("Enabled notifiers:", enabledNotifiers)
log("Enabled checkers: ", enabledCheckers)
log("Starting up notifiers and checkers...")
2022-05-27 14:13:46 +02:00
const notifiers = await Promise.all(enabledNotifiers.map(notifier => getNotifier(notifier)))
2022-05-28 15:03:43 +02:00
const sendMessage = msg => notifiers.forEach(notifier => notifier(msg))
await Promise.all(enabledCheckers.map(checker => getChecker(checker, sendMessage)))
log("Started all checkers!")
2022-05-27 14:13:46 +02:00
2022-05-27 14:55:32 +02:00
log("Sending out start-up messages...")
2022-05-28 15:03:43 +02:00
sendMessage("Started up 'maintenance-bot'...")
log("Start up complete!")
2022-05-27 14:55:32 +02:00
2022-05-28 15:03:43 +02:00
function onExitWarn() {
sendMessage("OH NO I AM DYING!")
setTimeout(() => process.exit(0), 200)
}
process.on("beforeExit", onExitWarn)
process.on("exit", onExitWarn)
process.on("SIGINT", onExitWarn)
process.on("SIGTERM", onExitWarn)
process.on("uncaughtException", onExitWarn)
process.on("unhandledRejection", onExitWarn)