2020-04-14 13:15:33 -04:00
|
|
|
import eris from 'eris';
|
2020-04-15 15:13:44 -04:00
|
|
|
import mongoose from 'mongoose';
|
2020-04-14 13:15:33 -04:00
|
|
|
import { promises as fs } from 'fs';
|
2020-05-05 19:13:18 -04:00
|
|
|
import { Collection, Command, Util, ServerManagement } from '.';
|
|
|
|
import { Member, MemberInterface, Moderation, ModerationInterface, Redirect, RedirectInterface } from '../models';
|
2020-04-14 13:15:33 -04:00
|
|
|
|
|
|
|
export default class Client extends eris.Client {
|
2020-04-15 15:13:44 -04:00
|
|
|
public config: { token: string, prefix: string, guildID: string, mongoDB: string };
|
2020-04-14 13:15:33 -04:00
|
|
|
|
|
|
|
public commands: Collection<Command>;
|
|
|
|
|
2020-04-15 15:13:44 -04:00
|
|
|
public intervals: Collection<NodeJS.Timeout>;
|
|
|
|
|
2020-04-14 13:15:33 -04:00
|
|
|
public util: Util;
|
|
|
|
|
2020-05-05 19:13:18 -04:00
|
|
|
public serverManagement: ServerManagement;
|
|
|
|
|
|
|
|
public db: { member: mongoose.Model<MemberInterface>, moderation: mongoose.Model<ModerationInterface>, redirect: mongoose.Model<RedirectInterface> };
|
2020-04-15 15:13:44 -04:00
|
|
|
|
2020-04-14 13:15:33 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
|
|
constructor(token: string, options?: eris.ClientOptions) {
|
|
|
|
super(token, options);
|
|
|
|
this.commands = new Collection<Command>();
|
2020-04-15 15:13:44 -04:00
|
|
|
this.intervals = new Collection<NodeJS.Timeout>();
|
2020-05-05 19:13:18 -04:00
|
|
|
this.db = { member: Member, moderation: Moderation, redirect: Redirect };
|
2020-04-15 15:13:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public async loadDatabase() {
|
|
|
|
await mongoose.connect(this.config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
|
2020-04-14 13:15:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public loadPlugins() {
|
|
|
|
this.util = new Util(this);
|
2020-05-05 19:13:18 -04:00
|
|
|
this.serverManagement = new ServerManagement(this);
|
2020-04-14 13:15:33 -04:00
|
|
|
}
|
|
|
|
|
2020-04-15 15:13:44 -04:00
|
|
|
public async loadIntervals() {
|
|
|
|
const intervalFiles = await fs.readdir(`${__dirname}/../intervals`);
|
|
|
|
intervalFiles.forEach((file) => {
|
|
|
|
const intervalName = file.split('.')[0];
|
|
|
|
if (file === 'index.js') return;
|
|
|
|
const interval: NodeJS.Timeout = (require(`${__dirname}/../intervals/${file}`).default)(this);
|
|
|
|
this.intervals.add(intervalName, interval);
|
|
|
|
this.util.signale.success(`Successfully loaded interval: ${intervalName}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-14 13:15:33 -04:00
|
|
|
public async loadEvents() {
|
|
|
|
const evtFiles = await fs.readdir(`${__dirname}/../events`);
|
|
|
|
evtFiles.forEach((file) => {
|
|
|
|
const eventName = file.split('.')[0];
|
|
|
|
if (file === 'index.js') return;
|
|
|
|
// eslint-disable-next-line
|
|
|
|
const event = new (require(`${__dirname}/../events/${file}`).default)(this);
|
|
|
|
this.on(eventName, (...args) => event.run(...args));
|
2020-04-14 21:33:34 -04:00
|
|
|
this.util.signale.success(`Successfully loaded event: ${eventName}`);
|
2020-04-14 13:15:33 -04:00
|
|
|
delete require.cache[require.resolve(`${__dirname}/../events/${file}`)];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public async loadCommands() {
|
|
|
|
const commandFiles = await fs.readdir(`${__dirname}/../commands`);
|
|
|
|
commandFiles.forEach((file) => {
|
|
|
|
// eslint-disable-next-line new-cap
|
|
|
|
const command: Command = new (require(`${__dirname}/../commands/${file}`).default)(this);
|
|
|
|
this.commands.add(command.name, command);
|
2020-04-14 21:33:34 -04:00
|
|
|
this.util.signale.success(`Successfully loaded command: ${command.name}`);
|
2020-04-14 13:15:33 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|