From 72b89b2f7822f7b21a5a7432b4d1ad8de79eb08c Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 17:15:24 +0000 Subject: [PATCH] Added DB to reload --- src/commands/load.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 8f55fe5..172b28a 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -15,7 +15,7 @@ export default class Load extends Command { public async run(message: Message, args: string[]) { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const allowed = ['config', 'util', 'command']; + const allowed = ['config', 'util', 'command', 'db']; const type = args[0].toLowerCase(); if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); @@ -27,6 +27,19 @@ export default class Load extends Command { const Util = require(`${corepath}/class/Util`).default; this.client.util = new Util(this.client); delete require.cache[`${corepath}/class/Util.js`]; + } else if (type === 'db') { + try { + const dbIndex = require('../models'); + let Db = dbIndex[args[1]]; + if (!Db) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); + delete require.cache[`${corepath}/models/index.js`]; + delete require.cache[`${corepath}/models/${args[1]}.js`]; + Db = require(`${corepath}/commands/${args[1]}`).default; + this.client.db = require('../models'); + } catch (error) { + if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`); + throw error; + } } else { try { const cmdIndex = require('../commands');