changes and utility funcs
parent
1dd2052b0c
commit
5609894812
|
@ -3,28 +3,38 @@ 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; }
|
||||
}
|
||||
|
@ -33,13 +43,13 @@ export default class Client extends Eris.Client {
|
|||
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);
|
||||
|
|
12
src/Util.ts
12
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<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}\`\`\``);
|
||||
}
|
||||
}
|
|
@ -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[] }
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue