2019-10-15 14:03:40 -04:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
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';
|
2019-10-15 20:34:13 -04:00
|
|
|
import { config, Util } from '.';
|
|
|
|
import { Account, AccountInterface, Moderation, ModerationInterface } from './models';
|
|
|
|
import { emojis } from './stores';
|
|
|
|
import { Command } from './class';
|
2019-10-14 15:46:10 -04:00
|
|
|
|
2019-10-14 18:01:05 -04:00
|
|
|
|
2019-10-14 15:46:10 -04:00
|
|
|
export default class Client extends Eris.Client {
|
2019-10-14 23:32:37 -04:00
|
|
|
public util: Util;
|
|
|
|
|
2019-10-14 19:04:07 -04:00
|
|
|
public commands: Map<string, Command>;
|
2019-10-14 23:32:37 -04:00
|
|
|
|
2019-10-14 15:46:10 -04:00
|
|
|
public aliases: Map<string, string>;
|
2019-10-14 23:32:37 -04:00
|
|
|
|
|
|
|
public db: { Account: mongoose.Model<AccountInterface>; Moderation: mongoose.Model<ModerationInterface>; };
|
|
|
|
|
|
|
|
public stores: { emojis: { success: string, loading: string, error: string }; };
|
|
|
|
|
2019-10-14 15:46:10 -04:00
|
|
|
constructor() {
|
2019-10-14 23:32:37 -04:00
|
|
|
super(config.token, { getAllUsers: true, restMode: true, defaultImageFormat: 'png' });
|
2019-10-14 15:46:10 -04:00
|
|
|
|
2019-10-14 23:32:37 -04:00
|
|
|
this.util = new Util(this);
|
2019-10-14 15:46:10 -04:00
|
|
|
this.commands = new Map();
|
|
|
|
this.aliases = new Map();
|
2019-10-14 23:32:37 -04:00
|
|
|
this.db = { Account, Moderation };
|
|
|
|
this.stores = { emojis };
|
2019-10-14 15:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public loadCommand(commandPath: string) {
|
|
|
|
// eslint-disable-next-line no-useless-catch
|
|
|
|
try {
|
|
|
|
const command = new (require(commandPath))(this);
|
2019-10-14 23:32:37 -04:00
|
|
|
this.commands.set(command.name, command);
|
2019-10-14 18:01:05 -04:00
|
|
|
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/');
|
2019-10-14 23:32:37 -04:00
|
|
|
|
2019-10-14 15:46:10 -04:00
|
|
|
const commands = await fs.readdir(path.join(__dirname, './commands/'));
|
2019-10-14 23:32:37 -04:00
|
|
|
commands.forEach((command) => {
|
2019-10-14 15:46:10 -04:00
|
|
|
const response = this.loadCommand(`./commands/${command}`);
|
|
|
|
if (response) console.log(response);
|
|
|
|
});
|
2019-10-14 23:32:37 -04:00
|
|
|
|
2019-10-14 15:46:10 -04:00
|
|
|
console.log(`Loading a total of ${evtFiles.length} events.`);
|
2019-10-14 23:32:37 -04:00
|
|
|
evtFiles.forEach((file) => {
|
2019-10-14 15:46:10 -04:00
|
|
|
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();
|
|
|
|
}
|
2019-10-14 23:32:37 -04:00
|
|
|
}
|