forked from Galactic/galactic-bot
tweaks to logger webhook
This commit is contained in:
parent
cb92b1eea0
commit
54dff4399d
@ -23,6 +23,13 @@ const Constants = {
|
|||||||
info: 'blue',
|
info: 'blue',
|
||||||
debug: 'magenta',
|
debug: 'magenta',
|
||||||
status: 'cyanBright'
|
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();
|
type = type.toLowerCase();
|
||||||
|
|
||||||
@ -67,7 +74,7 @@ class Logger {
|
|||||||
const strippedText = text.replace(stripRegex, '');
|
const strippedText = text.replace(stripRegex, '');
|
||||||
|
|
||||||
console.log(text); //eslint-disable-line no-console
|
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';
|
const stream = type === 'error' ? '_errorWriteStream' : '_writeStream';
|
||||||
if(this[stream]) {
|
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>')
|
const message = text.replace(new RegExp(process.env.DISCORD_TOKEN, 'gu'), '<redacted>')
|
||||||
.replace(new RegExp(username, 'gu'), '<redacted>');
|
.replace(new RegExp(username, 'gu'), '<redacted>');
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
color: 0xe88388,
|
color: Constants.ColorCodes[type],
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
description: `\`\`\`${message.length > 2000 ? message.substring(0, 2000) + ' ... CONTENT CUT OFF' : message}\`\`\``,
|
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.
|
//Messages coming from the shards process.send functions.
|
||||||
_handleMessage(shard, message) {
|
_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) {
|
_shardId(shard) {
|
||||||
|
@ -33,7 +33,7 @@ class LocaleLoader {
|
|||||||
let string = this.languages[language][index];
|
let string = this.languages[language][index];
|
||||||
if (!string) {
|
if (!string) {
|
||||||
const str = `< Missing Locale Index: ${language}.${index} >`;
|
const str = `< Missing Locale Index: ${language}.${index} >`;
|
||||||
this.logger.error(str);
|
this.logger.warn(str, { broadcast: true });
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user