feat: add button to clear reminder #3

Merged
naomi merged 5 commits from Add-button-to-clear-reminder-#2 into main 2025-11-02 09:23:30 -08:00
5 changed files with 40 additions and 49 deletions
Showing only changes of commit 429f4cf24f - Show all commits
+1 -28
View File
@@ -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<ActionRowBuilder<ButtonBuilder>> => {
const button = new ButtonBuilder().
setCustomId(`ack-${userId}`).
setLabel("Got it!").
setStyle(ButtonStyle.Secondary).
setEmoji("✅");
const actionRow = new ActionRowBuilder<ButtonBuilder>().
addComponents(button);
return [ actionRow ];
};
const replyForUnauthorized
= "❌ This button is only for the person who received the reminder.";
export { blocks, createAckButton, replyForUnauthorized };
+1 -1
View File
@@ -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({
+1 -1
View File
@@ -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";
+33
View File
@@ -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<ActionRowBuilder<ButtonBuilder>> => {
const button = new ButtonBuilder().
setCustomId(`ack-${userId}`).
setLabel("Got it!").
setStyle(ButtonStyle.Secondary).
setEmoji("✅");
const actionRow = new ActionRowBuilder<ButtonBuilder>().
addComponents(button);
return [ actionRow ];
};
export { createAckButton };
@@ -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<typeof createAckButtonConfig> => {
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 };