log errors to discord

This commit is contained in:
Lamp 2018-08-13 23:10:31 -07:00
parent 6f39c42c7b
commit 02a4a72ddf
No known key found for this signature in database
GPG Key ID: 0F1F8704BEDE369E
3 changed files with 20 additions and 11 deletions

View File

@ -8,6 +8,7 @@ module.exports = {
"webhooks": {
"welcome": process.env.WEBHOOK_WELCOME.split("/"),
"error": process.env.WEBHOOK_ERROR.split("/")
},
"opID": "281134216115257344",

View File

@ -6,6 +6,23 @@ global.Discord = require('discord.js');
global.fs = require('fs');
global.dClient = new Discord.Client({ disableEveryone: true });
// error handling
{
let webhook = new Discord.WebhookClient(config.webhooks.error[0], config.webhooks.error[1]);
global.onError = function logError(error) {
let msg = error.stack || error.message || error;
console.error(msg);
try {
webhook.send(`\`\`\`\n${msg}\n\`\`\``).catch(()=>{});
} catch(e) {}
}
process.on('unhandledRejection', onError);
process.on('uncaughtException', onError);
dClient.on('error', onError);
dClient.on('warn', onError);
}
global.dbClient = new (require('pg').Client)({
connectionString: process.env.DATABASE_URL,
ssl: !testmode,
@ -31,5 +48,3 @@ dClient.once('ready', () => {
require('./misc');
});
dClient.on('error', console.error);
dClient.on('warn', console.warn);

View File

@ -1,10 +1,3 @@
process.on('unhandledRejection', error => {
console.error(error.stack);
});
process.on('uncaughtException', error => {
console.error(error.stack);
});
Array.prototype.random = function () {
return this[Math.floor(Math.random() * this.length)]
}