2019-10-14 15:46:10 -04:00
|
|
|
import Eris from 'eris';
|
|
|
|
import mongoose from 'mongoose';
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
import path from 'path';
|
|
|
|
import config from './config.json';
|
|
|
|
|
2019-10-14 18:01:05 -04:00
|
|
|
const options: any = {
|
|
|
|
getAllUsers: true,
|
|
|
|
restMode: true,
|
|
|
|
defaultImageFormat: 'png'
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:46:10 -04:00
|
|
|
export default class Client extends Eris.Client {
|
|
|
|
public commands: Map<string, any>;
|
|
|
|
public aliases: Map<string, string>;
|
|
|
|
constructor() {
|
2019-10-14 18:01:05 -04:00
|
|
|
super(config.token, options);
|
2019-10-14 15:46:10 -04:00
|
|
|
|
|
|
|
this.commands = new Map();
|
|
|
|
this.aliases = new Map();
|
|
|
|
}
|
|
|
|
|
|
|
|
public loadCommand(commandPath: string) {
|
|
|
|
// eslint-disable-next-line no-useless-catch
|
|
|
|
try {
|
|
|
|
const command = new (require(commandPath))(this);
|
2019-10-14 18:01:05 -04:00
|
|
|
this.commands.set(command.name, command)
|
|
|
|
return `Successfully loaded ${command.name}.`;
|
2019-10-14 15:46:10 -04:00
|
|
|
} catch (err) { throw err; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public async init() {
|
|
|
|
const evtFiles = await fs.readdir('./events/');
|
|
|
|
|
|
|
|
const commands = await fs.readdir(path.join(__dirname, './commands/'));
|
|
|
|
commands.forEach(command => {
|
|
|
|
const response = this.loadCommand(`./commands/${command}`);
|
|
|
|
if (response) console.log(response);
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`Loading a total of ${evtFiles.length} events.`);
|
|
|
|
evtFiles.forEach(file => {
|
|
|
|
const eventName = file.split('.')[0];
|
|
|
|
console.log(`Loading Event: ${eventName}`);
|
|
|
|
const event = new (require(`./events/${file}`))(this);
|
|
|
|
this.on(eventName, (...args) => event.run(...args));
|
|
|
|
delete require.cache[require.resolve(`./events/${file}`)];
|
|
|
|
});
|
|
|
|
|
|
|
|
this.connect();
|
|
|
|
}
|
|
|
|
}
|