From ceb613c95fe3fe233c36d6848b776128075bce72 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:47:47 +0000 Subject: [PATCH] Added reload command --- src/commands/index.ts | 47 ++++++++++++++++++++++--------------------- src/commands/load.ts | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 src/commands/load.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index ee72450..7312475 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,23 +1,24 @@ -export { default as Announce } from './announce'; -export { default as Bearer } from './bearer'; -export { default as CreateAccount } from './createaccount'; -export { default as CWG } from './cwg'; -export { default as DeleteAccount } from './deleteaccount'; -export { default as Disk } from './disk'; -export { default as Eval } from './eval'; -export { default as Exec } from './exec'; -export { default as Help } from './help'; -export { default as Lock } from './lock'; -export { default as Modlogs } from './modlogs'; -export { default as Notify } from './notify'; -export { default as Parse } from './parse'; -export { default as Parseall } from './parseall'; -export { default as Ping } from './ping'; -export { default as Pull } from './pull'; -export { default as Restart } from './restart'; -export { default as SecureSign } from './securesign'; -export { default as Sysinfo } from './sysinfo'; -export { default as Unban } from './unban'; -export { default as Unlock } from './unlock'; -export { default as Warn } from './warn'; -export { default as Whois } from './whois'; +export { default as announce } from './announce'; +export { default as bearer } from './bearer'; +export { default as createAccount } from './createaccount'; +export { default as cwg } from './cwg'; +export { default as deleteaccount } from './deleteaccount'; +export { default as disk } from './disk'; +export { default as eval } from './eval'; +export { default as exec } from './exec'; +export { default as help } from './help'; +export { default as load } from './load'; +export { default as lock } from './lock'; +export { default as modlogs } from './modlogs'; +export { default as notify } from './notify'; +export { default as parse } from './parse'; +export { default as parseall } from './parseall'; +export { default as ping } from './ping'; +export { default as pull } from './pull'; +export { default as restart } from './restart'; +export { default as securesign } from './securesign'; +export { default as sysinfo } from './sysinfo'; +export { default as unban } from './unban'; +export { default as unlock } from './unlock'; +export { default as warn } from './warn'; +export { default as whois } from './whois'; diff --git a/src/commands/load.ts b/src/commands/load.ts new file mode 100644 index 0000000..a7c7830 --- /dev/null +++ b/src/commands/load.ts @@ -0,0 +1,41 @@ +import { Message } from 'eris'; +import { Client } from '..'; +import { Command } from '../class'; + +export default class Ping extends Command { + constructor(client: Client) { + super(client); + this.name = 'load'; + this.description = '(Re)loads command, config or util'; + this.aliases = ['reload']; + this.enabled = true; + } + + 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', 'function']; + const type = args[0].toLowerCase(); + if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); + + const corepath = '/var/CloudServices/dist'; + if (type === 'config') this.client.config = require(`${corepath}/config.json`); + else if (type === 'util') { + const Util = require(`${corepath}/class/Util`); + this.client.util = new Util(this.client); + } else { + try { + const Cmd = require(`${corepath}/commands`)[args[1]]; + this.client.commands.remove(args[1]); + this.client.loadCommand(Cmd); + } catch (error) { + if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`); + throw error; + } + } + return message.channel.createMessage(`${this.client.stores.emojis.success} Reloaded ${type}`); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +}