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,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<string, any>;
public aliases: Map<string, string>;
constructor() {
super(config.token, options);
public util: Util;
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.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();
}
}
}

View File

@ -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<string> {
const ex = promisify(childProcess.exec);
@ -17,4 +22,9 @@ export default class Util {
}
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 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;
}
}