diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/info/inviteInfo.ts | 6 | ||||
-rw-r--r-- | src/commands/utilities/highlight-!.ts | 5 | ||||
-rw-r--r-- | src/lib/utils/BushLogger.ts | 58 | ||||
-rw-r--r-- | src/tasks/cache/updateNeuItemCache.ts | 4 |
4 files changed, 31 insertions, 42 deletions
diff --git a/src/commands/info/inviteInfo.ts b/src/commands/info/inviteInfo.ts index bfe7eae..5df86ad 100644 --- a/src/commands/info/inviteInfo.ts +++ b/src/commands/info/inviteInfo.ts @@ -28,15 +28,15 @@ export default class InviteInfoCommand extends BushCommand { public override async exec(message: CommandMessage | SlashMessage, args: { invite: ArgType<'invite' | 'string'> }) { const invite = message.util.isSlashMessage(message) ? ((await Arg.cast('invite', message, args.invite as string)) as ArgType<'invite'>) - : args.invite; + : (args.invite as Invite); - const inviteInfoEmbed = new EmbedBuilder().setTitle(`Invite to ${invite.guild.name}`).setColor(colors.default); + const inviteInfoEmbed = new EmbedBuilder().setTitle(`Invite to ${invite.guild!.name}`).setColor(colors.default); this.generateAboutField(inviteInfoEmbed, invite); } private generateAboutField(embed: EmbedBuilder, invite: Invite) { - const about = [`**code:** ${invite.code}`, `**channel:** ${}`]; + const about = [`**code:** ${invite.code}`, `**channel:** ${invite.channel!.name}`]; embed.addFields({ name: 'ยป About', value: about.join('\n') }); } diff --git a/src/commands/utilities/highlight-!.ts b/src/commands/utilities/highlight-!.ts index b93f59a..f2ee259 100644 --- a/src/commands/utilities/highlight-!.ts +++ b/src/commands/utilities/highlight-!.ts @@ -186,10 +186,7 @@ export default class HighlightCommand extends BushCommand { throw new Error('This command is not meant to be executed directly.'); } - public override async execSlash( - message: SlashMessage, - args: { subcommand: keyof typeof highlightSubcommands; subcommandGroup?: string } - ) { + public override async execSlash(message: SlashMessage, args: { subcommand: string; subcommandGroup?: string }) { // manual `Flag.continue` const subcommand = this.handler.modules.get(`highlight-${args.subcommandGroup ?? args.subcommand}`)!; return subcommand.exec(message, args); 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/tasks/cache/updateNeuItemCache.ts b/src/tasks/cache/updateNeuItemCache.ts index fff9e08..14c107b 100644 --- a/src/tasks/cache/updateNeuItemCache.ts +++ b/src/tasks/cache/updateNeuItemCache.ts @@ -1,8 +1,8 @@ import { BushTask, Time } from '#lib'; -export default class UpdatePriceItemCache extends BushTask { +export default class UpdateNeuItemCache extends BushTask { public constructor() { - super('updatePriceItemCache', { + super('updateNeuItemCache', { delay: 1 * Time.Hour, runOnStart: true }); |