From dcdfc1fda7cfedf7c0f69ba51857fd7ebc71a2dd Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 29 Dec 2021 16:20:06 -0500 Subject: refactoring & documentation --- src/lib/common/DeleteButton.ts | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/lib/common/DeleteButton.ts') diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts index e2509a9..b666a4f 100644 --- a/src/lib/common/DeleteButton.ts +++ b/src/lib/common/DeleteButton.ts @@ -1,25 +1,34 @@ import { PaginateEmojis, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandUtil } from 'discord-akairo'; -import { Constants, MessageActionRow, MessageButton, type MessageComponentInteraction, type MessageOptions } from 'discord.js'; +import { MessageActionRow, MessageButton, type MessageComponentInteraction, type MessageOptions } from 'discord.js'; +import { MessageButtonStyles } from 'discord.js/typings/enums'; +/** + * Sends a message with a button for the user to delete it. + */ export class DeleteButton { + /** + * Options for sending the message + */ protected messageOptions: MessageOptions; - protected message: BushMessage | BushSlashMessage; /** - * Sends a message with a button for the user to delete it. - * @param message - The message to respond to - * @param options - The send message options + * The message that triggered the command */ - static async send(message: BushMessage | BushSlashMessage, options: Omit) { - return new DeleteButton(message, options).send(); - } + protected message: BushMessage | BushSlashMessage; + /** + * @param message The message to respond to + * @param options The send message options + */ protected constructor(message: BushMessage | BushSlashMessage, options: MessageOptions) { this.message = message; this.messageOptions = options; } + /** + * Sends a message with a button for the user to delete it. + */ protected async send() { this.updateComponents(); @@ -43,11 +52,16 @@ export class DeleteButton { }); } + /** + * Generates the components for the message + * @param edit Whether or not the message is being edited + * @param disable Whether or not to disable the buttons + */ protected updateComponents(edit = false, disable = false): void { this.messageOptions.components = [ new MessageActionRow().addComponents( new MessageButton({ - style: Constants.MessageButtonStyles.PRIMARY, + style: MessageButtonStyles.PRIMARY, customId: 'paginate__stop', emoji: PaginateEmojis.STOP, disabled: disable @@ -58,4 +72,13 @@ export class DeleteButton { this.messageOptions.reply = undefined; } } + + /** + * Sends a message with a button for the user to delete it. + * @param message The message to respond to + * @param options The send message options + */ + public static async send(message: BushMessage | BushSlashMessage, options: Omit) { + return new DeleteButton(message, options).send(); + } } -- cgit