tweaks to logger webhook

This commit is contained in:
Erik 2022-07-14 01:24:46 +03:00
parent cb92b1eea0
commit 54dff4399d
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 13 additions and 6 deletions

View File

@ -23,6 +23,13 @@ const Constants = {
info: 'blue',
debug: 'magenta',
status: 'cyanBright'
},
ColorCodes: {
error: 0xe88388,
warn: 0xf9d472,
info: 0x76a9d8,
debug: 0xd8abd7,
status: 0x72d4d7
}
};
@ -52,7 +59,7 @@ class Logger {
}
write(type = 'info', string = '', shard = null, api = false) {
write(type = 'info', string = '', shard = null, api = false, broadcast = false) {
type = type.toLowerCase();
@ -67,7 +74,7 @@ class Logger {
const strippedText = text.replace(stripRegex, '');
console.log(text); //eslint-disable-line no-console
if (type === 'error') this.webhook(strippedText);
if (type === 'error' || broadcast) this.webhook(strippedText, type);
const stream = type === 'error' ? '_errorWriteStream' : '_writeStream';
if(this[stream]) {
@ -77,13 +84,13 @@ class Logger {
}
webhook(text) {
webhook(text, type) {
const message = text.replace(new RegExp(process.env.DISCORD_TOKEN, 'gu'), '<redacted>')
.replace(new RegExp(username, 'gu'), '<redacted>');
const embed = {
color: 0xe88388,
color: Constants.ColorCodes[type],
timestamp: new Date(),
description: `\`\`\`${message.length > 2000 ? message.substring(0, 2000) + ' ... CONTENT CUT OFF' : message}\`\`\``,
};
@ -123,7 +130,7 @@ class Logger {
//Messages coming from the shards process.send functions.
_handleMessage(shard, message) {
this.write(message.type, message.message, shard, message._api);
this.write(message.type, message.message, shard, message._api, message.broadcast);
}
_shardId(shard) {

View File

@ -33,7 +33,7 @@ class LocaleLoader {
let string = this.languages[language][index];
if (!string) {
const str = `< Missing Locale Index: ${language}.${index} >`;
this.logger.error(str);
this.logger.warn(str, { broadcast: true });
return str;
}