aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils/BushLogger.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-04 19:32:39 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-04 19:32:39 -0400
commitb5793611d57a734d75b6a0845c441f33d144a5c0 (patch)
tree1deb4dc4cd0e1e575b1bc32ed0ae50085c7a3ecf /src/lib/utils/BushLogger.ts
parent41c532de2c7786b2bb8ba5d78f092fed3cc6b63a (diff)
downloadtanzanite-b5793611d57a734d75b6a0845c441f33d144a5c0.tar.gz
tanzanite-b5793611d57a734d75b6a0845c441f33d144a5c0.tar.bz2
tanzanite-b5793611d57a734d75b6a0845c441f33d144a5c0.zip
misc
Diffstat (limited to 'src/lib/utils/BushLogger.ts')
-rw-r--r--src/lib/utils/BushLogger.ts85
1 files changed, 40 insertions, 45 deletions
diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts
index e7532d8..cf5969c 100644
--- a/src/lib/utils/BushLogger.ts
+++ b/src/lib/utils/BushLogger.ts
@@ -1,17 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import chalk from 'chalk';
-import { MessageEmbed } from 'discord.js';
+import { MessageEmbed, Util } from 'discord.js';
import { inspect } from 'util';
-import { BushClient, BushSendMessageType } from '../extensions/discord-akairo/BushClient';
+import { BushSendMessageType } from '../extensions/discord-akairo/BushClient';
export class BushLogger {
- private client: BushClient;
- public constructor(client: BushClient) {
- this.client = client;
- }
-
- private parseFormatting(
+ static #parseFormatting(
content: any,
color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright' | '',
discordFormat = false
@@ -21,22 +16,22 @@ export class BushLogger {
const tempParsedArray: Array<string> = [];
newContent.forEach((value, index) => {
if (index % 2 !== 0) {
- tempParsedArray.push(discordFormat ? `**${value}**` : chalk[color](value));
+ tempParsedArray.push(discordFormat ? `**${Util.escapeMarkdown(value)}**` : chalk[color](value));
} else {
- tempParsedArray.push(value);
+ tempParsedArray.push(Util.escapeMarkdown(value));
}
});
return tempParsedArray.join('');
}
- private inspectContent(content: any, depth = 2, colors = true): string {
+ static #inspectContent(content: any, depth = 2, colors = true): string {
if (typeof content !== 'string') {
return inspect(content, { depth, colors });
}
return content;
}
- private stripColor(text: string): string {
+ static #stripColor(text: string): string {
return text.replace(
// eslint-disable-next-line no-control-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
@@ -44,7 +39,7 @@ export class BushLogger {
);
}
- private getTimeStamp(): string {
+ static #getTimeStamp(): string {
const now = new Date();
const hours = now.getHours();
const minute = now.getMinutes();
@@ -64,18 +59,18 @@ export class BushLogger {
* @param sendChannel - Should this also be logged to discord? Defaults to false.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public get log() {
- return this.info;
+ public static get log() {
+ return BushLogger.info;
}
/** Sends a message to the log channel */
- public async channelLog(message: BushSendMessageType): Promise<void> {
+ public static async channelLog(message: BushSendMessageType): Promise<void> {
const channel = await util.getConfigChannel('log');
await channel.send(message).catch(() => {});
}
/** Sends a message to the error channel */
- public async channelError(message: BushSendMessageType): Promise<void> {
+ public static async channelError(message: BushSendMessageType): Promise<void> {
const channel = await util.getConfigChannel('error');
await channel.send(message).catch(() => {});
}
@@ -85,19 +80,19 @@ export class BushLogger {
* @param content - The content to log.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public debug(content: any, depth = 0): void {
+ public static debug(content: any, depth = 0): void {
if (!client.config.isDevelopment) return;
- const newContent = this.inspectContent(content, depth, true);
- console.log(`${chalk.bgMagenta(this.getTimeStamp())} ${chalk.magenta('[Debug]')}`, newContent);
+ const newContent = this.#inspectContent(content, depth, true);
+ console.log(`${chalk.bgMagenta(this.#getTimeStamp())} ${chalk.magenta('[Debug]')}`, newContent);
}
/**
* Logs raw debug information. Only works in dev is enabled in the config.
* @param content - The content to log.
*/
- public debugRaw(...content: any): void {
+ public static debugRaw(...content: any): void {
if (!client.config.isDevelopment) return;
- console.log(`${chalk.bgMagenta(this.getTimeStamp())} ${chalk.magenta('[Debug]')}`, ...content);
+ console.log(`${chalk.bgMagenta(this.#getTimeStamp())} ${chalk.magenta('[Debug]')}`, ...content);
}
/**
@@ -107,15 +102,15 @@ export class BushLogger {
* @param sendChannel - Should this also be logged to discord? Defaults to false.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public async verbose(header: string, content: any, sendChannel = false, depth = 0): Promise<void> {
+ public static async verbose(header: string, content: any, sendChannel = false, depth = 0): Promise<void> {
if (!client.config.logging.verbose) return;
- const newContent = this.inspectContent(content, depth, true);
+ const newContent = this.#inspectContent(content, depth, true);
console.info(
- `${chalk.bgGrey(this.getTimeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseFormatting(newContent, 'blackBright')
+ `${chalk.bgGrey(this.#getTimeStamp())} ${chalk.grey(`[${header}]`)} ` + this.#parseFormatting(newContent, 'blackBright')
);
if (!sendChannel) return;
const embed = new MessageEmbed()
- .setDescription(`**[${header}]** ${this.parseFormatting(this.stripColor(newContent), '', true)}`)
+ .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`)
.setColor(util.colors.gray)
.setTimestamp();
await this.channelLog({ embeds: [embed] });
@@ -128,15 +123,15 @@ export class BushLogger {
* @param sendChannel - Should this also be logged to discord? Defaults to false.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public async info(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
+ public static async info(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
if (!client.config.logging.info) return;
- const newContent = this.inspectContent(content, depth, true);
+ const newContent = this.#inspectContent(content, depth, true);
console.info(
- `${chalk.bgCyan(this.getTimeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseFormatting(newContent, 'blueBright')
+ `${chalk.bgCyan(this.#getTimeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.#parseFormatting(newContent, 'blueBright')
);
if (!sendChannel) return;
const embed = new MessageEmbed()
- .setDescription(`**[${header}]** ${this.parseFormatting(this.stripColor(newContent), '', true)}`)
+ .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`)
.setColor(util.colors.info)
.setTimestamp();
await this.channelLog({ embeds: [embed] });
@@ -149,16 +144,16 @@ export class BushLogger {
* @param sendChannel - Should this also be logged to discord? Defaults to false.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public async warn(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
- const newContent = this.inspectContent(content, depth, true);
+ public static async warn(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
+ const newContent = this.#inspectContent(content, depth, true);
console.warn(
- `${chalk.bgYellow(this.getTimeStamp())} ${chalk.yellow(`[${header}]`)} ` +
- this.parseFormatting(newContent, 'yellowBright')
+ `${chalk.bgYellow(this.#getTimeStamp())} ${chalk.yellow(`[${header}]`)} ` +
+ this.#parseFormatting(newContent, 'yellowBright')
);
if (!sendChannel) return;
const embed = new MessageEmbed()
- .setDescription(`**[${header}]** ${this.parseFormatting(this.stripColor(newContent), '', true)}`)
+ .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`)
.setColor(util.colors.warn)
.setTimestamp();
await this.channelLog({ embeds: [embed] });
@@ -171,15 +166,15 @@ export class BushLogger {
* @param sendChannel - Should this also be logged to discord? Defaults to false.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public async error(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
- const newContent = this.inspectContent(content, depth, true);
+ public static async error(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
+ const newContent = this.#inspectContent(content, depth, true);
console.error(
- `${chalk.bgRedBright(this.getTimeStamp())} ${chalk.redBright(`[${header}]`)} ` +
- this.parseFormatting(newContent, 'redBright')
+ `${chalk.bgRedBright(this.#getTimeStamp())} ${chalk.redBright(`[${header}]`)} ` +
+ this.#parseFormatting(newContent, 'redBright')
);
if (!sendChannel) return;
const embed = new MessageEmbed()
- .setDescription(`**[${header}]** ${this.parseFormatting(this.stripColor(newContent), '', true)}`)
+ .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`)
.setColor(util.colors.error)
.setTimestamp();
await this.channelError({ embeds: [embed] });
@@ -192,15 +187,15 @@ export class BushLogger {
* @param sendChannel - Should this also be logged to discord? Defaults to false.
* @param depth - The depth the content will inspected. Defaults to 0.
*/
- public async success(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
- const newContent = this.inspectContent(content, depth, true);
+ public static async success(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
+ const newContent = this.#inspectContent(content, depth, true);
console.log(
- `${chalk.bgGreen(this.getTimeStamp())} ${chalk.greenBright(`[${header}]`)} ` +
- this.parseFormatting(newContent, 'greenBright')
+ `${chalk.bgGreen(this.#getTimeStamp())} ${chalk.greenBright(`[${header}]`)} ` +
+ this.#parseFormatting(newContent, 'greenBright')
);
if (!sendChannel) return;
const embed = new MessageEmbed()
- .setDescription(`**[${header}]** ${this.parseFormatting(this.stripColor(newContent), '', true)}`)
+ .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`)
.setColor(util.colors.success)
.setTimestamp();
await this.channelLog({ embeds: [embed] }).catch(() => {});