import settings from "./libs/settings.js" import getNotifier from "./libs/getNotifier.js" import getLogger from "./libs/logger.js" import getChecker from "./libs/getChecker.js" const log = getLogger("MAIN", "blue") log("Starting up maintenance-bot...") log("Finding enabled notifiers and checkers...") const enabledNotifiers = Object.keys(settings.notifiers).filter(notifier => settings.notifiers[notifier].enabled) 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...") const notifiers = await Promise.all(enabledNotifiers.map(notifier => getNotifier(notifier))) const sendMessage = msg => notifiers.forEach(notifier => notifier(msg)) await Promise.all(enabledCheckers.map(checker => getChecker(checker, sendMessage))) log("Started all checkers!") log("Sending out start-up messages...") sendMessage("Started up 'maintenance-bot'...") log("Start up complete!") 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)