diff --git a/src/discordas.ts b/src/discordas.ts index e31065bf1aa9c89a74b84e19c42c4277e4d176ef..182b5cda54906345b24e78652148f82c1fc8d978 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -214,20 +214,34 @@ async function run(): Promise<void> { roomhandler.bindThirdparty(); + try { + await startDiscordBot(discordbot); + log.info("Discordbot started successfully"); + } catch (err) { + log.error(err); + log.error("Failure during startup. Exiting"); + process.exit(1); + } + await appservice.begin(); log.info(`Started listening on port ${port}`); +} + +async function startDiscordBot(discordbot: DiscordBot, falloffSeconds = 5) { try { await discordbot.init(); await discordbot.run(); - log.info("Discordbot started successfully"); } catch (err) { - log.error(err); - log.error("Failure during startup. Exiting"); - process.exit(1); + // no more than 5 minutes + const newFalloffSeconds = Math.min(falloffSeconds * 2, 5 * 60); + log.error(`Failed do start Discordbot: ${err.code}. Will try again in ${newFalloffSeconds} seconds`); + await new Promise((r, _) => setTimeout(r, newFalloffSeconds * 1000)); + return startDiscordBot(discordbot, newFalloffSeconds); } } + run().catch((err) => { log.error("A fatal error occurred during startup:", err); process.exit(1);