From d845612f512d5ce40e38a18c7a03a83c534c6f37 Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 15 Feb 2022 14:32:57 +0000 Subject: [PATCH] this doesn't need to be global --- src/index.ts | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/index.ts b/src/index.ts index 91deadf..e6896a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,24 +40,26 @@ if (config.health.healthz.enabled) { Healthz.listen(); } -let bot: Mjolnir | null = null; (async function () { - const storagePath = path.isAbsolute(config.dataPath) ? config.dataPath : path.join(__dirname, '../', config.dataPath); - const storage = new SimpleFsStorageProvider(path.join(storagePath, "bot.json")); + let bot: Mjolnir | null = null; + try { + const storagePath = path.isAbsolute(config.dataPath) ? config.dataPath : path.join(__dirname, '../', config.dataPath); + const storage = new SimpleFsStorageProvider(path.join(storagePath, "bot.json")); - let client: MatrixClient; - if (config.pantalaimon.use) { - const pantalaimon = new PantalaimonClient(config.homeserverUrl, storage); - client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password); - } else { - client = new MatrixClient(config.homeserverUrl, config.accessToken, storage); + let client: MatrixClient; + if (config.pantalaimon.use) { + const pantalaimon = new PantalaimonClient(config.homeserverUrl, storage); + client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password); + } else { + client = new MatrixClient(config.homeserverUrl, config.accessToken, storage); + } + patchMatrixClient(); + config.RUNTIME.client = client; + + bot = await Mjolnir.setupMjolnirFromConfig(client); + await bot.start(); + } catch (err) { + bot?.logMessage(LogLevel.ERROR, "index", err); + process.exit(1); } - patchMatrixClient(); - config.RUNTIME.client = client; - - bot = await Mjolnir.setupMjolnirFromConfig(client); - await bot.start(); -})().catch(err => { - bot?.logMessage(LogLevel.ERROR, "index", err); - process.exit(1); -}); +})();