diff --git a/src/Client.ts b/src/Client.ts index 2ed0535..28f82c2 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -6,7 +6,7 @@ import path from 'path'; import config from './config.json'; import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface } from './models'; import { emojis } from './stores'; -import { Command, Util } from './class'; +import { Command, Util, Collection } from './class'; export default class Client extends Eris.Client { @@ -14,7 +14,7 @@ export default class Client extends Eris.Client { public util: Util; - public commands: Map; + public commands: Collection; public aliases: Map; @@ -30,8 +30,7 @@ export default class Client extends Eris.Client { process.title = 'cloudservices'; this.config = config; this.util = new Util(this); - this.commands = new Map(); - this.aliases = new Map(); + this.commands = new Collection({ base: Command }); this.db = { Account, Domain, Moderation }; this.stores = { emojis }; this.signale = signale; @@ -68,8 +67,15 @@ export default class Client extends Eris.Client { // eslint-disable-next-line no-useless-catch try { // eslint-disable-next-line - const command = new (require(commandPath).default)(this); - this.commands.set(command.name, command); + const command: Command = new (require(commandPath).default)(this); + if (command.subcmds.length) { + command.subcmds.forEach((C) => { + const cmd: Command = new C(this); + command.subcommands.add(cmd.name, cmd); + }); + delete command.subcmds; + } + this.commands.add(command.name, command); this.signale.complete(`Loaded command ${command.name}`); } catch (err) { throw err; } } diff --git a/src/class/Command.ts b/src/class/Command.ts index a6cec05..c05ddc5 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -1,5 +1,6 @@ import { Message } from 'eris'; import { Client } from '..'; +import { Collection } from '.'; export default class Command { name: string @@ -18,7 +19,9 @@ export default class Command { guildOnly?: boolean - subcommands: Command[] + subcmds?: any[] + + subcommands?: Collection public run(message: Message, args: string[]) {} // eslint-disable-line @@ -30,7 +33,7 @@ export default class Command { this.aliases = []; this.guildOnly = true; this.client = client; - this.subcommands = []; + this.subcmds = []; this.permissions = {}; } } diff --git a/src/class/index.ts b/src/class/index.ts index 7659aa5..a7a9a5c 100644 --- a/src/class/index.ts +++ b/src/class/index.ts @@ -1,3 +1,4 @@ export { default as Command } from './Command'; export { default as RichEmbed } from './RichEmbed'; export { default as Util } from './Util'; +export { default as Collection } from './Collection';