Use new system for loading commands

merge-requests/1/merge
Bsian 2019-10-31 22:23:59 +00:00
parent ab7008b429
commit f8a600535b
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import config from './config.json';
import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface } from './models';
import { emojis } from './stores';
import { Command, Util, Collection } from './class';
import * as commands from './commands';
export default class Client extends Eris.Client {
@ -61,11 +62,11 @@ export default class Client extends Eris.Client {
});
}
public loadCommand(commandPath: string) {
public loadCommand(CommandFile: any) {
// eslint-disable-next-line no-useless-catch
try {
// eslint-disable-next-line
const command: Command = new (require(commandPath).default)(this);
const command: Command = new CommandFile(this);
if (command.subcmds.length) {
command.subcmds.forEach((C) => {
const cmd: Command = new C(this);
@ -80,11 +81,14 @@ export default class Client extends Eris.Client {
public async init() {
const evtFiles = await fs.readdir('./events/');
Object.values(commands).forEach((c: Function) => this.loadCommand(c));
/*
const commands = await fs.readdir(path.join(__dirname, './commands/'));
commands.forEach((command) => {
if (command === 'index.js') return;
this.loadCommand(`./commands/${command}`);
});
*/
evtFiles.forEach((file) => {
const eventName = file.split('.')[0];