Added in-house Collection

merge-requests/1/merge
Bsian 2019-10-31 18:32:59 +00:00
parent 28229f6e69
commit 71053df288
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
3 changed files with 18 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import path from 'path';
import config from './config.json'; import config from './config.json';
import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface } from './models'; import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface } from './models';
import { emojis } from './stores'; import { emojis } from './stores';
import { Command, Util } from './class'; import { Command, Util, Collection } from './class';
export default class Client extends Eris.Client { export default class Client extends Eris.Client {
@ -14,7 +14,7 @@ export default class Client extends Eris.Client {
public util: Util; public util: Util;
public commands: Map<string, Command>; public commands: Collection;
public aliases: Map<string, string>; public aliases: Map<string, string>;
@ -30,8 +30,7 @@ export default class Client extends Eris.Client {
process.title = 'cloudservices'; process.title = 'cloudservices';
this.config = config; this.config = config;
this.util = new Util(this); this.util = new Util(this);
this.commands = new Map(); this.commands = new Collection({ base: Command });
this.aliases = new Map();
this.db = { Account, Domain, Moderation }; this.db = { Account, Domain, Moderation };
this.stores = { emojis }; this.stores = { emojis };
this.signale = signale; this.signale = signale;
@ -68,8 +67,15 @@ export default class Client extends Eris.Client {
// eslint-disable-next-line no-useless-catch // eslint-disable-next-line no-useless-catch
try { try {
// eslint-disable-next-line // eslint-disable-next-line
const command = new (require(commandPath).default)(this); const command: Command = new (require(commandPath).default)(this);
this.commands.set(command.name, command); 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}`); this.signale.complete(`Loaded command ${command.name}`);
} catch (err) { throw err; } } catch (err) { throw err; }
} }

View File

@ -1,5 +1,6 @@
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
import { Collection } from '.';
export default class Command { export default class Command {
name: string name: string
@ -18,7 +19,9 @@ export default class Command {
guildOnly?: boolean guildOnly?: boolean
subcommands: Command[] subcmds?: any[]
subcommands?: Collection
public run(message: Message, args: string[]) {} // eslint-disable-line public run(message: Message, args: string[]) {} // eslint-disable-line
@ -30,7 +33,7 @@ export default class Command {
this.aliases = []; this.aliases = [];
this.guildOnly = true; this.guildOnly = true;
this.client = client; this.client = client;
this.subcommands = []; this.subcmds = [];
this.permissions = {}; this.permissions = {};
} }
} }

View File

@ -1,3 +1,4 @@
export { default as Command } from './Command'; export { default as Command } from './Command';
export { default as RichEmbed } from './RichEmbed'; export { default as RichEmbed } from './RichEmbed';
export { default as Util } from './Util'; export { default as Util } from './Util';
export { default as Collection } from './Collection';