From 0dbdb1cbd6e5dab2cc39ca58a7a1a43e6fdc4950 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 11 May 2024 19:35:45 +0700 Subject: [PATCH] fix(help): hoot in footer too short (excluded "hot") --- src/commands/General/help.ts | 4 ++-- src/lib/utils.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/commands/General/help.ts b/src/commands/General/help.ts index 6c62a7c..16e154a 100644 --- a/src/commands/General/help.ts +++ b/src/commands/General/help.ts @@ -2,7 +2,7 @@ import { ApplyOptions } from '@sapphire/decorators'; import { PaginatedMessage } from '@sapphire/discord.js-utilities'; import { Command } from '@sapphire/framework'; import { ApplicationCommandType, EmbedBuilder, chatInputApplicationCommandMention } from 'discord.js'; -import { getRandomHoot, replyLoadingChatInputInteraction } from '../../lib/utils'; +import { getRandomHootString, replyLoadingChatInputInteraction } from '../../lib/utils'; const dev = process.env.NODE_ENV !== 'production'; @@ -25,7 +25,7 @@ export class UserCommand extends Command { template: new EmbedBuilder() .setColor('Random') // Be sure to add a space so this is offset from the page numbers! - .setFooter({ text: ` ${getRandomHoot()}`, iconURL: `${interaction.user.displayAvatarURL()}` }) + .setFooter({ text: ` ${getRandomHootString()}`, iconURL: `${interaction.user.displayAvatarURL()}` }) .setThumbnail(this.container.client.user?.displayAvatarURL() || null) }); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index ca1b27a..7bb8e85 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -135,11 +135,15 @@ export function getRandomInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; } -export function getRandomHoot(oLength: number = 0, upperH: boolean = false, upperCase: boolean = false) { - const min = 1, +export function getRandomHootString(oLength: number = 0, upperH: boolean = false, upperCase: boolean = false) { + const min = 2, max = oLength <= 0 ? 10 : oLength > 10 ? 10 : oLength; const randomLength = getRandomInt(min, max); - const oString = new Array(randomLength).fill('o').join(''); + const oString = generateDuplicateString('o', randomLength); const content = `${upperH ? 'H' : 'h'}${oString}t`; return upperCase ? content.toUpperCase() : content; } + +export function generateDuplicateString(input: string, length: number) { + return new Array(length).fill(input).join(''); +}