2020-04-13 22:38:10 +02:00
|
|
|
const Transport = require('winston-transport');
|
2020-04-14 10:26:59 +02:00
|
|
|
const { WebhookClient } = require('discord.js');
|
|
|
|
const { username } = require('os').userInfo();
|
|
|
|
const { inspect } = require('util');
|
|
|
|
|
|
|
|
const options = require('../../../options.json');
|
|
|
|
|
|
|
|
const regex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
|
2020-04-13 22:38:10 +02:00
|
|
|
|
|
|
|
class DiscordWebhook extends Transport {
|
2020-04-14 10:26:59 +02:00
|
|
|
constructor(opts) {
|
|
|
|
super(opts);
|
|
|
|
|
|
|
|
this.webhookClient = new WebhookClient(
|
|
|
|
options.logger.webhook.id,
|
|
|
|
options.logger.webhook.token
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
log(info, callback) {
|
|
|
|
setImmediate(() => {
|
|
|
|
this.emit('logged', info);
|
|
|
|
});
|
|
|
|
|
|
|
|
const message = info.message.replace(regex, '')
|
|
|
|
.replace(new RegExp(options.bot.token, 'g'), '<redacted>')
|
|
|
|
.replace(new RegExp(username, 'g'), '<redacted>');
|
|
|
|
|
|
|
|
const developers = ['nolan', 'navy'];
|
|
|
|
const random = developers[Math.floor(Math.random()*developers.length)];
|
|
|
|
|
|
|
|
const embed = {
|
|
|
|
color: 0xe88388,
|
|
|
|
timestamp: new Date(),
|
|
|
|
description: `\`\`\`${message}\`\`\``,
|
|
|
|
footer: {
|
|
|
|
text: `probably ${random}'s fault`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.webhookClient.send('', { embeds: [embed] });
|
|
|
|
|
|
|
|
callback();
|
|
|
|
}
|
2020-04-13 22:38:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = DiscordWebhook;
|