diff --git a/src/config/blocks.ts b/src/config/blocks.ts index e7c6bed..8a71c7f 100644 --- a/src/config/blocks.ts +++ b/src/config/blocks.ts @@ -14,7 +14,7 @@ import { ActionRowBuilder, } from "discord.js"; -const blocks = [ +export const blocks = [ new ContainerBuilder(). addTextDisplayComponents( new TextDisplayBuilder().setContent("# About Altaria"), @@ -64,30 +64,3 @@ const blocks = [ setURL("https://forum.nhcarrigan.com"), ), ]; - -// Config for the acknowledgment button - -/** - * 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); - - return [ actionRow ]; -}; - -const replyForUnauthorized - = "❌ This button is only for the person who received the reminder."; - -export { blocks, createAckButton, replyForUnauthorized }; diff --git a/src/index.ts b/src/index.ts index 6b45884..2e64b6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,8 @@ import { DiscordAnalytics } from "@nhcarrigan/discord-analytics"; import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js"; import { blocks } from "./config/blocks.js"; import { checkAltText } from "./modules/checkAltText.js"; +import { handleAckButton } from "./modules/handleAckButton.js"; import { instantiateServer } from "./server/serve.js"; -import { handleAckButton } from "./utils/buttonAck.js"; import { logger } from "./utils/logger.js"; const client = new Client({ diff --git a/src/modules/checkAltText.ts b/src/modules/checkAltText.ts index 6054c3b..d58fdfc 100644 --- a/src/modules/checkAltText.ts +++ b/src/modules/checkAltText.ts @@ -5,7 +5,7 @@ */ import { reminders } from "../config/reminders.js"; -import { createAckButton } from "../utils/buttonAck.js"; +import { createAckButton } from "../modules/createAckButton.js"; import { getRandomValue } from "../utils/getRandomValue.js"; import { logger } from "../utils/logger.js"; import type { Message } from "discord.js"; diff --git a/src/modules/createAckButton.ts b/src/modules/createAckButton.ts new file mode 100644 index 0000000..3a99322 --- /dev/null +++ b/src/modules/createAckButton.ts @@ -0,0 +1,33 @@ +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Gurkirat Singh - Technical volunteer + */ + +import { + ActionRowBuilder, + ButtonBuilder, + ButtonStyle, +} from "discord.js"; + +/** + * 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); + + return [ actionRow ]; +}; + +export { createAckButton }; diff --git a/src/utils/buttonAck.ts b/src/modules/handleAckButton.ts similarity index 57% rename from src/utils/buttonAck.ts rename to src/modules/handleAckButton.ts index 6752af6..b497f0e 100644 --- a/src/utils/buttonAck.ts +++ b/src/modules/handleAckButton.ts @@ -5,26 +5,11 @@ */ 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. - */ -const createAckButton = ( - userId: string, -): ReturnType => { - return createAckButtonConfig(userId); -}; - -/** - * Handles button interaction for acknowledgment buttons. + * Handles button interactions for acknowledgment buttons. * @param interaction - The button interaction to handle. - * @returns Promise that resolves to true if the button was handled, false otherwise. + * @returns Promise that resolves to true if button was handled, false otherwise. */ const handleAckButton = async( interaction: ButtonInteraction, @@ -38,7 +23,7 @@ const handleAckButton = async( if (interaction.user.id !== authorizedUserId) { // Show error that auto-deletes after 2 seconds await interaction.reply({ - content: replyForUnauthorized, + content: "❌ This button is only for the recipient.", flags: MessageFlags.Ephemeral, }); setTimeout(() => { @@ -53,4 +38,4 @@ const handleAckButton = async( return true; }; -export { createAckButton, handleAckButton }; +export { handleAckButton };