diff --git a/src/class/Client.ts b/src/class/Client.ts index 8a8eabb..28470cc 100644 --- a/src/class/Client.ts +++ b/src/class/Client.ts @@ -3,9 +3,10 @@ import mongoose from 'mongoose'; import { promises as fs } from 'fs'; import { Collection, Command, LocalStorage, Util, ServerManagement, Event } from '.'; import { File, FileInterface, Member, MemberInterface, Moderation, ModerationInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface } from '../models'; +import { Config } from '../../types'; // eslint-disable-line export default class Client extends eris.Client { - public config: { token: string, prefix: string, guildID: string, mongoDB: string, emailPass: string, }; + public config: Config; public commands: Collection; diff --git a/src/class/Util.ts b/src/class/Util.ts index 184e55d..7df6ae9 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -1,7 +1,7 @@ /* eslint-disable no-bitwise */ import nodemailer from 'nodemailer'; import signale from 'signale'; -import { Member, Message, Guild, PrivateChannel, GroupChannel, Role, AnyGuildChannel } from 'eris'; +import { Member, Message, Guild, PrivateChannel, GroupChannel, Role, AnyGuildChannel, WebhookPayload } from 'eris'; import { Client, Command, Moderation, RichEmbed } from '.'; import { statusMessages as emotes } from '../configs/emotes.json'; @@ -79,7 +79,7 @@ export default class Util { public async handleError(error: Error, message?: Message, command?: Command, disable = true): Promise { try { this.signale.error(error); - const info = { content: `\`\`\`js\n${error.stack || error}\n\`\`\``, embed: null }; + const info: WebhookPayload = { content: `\`\`\`js\n${error.stack || error}\n\`\`\``, embeds: [] }; if (message) { const embed = new RichEmbed(); embed.setColor('FF0000'); @@ -93,9 +93,9 @@ export default class Util { else guild = message.channel.guild.id; embed.addField('Message link', `[Click here](https://discordapp.com/channels/${guild}/${message.channel.id}/${message.id})`, true); embed.setTimestamp(new Date(message.timestamp)); - info.embed = embed; + info.embeds.push(embed); } - await this.client.createMessage('595788220764127272', info); + await this.client.executeWebhook(this.client.config.webhookID, this.client.config.webhookToken, info); const msg = message ? message.content.slice(this.client.config.prefix.length).trim().split(/ +/g) : []; if (command && disable) this.resolveCommand(msg).then((c) => { c.cmd.enabled = false; }); if (message) message.channel.createMessage(`***${this.emojis.ERROR} An unexpected error has occured - please contact a Staff member.${command && disable ? ' This command has been disabled.' : ''}***`); diff --git a/src/main.ts b/src/main.ts index 0f5d92e..55b2802 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,10 +6,11 @@ import { promises as fs } from 'fs'; import { Client } from './class'; import * as eventFiles from './events'; import * as commandFiles from './commands'; +import { Config } from '../types'; // eslint-disable-line async function main(): Promise { const read = await fs.readFile('../config.yaml', 'utf8'); - const config: { token: string, prefix: string, guildID: string, mongoDB: string, emailPass: string } = parse(read); + const config: Config = parse(read); const client = new Client(config.token, { defaultImageFormat: 'png', restMode: true }); client.config = config; await client.loadDatabase(); diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..971ffc9 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,9 @@ +export declare interface Config { + token: string; + prefix: string; + guildID: string; + mongoDB: string; + emailPass: string; + webhookID: string; + webhookToken: string; +}