2019-10-14 15:46:10 -04:00
|
|
|
import { promisify } from 'util';
|
|
|
|
import childProcess from 'child_process';
|
|
|
|
import nodemailer from 'nodemailer';
|
2019-10-14 23:32:37 -04:00
|
|
|
import Client from './Client';
|
2019-10-14 23:37:04 -04:00
|
|
|
import Command from './class/Command';
|
2019-10-14 15:46:10 -04:00
|
|
|
|
|
|
|
export default class Util {
|
2019-10-14 23:32:37 -04:00
|
|
|
public client: Client;
|
|
|
|
|
|
|
|
constructor(client: Client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
2019-10-14 15:46:10 -04:00
|
|
|
|
|
|
|
public async exec(command: string): Promise<string> {
|
|
|
|
const ex = promisify(childProcess.exec);
|
|
|
|
let result: string;
|
|
|
|
try {
|
|
|
|
const res = await ex(command);
|
|
|
|
if (res.stderr) result = res.stderr;
|
|
|
|
else result = res.stdout;
|
|
|
|
} catch (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-14 23:32:37 -04:00
|
|
|
|
|
|
|
public sendError(error: Error): void {
|
|
|
|
// @ts-ignore
|
|
|
|
this.client.guilds.get('446067825673633794').channels.get('595788220764127272').createMessage(`\`\`\`ts\n${error.stack}\`\`\``);
|
|
|
|
}
|
2019-10-14 23:37:04 -04:00
|
|
|
|
2019-10-15 10:42:42 -04:00
|
|
|
public resolveCommand(command: string): Command {
|
|
|
|
if (this.client.commands.has(command)) return this.client.commands.get(command);
|
|
|
|
for (const cmd of this.client.commands.values()) {
|
2019-10-14 23:37:04 -04:00
|
|
|
if (!cmd.aliases) continue;
|
2019-10-14 19:04:07 -04:00
|
|
|
for (const alias of cmd.aliases) {
|
2019-10-14 23:37:04 -04:00
|
|
|
if (command === alias.toLowerCase()) return cmd;
|
2019-10-14 19:04:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-14 23:32:37 -04:00
|
|
|
}
|