diff --git a/src/Client.ts b/src/Client.ts index e8bb57f..7a775dd 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -3,43 +3,53 @@ import mongoose from 'mongoose'; import fs from 'fs-extra'; import path from 'path'; import config from './config.json'; +import Account, { AccountInterface } from './models/Account.js'; +import Moderation, { ModerationInterface } from './models/Moderation.js'; +import emojis from './stores/emojis.js'; +import Util from './Util.js'; -const options: any = { - getAllUsers: true, - restMode: true, - defaultImageFormat: 'png' -} export default class Client extends Eris.Client { - public commands: Map; - public aliases: Map; - constructor() { - super(config.token, options); + public util: Util; + public commands: Map; + + public aliases: Map; + + public db: { Account: mongoose.Model; Moderation: mongoose.Model; }; + + public stores: { emojis: { success: string, loading: string, error: string }; }; + + constructor() { + super(config.token, { getAllUsers: true, restMode: true, defaultImageFormat: 'png' }); + + this.util = new Util(this); this.commands = new Map(); this.aliases = new Map(); + this.db = { Account, Moderation }; + this.stores = { emojis }; } public loadCommand(commandPath: string) { // eslint-disable-next-line no-useless-catch try { const command = new (require(commandPath))(this); - this.commands.set(command.name, command) + this.commands.set(command.name, command); return `Successfully loaded ${command.name}.`; } 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 => { + 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 => { + evtFiles.forEach((file) => { const eventName = file.split('.')[0]; console.log(`Loading Event: ${eventName}`); const event = new (require(`./events/${file}`))(this); @@ -49,4 +59,4 @@ export default class Client extends Eris.Client { this.connect(); } -} \ No newline at end of file +} diff --git a/src/Util.ts b/src/Util.ts index 689daf0..1f12fc8 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -1,9 +1,14 @@ import { promisify } from 'util'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; +import Client from './Client'; export default class Util { - constructor() {} + public client: Client; + + constructor(client: Client) { + this.client = client; + } public async exec(command: string): Promise { const ex = promisify(childProcess.exec); @@ -17,4 +22,9 @@ export default class Util { } return result; } -} \ No newline at end of file + + public sendError(error: Error): void { + // @ts-ignore + this.client.guilds.get('446067825673633794').channels.get('595788220764127272').createMessage(`\`\`\`ts\n${error.stack}\`\`\``); + } +} diff --git a/src/class/Command.ts b/src/class/Command.ts index 944c3ca..50dd7dc 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -1,21 +1,29 @@ -import { Message } from 'eris' -import Client from '../Client' +import { Message } from 'eris'; +import Client from '../Client'; export default class Command { name: string + description?: string + usage?: string + enabled: boolean + aliases?: string[] + client: Client - permissions?: { roles: string[], users: string[] } - public run (message: Message, args: string[]) {} + + permissions?: { roles?: string[], users?: string[] } + + public run(message: Message, args: string[]) {} + constructor(client: Client) { - this.name = 'None' - this.description = 'No description given' - this.usage = 'No usage given' - this.enabled = false - this.aliases = [] - this.client = client + this.name = 'None'; + this.description = 'No description given'; + this.usage = 'No usage given'; + this.enabled = false; + this.aliases = []; + this.client = client; } }