1
0
Fork 0

Use new system for loading commands

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