diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 16:20:06 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 16:20:06 -0500 |
commit | dcdfc1fda7cfedf7c0f69ba51857fd7ebc71a2dd (patch) | |
tree | 49845130275172abe14162427336842a7a71ccad /src/lib/common/DeleteButton.ts | |
parent | 4cebaca70939b87c78537c5c3cd099e29e2e4e04 (diff) | |
download | tanzanite-dcdfc1fda7cfedf7c0f69ba51857fd7ebc71a2dd.tar.gz tanzanite-dcdfc1fda7cfedf7c0f69ba51857fd7ebc71a2dd.tar.bz2 tanzanite-dcdfc1fda7cfedf7c0f69ba51857fd7ebc71a2dd.zip |
refactoring & documentation
Diffstat (limited to 'src/lib/common/DeleteButton.ts')
-rw-r--r-- | src/lib/common/DeleteButton.ts | 41 |
1 files changed, 32 insertions, 9 deletions
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<MessageOptions, 'components'>) { - 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<MessageOptions, 'components'>) { + return new DeleteButton(message, options).send(); + } } |