From 22f741e585324155e644c3b2bcd1fc3bd5b39bb8 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Sun, 2 Nov 2025 09:18:32 -0800 Subject: [PATCH] forgot to use lint --- src/config/blocks.ts | 39 +++++++++++++-------- src/modules/checkAltText.ts | 3 +- src/utils/buttonAck.ts | 68 +++++++++++++++++++++++-------------- 3 files changed, 68 insertions(+), 42 deletions(-) diff --git a/src/config/blocks.ts b/src/config/blocks.ts index 1afa722..e7c6bed 100644 --- a/src/config/blocks.ts +++ b/src/config/blocks.ts @@ -14,7 +14,7 @@ import { ActionRowBuilder, } from "discord.js"; -export const blocks = [ +const blocks = [ new ContainerBuilder(). addTextDisplayComponents( new TextDisplayBuilder().setContent("# About Altaria"), @@ -65,20 +65,29 @@ export const blocks = [ ), ]; -// config for the acknowledgment button +// Config for the acknowledgment button -export const createAckButton = (userId: string) => { - const button = new ButtonBuilder() - .setCustomId(`ack-${userId}`) - .setLabel("Got it!") - .setStyle(ButtonStyle.Secondary) - .setEmoji("✅"); +/** + * Creates an acknowledgment button for alt-text reminders. + * @param userId - The ID of the user who can acknowledge the reminder. + * @returns An array containing an ActionRow with the acknowledgment button. + */ +const createAckButton = ( + userId: string, +): Array> => { + const button = new ButtonBuilder(). + setCustomId(`ack-${userId}`). + setLabel("Got it!"). + setStyle(ButtonStyle.Secondary). + setEmoji("✅"); - - const actionRow = new ActionRowBuilder() - .addComponents(button); + const actionRow = new ActionRowBuilder(). + addComponents(button); - return [actionRow]; - }; - -export const replyForUnauthorized = "❌ This button is only for the person who received the reminder."; \ No newline at end of file + return [ actionRow ]; +}; + +const replyForUnauthorized + = "❌ This button is only for the person who received the reminder."; + +export { blocks, createAckButton, replyForUnauthorized }; diff --git a/src/modules/checkAltText.ts b/src/modules/checkAltText.ts index 34bc288..6054c3b 100644 --- a/src/modules/checkAltText.ts +++ b/src/modules/checkAltText.ts @@ -33,9 +33,10 @@ export const checkAltText = async(message: Message): Promise => { if (noDescription.size > 0) { const reminder = getRandomValue(reminders); + // Button for acknowledgment await message.reply({ components: createAckButton(message.author.id), - content: `${reminder}\n-# If you do not know how to do this, check [Discord's help article]()!\n-# Need help writing descriptive text? Our bot [Cordelia]() can do it for you!`, // Button for acknowledgment + content: `${reminder}\n-# If you do not know how to do this, check [Discord's help article]()!\n-# Need help writing descriptive text? Our bot [Cordelia]() can do it for you!`, }).catch(() => { return null; }); diff --git a/src/utils/buttonAck.ts b/src/utils/buttonAck.ts index 8e6edb6..6752af6 100644 --- a/src/utils/buttonAck.ts +++ b/src/utils/buttonAck.ts @@ -4,37 +4,53 @@ * @author Gurkirat Singh - Technical volunteer */ -import { ButtonInteraction, MessageFlags } from "discord.js"; -import { createAckButton as createAckButtonConfig } from "../config/blocks.js"; -import { replyForUnauthorized } from "../config/blocks.js"; - - +import { type ButtonInteraction, MessageFlags } from "discord.js"; +import { + createAckButton as createAckButtonConfig, + replyForUnauthorized, +} from "../config/blocks.js"; /** - * Creates an acknowledgment button for alt-text reminders - * @param userId - The ID of the user who can acknowledge the reminder - * @returns ActionRow with the acknowledgment button + * Creates an acknowledgment button for alt-text reminders. + * @param userId - The ID of the user who can acknowledge the reminder. + * @returns ActionRow with the acknowledgment button. */ - - -export const createAckButton = (userId: string) => { +const createAckButton = ( + userId: string, +): ReturnType => { return createAckButtonConfig(userId); }; -// function to handle button interaction -export const handleAckButton = async (interaction: ButtonInteraction) => { - if (!interaction.customId.startsWith("ack-")) { - return false; // Not our button - } - - const authorizedUserId = interaction.customId.split("-")[1]; - if (interaction.user.id !== authorizedUserId) { - // Show error that auto-deletes after 2 seconds - await interaction.reply({ content: replyForUnauthorized, flags: MessageFlags.Ephemeral }); - setTimeout(() => interaction.deleteReply().catch(() => {}), 2000); - return true; - } +/** + * Handles button interaction for acknowledgment buttons. + * @param interaction - The button interaction to handle. + * @returns Promise that resolves to true if the button was handled, false otherwise. + */ +const handleAckButton = async( + interaction: ButtonInteraction, +): Promise => { + if (!interaction.customId.startsWith("ack-")) { + // Not our button + return false; + } - await interaction.message.delete(); + const [ , authorizedUserId ] = interaction.customId.split("-"); + if (interaction.user.id !== authorizedUserId) { + // Show error that auto-deletes after 2 seconds + await interaction.reply({ + content: replyForUnauthorized, + flags: MessageFlags.Ephemeral, + }); + setTimeout(() => { + void interaction.deleteReply().catch(() => { + // Intentionally empty - ignore deletion errors + }); + }, 2000); return true; -} + } + + await interaction.message.delete(); + return true; +}; + +export { createAckButton, handleAckButton };