1
0
Fork 0

changes and utility funcs

refactor/models
Matthew R 2019-10-14 23:32:37 -04:00
parent 1dd2052b0c
commit 5609894812
No known key found for this signature in database
GPG Key ID: 97CA005641E9054C
3 changed files with 55 additions and 27 deletions

View File

@ -3,28 +3,38 @@ import mongoose from 'mongoose';
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import config from './config.json'; 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 { export default class Client extends Eris.Client {
public commands: Map<string, any>; public util: Util;
public aliases: Map<string, string>;
constructor() {
super(config.token, options);
public commands: Map<string, any>;
public aliases: Map<string, string>;
public db: { Account: mongoose.Model<AccountInterface>; Moderation: mongoose.Model<ModerationInterface>; };
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.commands = new Map();
this.aliases = new Map(); this.aliases = new Map();
this.db = { Account, Moderation };
this.stores = { emojis };
} }
public loadCommand(commandPath: string) { public loadCommand(commandPath: string) {
// eslint-disable-next-line no-useless-catch // eslint-disable-next-line no-useless-catch
try { try {
const command = new (require(commandPath))(this); const command = new (require(commandPath))(this);
this.commands.set(command.name, command) this.commands.set(command.name, command);
return `Successfully loaded ${command.name}.`; return `Successfully loaded ${command.name}.`;
} catch (err) { throw err; } } catch (err) { throw err; }
} }
@ -33,13 +43,13 @@ export default class Client extends Eris.Client {
const evtFiles = await fs.readdir('./events/'); const evtFiles = await fs.readdir('./events/');
const commands = await fs.readdir(path.join(__dirname, './commands/')); const commands = await fs.readdir(path.join(__dirname, './commands/'));
commands.forEach(command => { commands.forEach((command) => {
const response = this.loadCommand(`./commands/${command}`); const response = this.loadCommand(`./commands/${command}`);
if (response) console.log(response); if (response) console.log(response);
}); });
console.log(`Loading a total of ${evtFiles.length} events.`); console.log(`Loading a total of ${evtFiles.length} events.`);
evtFiles.forEach(file => { evtFiles.forEach((file) => {
const eventName = file.split('.')[0]; const eventName = file.split('.')[0];
console.log(`Loading Event: ${eventName}`); console.log(`Loading Event: ${eventName}`);
const event = new (require(`./events/${file}`))(this); const event = new (require(`./events/${file}`))(this);

View File

@ -1,9 +1,14 @@
import { promisify } from 'util'; import { promisify } from 'util';
import childProcess from 'child_process'; import childProcess from 'child_process';
import nodemailer from 'nodemailer'; import nodemailer from 'nodemailer';
import Client from './Client';
export default class Util { export default class Util {
constructor() {} public client: Client;
constructor(client: Client) {
this.client = client;
}
public async exec(command: string): Promise<string> { public async exec(command: string): Promise<string> {
const ex = promisify(childProcess.exec); const ex = promisify(childProcess.exec);
@ -17,4 +22,9 @@ export default class Util {
} }
return result; return result;
} }
public sendError(error: Error): void {
// @ts-ignore
this.client.guilds.get('446067825673633794').channels.get('595788220764127272').createMessage(`\`\`\`ts\n${error.stack}\`\`\``);
}
} }

View File

@ -1,21 +1,29 @@
import { Message } from 'eris' import { Message } from 'eris';
import Client from '../Client' import Client from '../Client';
export default class Command { export default class Command {
name: string name: string
description?: string description?: string
usage?: string usage?: string
enabled: boolean enabled: boolean
aliases?: string[] aliases?: string[]
client: Client client: Client
permissions?: { roles: string[], users: string[] }
permissions?: { roles?: string[], users?: string[] }
public run(message: Message, args: string[]) {} public run(message: Message, args: string[]) {}
constructor(client: Client) { constructor(client: Client) {
this.name = 'None' this.name = 'None';
this.description = 'No description given' this.description = 'No description given';
this.usage = 'No usage given' this.usage = 'No usage given';
this.enabled = false this.enabled = false;
this.aliases = [] this.aliases = [];
this.client = client this.client = client;
} }
} }