From b5793611d57a734d75b6a0845c441f33d144a5c0 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 4 Aug 2021 19:32:39 -0400 Subject: misc --- src/lib/utils/BushCache.ts | 16 ++++---- src/lib/utils/BushConstants.ts | 41 +++++++++----------- src/lib/utils/BushLogger.ts | 85 ++++++++++++++++++++---------------------- 3 files changed, 64 insertions(+), 78 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/BushCache.ts b/src/lib/utils/BushCache.ts index f9def5e..cdf328b 100644 --- a/src/lib/utils/BushCache.ts +++ b/src/lib/utils/BushCache.ts @@ -1,15 +1,13 @@ import { Collection, Snowflake } from 'discord.js'; import { Guild } from '../models/Guild'; -class GlobalCache { - public static superUsers = new Array(); - public static disabledCommands = new Array(); - public static blacklistedChannels = new Array(); - public static blacklistedGuilds = new Array(); - public static blacklistedUsers = new Array(); -} - export class BushCache { - public static global = GlobalCache; + public static global = { + superUsers: new Array(), + disabledCommands: new Array(), + blacklistedChannels: new Array(), + blacklistedGuilds: new Array(), + blacklistedUsers: new Array() + }; public static guilds = new Collection(); } diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 97f86c4..391db75 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -186,36 +186,25 @@ export class BushConstants { maybeNitroDiscrims: ['1111', '2222', '3333', '4444', '5555', '6666', '6969', '7777', '8888', '9999'], + // prettier-ignore capes: [ - // supporter capes + /* supporter capes */ { name: 'patreon1', index: 0 }, { name: 'patreon2', index: 1 }, { name: 'fade', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/fade.gif', index: 2 }, { name: 'lava', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/lava.gif', index: 3 }, - { - name: 'mcworld', - custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/mcworld_compressed.gif', - index: 4 - }, - { - name: 'negative', - custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/negative_compressed.gif', - index: 5 - }, - { - name: 'space', - custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/space_compressed.gif', - index: 6 - }, + { name: 'mcworld', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/mcworld_compressed.gif', index: 4 }, + { name: 'negative', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/negative_compressed.gif', index: 5 }, + { name: 'space', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/space_compressed.gif', index: 6 }, { name: 'void', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/void.gif', index: 7 }, { name: 'tunnel', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/tunnel.gif', index: 8 }, - // Staff capes + /* Staff capes */ { name: 'contrib', index: 9 }, { name: 'mbstaff', index: 10 }, { name: 'ironmoon', index: 11 }, { name: 'gravy', index: 12 }, { name: 'nullzee', index: 13 }, - // partner capes + /* partner capes */ { name: 'thebakery', index: 14 }, { name: 'dsm', index: 15 }, { name: 'packshq', index: 16 }, @@ -224,12 +213,16 @@ export class BushConstants { { name: 'sbp', index: 19 }, { name: 'subreddit_light', index: 20 }, { name: 'subreddit_dark', index: 21 }, - // streamer capes - { name: 'alexxoffi', index: 22 }, - { name: 'jakethybro', index: 23 }, - { name: 'krusty', index: 24 }, - { name: 'soldier', index: 25 }, - { name: 'zera', index: 26 } + {name : 'skyclient', index: 22 }, + /* streamer capes */ + { name: 'alexxoffi', index: 23 }, + { name: 'jakethybro', index: 24 }, + { name: 'krusty', index: 25 }, + { name: 'krusty_day', index: 26 }, + { name: 'krusty_night', index: 27 }, + { name: 'krusty_sunset', index: 28 }, + { name: 'soldier', index: 29 }, + { name: 'zera', index: 30 }, ], roleMap: [ { name: '*', id: '792453550768390194' }, 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 = []; 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 { + public static async channelLog(message: BushSendMessageType): Promise { const channel = await util.getConfigChannel('log'); await channel.send(message).catch(() => {}); } /** Sends a message to the error channel */ - public async channelError(message: BushSendMessageType): Promise { + public static async channelError(message: BushSendMessageType): Promise { 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 { + public static async verbose(header: string, content: any, sendChannel = false, depth = 0): Promise { 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 { + public static async info(header: string, content: any, sendChannel = true, depth = 0): Promise { 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 { - const newContent = this.inspectContent(content, depth, true); + public static async warn(header: string, content: any, sendChannel = true, depth = 0): Promise { + 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 { - const newContent = this.inspectContent(content, depth, true); + public static async error(header: string, content: any, sendChannel = true, depth = 0): Promise { + 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 { - const newContent = this.inspectContent(content, depth, true); + public static async success(header: string, content: any, sendChannel = true, depth = 0): Promise { + 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(() => {}); -- cgit