diff options
Diffstat (limited to 'src/lib/utils')
-rw-r--r-- | src/lib/utils/BushClientUtils.ts | 2 | ||||
-rw-r--r-- | src/lib/utils/BushConstants.ts | 21 | ||||
-rw-r--r-- | src/lib/utils/BushLogger.ts | 58 | ||||
-rw-r--r-- | src/lib/utils/BushUtils.ts | 2 |
4 files changed, 43 insertions, 40 deletions
diff --git a/src/lib/utils/BushClientUtils.ts b/src/lib/utils/BushClientUtils.ts index af49803..920ff40 100644 --- a/src/lib/utils/BushClientUtils.ts +++ b/src/lib/utils/BushClientUtils.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'assert/strict'; import { cleanCodeBlockContent, DMChannel, diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 67723e3..8a7bf03 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -200,11 +200,22 @@ export const pronounMapping = Object.freeze({ */ export const mappings = deepLock({ guilds: { - bush: '516977525906341928', - tree: '767448775450820639', - staff: '784597260465995796', - space_ship: '717176538717749358', - sbr: '839287012409999391' + "Moulberry's Bush": '516977525906341928', + "Moulberry's Tree": '767448775450820639', + 'MB Staff': '784597260465995796', + "IRONM00N's Space Ship": '717176538717749358' + }, + + channels: { + 'neu-support': '714332750156660756', + 'giveaways': '767782084981817344' + }, + + users: { + IRONM00N: '322862723090219008', + Moulberry: '211288288055525376', + nopo: '384620942577369088', + Bestower: '496409778822709251' }, permissions: { diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts index 5c98760..995dd82 100644 --- a/src/lib/utils/BushLogger.ts +++ b/src/lib/utils/BushLogger.ts @@ -1,6 +1,7 @@ import chalk from 'chalk'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Client, EmbedBuilder, escapeMarkdown, PartialTextBasedChannelFields, type Message } from 'discord.js'; +import { Client, EmbedBuilder, escapeMarkdown, Formatters, PartialTextBasedChannelFields, type Message } from 'discord.js'; +import { stripVTControlCharacters as stripColor } from 'node:util'; import repl, { REPLServer, REPL_MODE_STRICT } from 'repl'; import { WriteStream } from 'tty'; import { type SendMessageType } from '../extensions/discord-akairo/BushClient.js'; @@ -72,16 +73,16 @@ function parseFormatting( discordFormat = false ): string | typeof content { if (typeof content !== 'string') return content; - const newContent: Array<string> = content.split(/<<|>>/); - const tempParsedArray: Array<string> = []; - newContent.forEach((value, index) => { - if (index % 2 !== 0) { - tempParsedArray.push(discordFormat ? `**${escapeMarkdown(value)}**` : color ? chalk[color](value) : value); - } else { - tempParsedArray.push(discordFormat ? escapeMarkdown(value) : value); - } - }); - return tempParsedArray.join(''); + return content + .split(/<<|>>/) + .map((value, index) => { + if (discordFormat) { + return index % 2 === 0 ? escapeMarkdown(value) : Formatters.bold(escapeMarkdown(value)); + } else { + return index % 2 === 0 || !color ? value : chalk[color](value); + } + }) + .join(''); } /** @@ -99,33 +100,24 @@ function inspectContent(content: any, depth = 2, colors = true): string { } /** - * Strips ANSI color codes from a string. - * @param text The string to strip color codes from. - * @returns A string without ANSI color codes. - */ -function 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, - '' - ); -} - -/** * Generates a formatted timestamp for logging. * @returns The formatted timestamp. */ function getTimeStamp(): 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}`; + const minute = pad(now.getMinutes()); + const hour = pad(now.getHours() % 12); + const meridiem = now.getHours() > 12 ? 'PM' : 'AM'; + const year = now.getFullYear().toString().slice(2).padStart(2, '0'); + const date = `${pad(now.getMonth() + 1)}/${pad(now.getDay())}/${year}`; + return `${date} ${hour}:${minute} ${meridiem}`; +} + +/** + * Pad a two-digit number. + */ +function pad(num: number) { + return num.toString().padStart(2, '0'); } /** diff --git a/src/lib/utils/BushUtils.ts b/src/lib/utils/BushUtils.ts index 19260c8..af173f9 100644 --- a/src/lib/utils/BushUtils.ts +++ b/src/lib/utils/BushUtils.ts @@ -10,7 +10,7 @@ import { type SlashMessage } from '#lib'; import { humanizeDuration as humanizeDurationMod } from '@notenoughupdates/humanize-duration'; -import assert from 'assert'; +import assert from 'assert/strict'; import cp from 'child_process'; import deepLock from 'deep-lock'; import { Util as AkairoUtil } from 'discord-akairo'; |