From 30d6ae69fe2c5c3dc76bb8f8d51938351cf1db66 Mon Sep 17 00:00:00 2001 From: James O'Cull Date: Fri, 24 Sep 2021 14:05:31 -0400 Subject: [PATCH] Move into an async function to allow `await` on writeJson --- src/app.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/app.ts b/src/app.ts index c7efa3a..ae18968 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,24 +2,26 @@ import * as fs from 'fs'; import { requireFile, projectDir, writeJson } from 'discord-bot-quickstart'; import { IRhythmBotConfig, RhythmBot } from './bot'; -const configPath = projectDir('../bot-config.json'); -if (!fs.existsSync(configPath)) { - writeJson({ discord: { token: '' } }, configPath); -} +(async function () { + const configPath = projectDir('../bot-config.json'); + if (!fs.existsSync(configPath)) { + await writeJson({ discord: { token: '' } }, configPath); + } -let config: IRhythmBotConfig = requireFile('../bot-config.json'); + let config: IRhythmBotConfig = requireFile('../bot-config.json'); -const bot = new RhythmBot(config); + const bot = new RhythmBot(config); -if (!!config && config.discord.token === '') { - bot.logger.debug('Invalid Token - Create valid token in the Discord Developer Portal'); - console.log('Invalid Token - Create valid token in the Discord Developer Portal'); - process.exit(0); -} + if (!!config && config.discord.token === '') { + bot.logger.debug('Invalid Token - Create valid token in the Discord Developer Portal'); + console.log('Invalid Token - Create valid token in the Discord Developer Portal'); + process.exit(0); + } -bot.connect() - .then(() => { - bot.logger.debug('Rhythm Bot Online'); - bot.listen(); - }) - .catch(err => bot.logger.error(err)); + bot.connect() + .then(() => { + bot.logger.debug('Rhythm Bot Online'); + bot.listen(); + }) + .catch(err => bot.logger.error(err)); +})(); \ No newline at end of file