From 158ddb8a23ecb99ac0694b8f3527178f7e0b76b8 Mon Sep 17 00:00:00 2001 From: Will Hunt <will@half-shot.uk> Date: Sat, 4 Jul 2020 12:20:56 +0100 Subject: [PATCH] A few things changed in YAML that stopped TS from completing --- src/discordas.ts | 6 +++++- tools/addbot.ts | 4 ++-- tools/toolshelper.ts | 3 ++- tools/userClientTools.ts | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/discordas.ts b/src/discordas.ts index fa4d5b5..be4b204 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -133,7 +133,11 @@ async function run() { if (!port) { throw Error("Port not given in command line or config file"); } - config.applyConfig(yaml.safeLoad(fs.readFileSync(configPath, "utf8"))); + const readConfig = yaml.safeLoad(fs.readFileSync(configPath, "utf8")); + if (typeof readConfig !== "object") { + throw Error("Config is not of type object"); + } + config.applyConfig(readConfig); Log.Configure(config.logging); if (config.database.roomStorePath || config.database.userStorePath) { log.error("The keys 'roomStorePath' and/or 'userStorePath' is still defined in the config. " + diff --git a/tools/addbot.ts b/tools/addbot.ts index 2dda777..335e1f1 100644 --- a/tools/addbot.ts +++ b/tools/addbot.ts @@ -62,6 +62,6 @@ const yamlConfig = yaml.safeLoad(fs.readFileSync(options.config, "utf8")); if (yamlConfig === null) { console.error("You have an error in your discord config."); } - -const url = Util.GetBotLink(yamlConfig); +// We assume the config is well formed in this script +const url = Util.GetBotLink(yamlConfig as any); console.log(`Go to ${url} to invite the bot into a guild.`); diff --git a/tools/toolshelper.ts b/tools/toolshelper.ts index 1449f13..a0d5711 100644 --- a/tools/toolshelper.ts +++ b/tools/toolshelper.ts @@ -24,7 +24,8 @@ export class ToolsHelper { homeserverName: config.bridge.domain, homeserverUrl: config.bridge.homeserverUrl, port: 0, - registration, + // We assume the registration is well formed + registration: registration as any, }); const store = needsStore ? new DiscordStore(config.database ? config.database.filename : "discord.db") : null; diff --git a/tools/userClientTools.ts b/tools/userClientTools.ts index 0aadc22..a6d923f 100644 --- a/tools/userClientTools.ts +++ b/tools/userClientTools.ts @@ -71,7 +71,7 @@ if (options.help || (options.add && options.remove) || !(options.add || options. process.exit(0); } -const config: DiscordBridgeConfig = yaml.safeLoad(fs.readFileSync(options.config, "utf8")); +const config: DiscordBridgeConfig = yaml.safeLoad(fs.readFileSync(options.config, "utf8")) as DiscordBridgeConfig; const discordstore = new DiscordStore(config.database ? config.database : "discord.db"); discordstore.init().then(() => { log.info("Loaded database."); -- GitLab