import eris from 'eris'; import mongoose from 'mongoose'; import { promises as fs } from 'fs'; import { Collection, Command, Util } from '.'; import { Member, MemberInterface, Moderation, ModerationInterface } from '../models'; export default class Client extends eris.Client { public config: { token: string, prefix: string, guildID: string, mongoDB: string }; public commands: Collection; public intervals: Collection; public util: Util; public db: { member: mongoose.Model, moderation: mongoose.Model }; // eslint-disable-next-line @typescript-eslint/no-useless-constructor constructor(token: string, options?: eris.ClientOptions) { super(token, options); this.commands = new Collection(); this.intervals = new Collection(); this.db = { member: Member, moderation: Moderation }; } public async loadDatabase() { await mongoose.connect(this.config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true }); } public loadPlugins() { this.util = new Util(this); } 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}`); }); } 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)); this.util.signale.success(`Successfully loaded event: ${eventName}`); 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); this.util.signale.success(`Successfully loaded command: ${command.name}`); }); } }