forked from engineering/cloudservices
changes and utility funcs
parent
1dd2052b0c
commit
5609894812
|
@ -3,43 +3,53 @@ 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; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
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);
|
||||||
|
@ -49,4 +59,4 @@ export default class Client extends Eris.Client {
|
||||||
|
|
||||||
this.connect();
|
this.connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/Util.ts
14
src/Util.ts
|
@ -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}\`\`\``);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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[] }
|
|
||||||
public run (message: Message, args: string[]) {}
|
permissions?: { roles?: string[], users?: 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue