From 25cf269e2e793de5fefb9aa3f19fb167168e06c6 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 20:13:49 -0400 Subject: stuff --- src/lib/utils/Console.ts | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/lib/utils/Console.ts (limited to 'src/lib/utils/Console.ts') diff --git a/src/lib/utils/Console.ts b/src/lib/utils/Console.ts new file mode 100644 index 0000000..36c078c --- /dev/null +++ b/src/lib/utils/Console.ts @@ -0,0 +1,94 @@ +import chalk from 'chalk'; +import { BushClient } from '../extensions/BushClient'; + +export class CustomConsole { + private client: BushClient; + public constructor(client: BushClient) { + this.client = client; + } + + private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string|any { + if (typeof content === 'string') { + const newContent: Array = content.split(/<<|>>/); + const tempParsedArray: Array = []; + newContent.forEach((value, index) => { + if (index % 2 !== 0) { + tempParsedArray.push(chalk[color](value)); + } else { + tempParsedArray.push(value); + } + }); + return tempParsedArray.join(''); + } else { + return content + } + + } + + private timeStamp(): string { + const now = new Date(); + const hours = now.getHours(); + const minute = now.getMinutes(); + let hour = hours; + let amOrPm: 'AM' | 'PM' = 'AM'; + if (hour > 12) { + amOrPm = 'PM'; + hour = hour - 12; + } + + return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; + } + + /** + * Logs debug information. + * @param content - The content to log. + */ + public debug(content: any): void { + console.log(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey('[Debug]')}`, content); + } + + /** + * Logs verbose information. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in grey. + * @param content - The content to log, highlights displayed in bright black. + */ + public verbose(header: string, content: string): void { + return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} `+this.parseColors(content, 'blackBright')); + } + + /** + * Logs information. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in cyan. + * @param content - The content to log, highlights displayed in bright blue. + */ + public info(header: string, content: string): void { + return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} `+this.parseColors(content, 'blueBright')); + } + + /** + * Logs warnings. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in yellow. + * @param content - The content to log, highlights displayed in bright yellow. + */ + public warn(header: string, content: string): void { + return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} `+this.parseColors(content, 'yellowBright')); + } + + /** + * Logs errors. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in bright red. + * @param content - The content to log, highlights displayed in bright red. + */ + public error(header: string, content: string): void { + return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} `+ this.parseColors(content, 'redBright')); + } + + /** + * Logs successes. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in green. + * @param content - The content to log, highlights displayed in bright green. + */ + public success(header: string, content: string): void { + return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} `+this.parseColors(content, 'greenBright')); + } +} -- cgit From fbce619ff39521bdd30ab6598c83d0c94e5ae6b8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 29 May 2021 00:14:24 +0000 Subject: Automatically format code --- src/lib/utils/Console.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/lib/utils/Console.ts') diff --git a/src/lib/utils/Console.ts b/src/lib/utils/Console.ts index 36c078c..5b61094 100644 --- a/src/lib/utils/Console.ts +++ b/src/lib/utils/Console.ts @@ -7,7 +7,7 @@ export class CustomConsole { this.client = client; } - private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string|any { + private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string | any { if (typeof content === 'string') { const newContent: Array = content.split(/<<|>>/); const tempParsedArray: Array = []; @@ -20,9 +20,8 @@ export class CustomConsole { }); return tempParsedArray.join(''); } else { - return content + return content; } - } private timeStamp(): string { @@ -53,7 +52,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright black. */ public verbose(header: string, content: string): void { - return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} `+this.parseColors(content, 'blackBright')); + return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseColors(content, 'blackBright')); } /** @@ -62,7 +61,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright blue. */ public info(header: string, content: string): void { - return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} `+this.parseColors(content, 'blueBright')); + return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseColors(content, 'blueBright')); } /** @@ -71,7 +70,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright yellow. */ public warn(header: string, content: string): void { - return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} `+this.parseColors(content, 'yellowBright')); + return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} ` + this.parseColors(content, 'yellowBright')); } /** @@ -80,7 +79,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright red. */ public error(header: string, content: string): void { - return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} `+ this.parseColors(content, 'redBright')); + return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} ` + this.parseColors(content, 'redBright')); } /** @@ -89,6 +88,6 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright green. */ public success(header: string, content: string): void { - return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} `+this.parseColors(content, 'greenBright')); + return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} ` + this.parseColors(content, 'greenBright')); } } -- cgit From 6bb93ad27fbc39dc8cf6c8adb5e88e7c39e6c788 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 20:17:31 -0400 Subject: I am dumb --- src/lib/utils/Console.ts | 166 +++++++++++++++++++++++------------------------ src/lib/utils/Logger.ts | 82 +++++++++++------------ 2 files changed, 124 insertions(+), 124 deletions(-) (limited to 'src/lib/utils/Console.ts') diff --git a/src/lib/utils/Console.ts b/src/lib/utils/Console.ts index 5b61094..b74ea07 100644 --- a/src/lib/utils/Console.ts +++ b/src/lib/utils/Console.ts @@ -1,93 +1,93 @@ -import chalk from 'chalk'; -import { BushClient } from '../extensions/BushClient'; +// import chalk from 'chalk'; +// import { BushClient } from '../extensions/BushClient'; -export class CustomConsole { - private client: BushClient; - public constructor(client: BushClient) { - this.client = client; - } +// export class CustomConsole { +// private client: BushClient; +// public constructor(client: BushClient) { +// this.client = client; +// } - private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string | any { - if (typeof content === 'string') { - const newContent: Array = content.split(/<<|>>/); - const tempParsedArray: Array = []; - newContent.forEach((value, index) => { - if (index % 2 !== 0) { - tempParsedArray.push(chalk[color](value)); - } else { - tempParsedArray.push(value); - } - }); - return tempParsedArray.join(''); - } else { - return content; - } - } +// private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string | any { +// if (typeof content === 'string') { +// const newContent: Array = content.split(/<<|>>/); +// const tempParsedArray: Array = []; +// newContent.forEach((value, index) => { +// if (index % 2 !== 0) { +// tempParsedArray.push(chalk[color](value)); +// } else { +// tempParsedArray.push(value); +// } +// }); +// return tempParsedArray.join(''); +// } else { +// return content; +// } +// } - private timeStamp(): string { - const now = new Date(); - const hours = now.getHours(); - const minute = now.getMinutes(); - let hour = hours; - let amOrPm: 'AM' | 'PM' = 'AM'; - if (hour > 12) { - amOrPm = 'PM'; - hour = hour - 12; - } +// private timeStamp(): string { +// const now = new Date(); +// const hours = now.getHours(); +// const minute = now.getMinutes(); +// let hour = hours; +// let amOrPm: 'AM' | 'PM' = 'AM'; +// if (hour > 12) { +// amOrPm = 'PM'; +// hour = hour - 12; +// } - return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; - } +// return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; +// } - /** - * Logs debug information. - * @param content - The content to log. - */ - public debug(content: any): void { - console.log(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey('[Debug]')}`, content); - } +// /** +// * Logs debug information. +// * @param content - The content to log. +// */ +// public debug(content: any): void { +// console.log(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey('[Debug]')}`, content); +// } - /** - * Logs verbose information. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in grey. - * @param content - The content to log, highlights displayed in bright black. - */ - public verbose(header: string, content: string): void { - return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseColors(content, 'blackBright')); - } +// /** +// * Logs verbose information. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in grey. +// * @param content - The content to log, highlights displayed in bright black. +// */ +// public verbose(header: string, content: string): void { +// return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseColors(content, 'blackBright')); +// } - /** - * Logs information. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in cyan. - * @param content - The content to log, highlights displayed in bright blue. - */ - public info(header: string, content: string): void { - return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseColors(content, 'blueBright')); - } +// /** +// * Logs information. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in cyan. +// * @param content - The content to log, highlights displayed in bright blue. +// */ +// public info(header: string, content: string): void { +// return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseColors(content, 'blueBright')); +// } - /** - * Logs warnings. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in yellow. - * @param content - The content to log, highlights displayed in bright yellow. - */ - public warn(header: string, content: string): void { - return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} ` + this.parseColors(content, 'yellowBright')); - } +// /** +// * Logs warnings. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in yellow. +// * @param content - The content to log, highlights displayed in bright yellow. +// */ +// public warn(header: string, content: string): void { +// return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} ` + this.parseColors(content, 'yellowBright')); +// } - /** - * Logs errors. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in bright red. - * @param content - The content to log, highlights displayed in bright red. - */ - public error(header: string, content: string): void { - return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} ` + this.parseColors(content, 'redBright')); - } +// /** +// * Logs errors. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in bright red. +// * @param content - The content to log, highlights displayed in bright red. +// */ +// public error(header: string, content: string): void { +// return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} ` + this.parseColors(content, 'redBright')); +// } - /** - * Logs successes. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in green. - * @param content - The content to log, highlights displayed in bright green. - */ - public success(header: string, content: string): void { - return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} ` + this.parseColors(content, 'greenBright')); - } -} +// /** +// * Logs successes. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in green. +// * @param content - The content to log, highlights displayed in bright green. +// */ +// public success(header: string, content: string): void { +// return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} ` + this.parseColors(content, 'greenBright')); +// } +// } diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts index 95f32ad..b0f7da5 100644 --- a/src/lib/utils/Logger.ts +++ b/src/lib/utils/Logger.ts @@ -1,43 +1,43 @@ -// import { TextChannel } from 'discord.js'; -// import { BushClient } from '../extensions/BushClient'; -// import chalk from 'chalk'; +import { TextChannel } from 'discord.js'; +import { BushClient } from '../extensions/BushClient'; +import chalk from 'chalk'; -// export class Logger { -// private client: BushClient; -// public constructor(client: BushClient) { -// this.client = client; -// } -// private 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, -// '' -// ); -// } -// public getChannel(channel: 'log' | 'error' | 'dm'): Promise { -// return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; -// } -// public async log(message: string, sendChannel = false): Promise { -// console.log(chalk`{bgCyan LOG} ` + message); -// if (sendChannel) { -// const channel = await this.getChannel('log'); -// await channel.send('[LOG] ' + this.stripColor(message)); -// } -// } +export class Logger { + private client: BushClient; + public constructor(client: BushClient) { + this.client = client; + } + private 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, + '' + ); + } + public getChannel(channel: 'log' | 'error' | 'dm'): Promise { + return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; + } + public async log(message: string, sendChannel = false): Promise { + console.log(chalk`{bgCyan LOG} ` + message); + if (sendChannel) { + const channel = await this.getChannel('log'); + await channel.send('[LOG] ' + this.stripColor(message)); + } + } -// public async verbose(message: string, sendChannel = false): Promise { -// if (!this.client.config.verbose) return; -// console.log(chalk`{bgMagenta VERBOSE} ` + message); -// if (sendChannel) { -// const channel = await this.getChannel('log'); -// await channel.send('[VERBOSE] ' + this.stripColor(message)); -// } -// } -// public async error(message: string, sendChannel = false): Promise { -// console.log(chalk`{bgRed ERROR} ` + message); -// if (sendChannel) { -// const channel = await this.getChannel('error'); -// await channel.send('[ERROR] ' + this.stripColor(message)); -// } -// } -// } + public async verbose(message: string, sendChannel = false): Promise { + if (!this.client.config.verbose) return; + console.log(chalk`{bgMagenta VERBOSE} ` + message); + if (sendChannel) { + const channel = await this.getChannel('log'); + await channel.send('[VERBOSE] ' + this.stripColor(message)); + } + } + public async error(message: string, sendChannel = false): Promise { + console.log(chalk`{bgRed ERROR} ` + message); + if (sendChannel) { + const channel = await this.getChannel('error'); + await channel.send('[ERROR] ' + this.stripColor(message)); + } + } +} -- cgit