generated from nhcarrigan/template
feat: add button to clear reminder #3
+1
-28
@@ -14,7 +14,7 @@ import {
|
|||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
|
||||||
const blocks = [
|
export const blocks = [
|
||||||
new ContainerBuilder().
|
new ContainerBuilder().
|
||||||
addTextDisplayComponents(
|
addTextDisplayComponents(
|
||||||
new TextDisplayBuilder().setContent("# About Altaria"),
|
new TextDisplayBuilder().setContent("# About Altaria"),
|
||||||
@@ -64,30 +64,3 @@ const blocks = [
|
|||||||
setURL("https://forum.nhcarrigan.com"),
|
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
@@ -8,8 +8,8 @@ import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
|||||||
import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js";
|
import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js";
|
||||||
import { blocks } from "./config/blocks.js";
|
import { blocks } from "./config/blocks.js";
|
||||||
import { checkAltText } from "./modules/checkAltText.js";
|
import { checkAltText } from "./modules/checkAltText.js";
|
||||||
|
import { handleAckButton } from "./modules/handleAckButton.js";
|
||||||
import { instantiateServer } from "./server/serve.js";
|
import { instantiateServer } from "./server/serve.js";
|
||||||
import { handleAckButton } from "./utils/buttonAck.js";
|
|
||||||
import { logger } from "./utils/logger.js";
|
import { logger } from "./utils/logger.js";
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { reminders } from "../config/reminders.js";
|
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 { getRandomValue } from "../utils/getRandomValue.js";
|
||||||
import { logger } from "../utils/logger.js";
|
import { logger } from "../utils/logger.js";
|
||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
|
|||||||
@@ -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 { type ButtonInteraction, MessageFlags } from "discord.js";
|
||||||
import {
|
|
||||||
createAckButton as createAckButtonConfig,
|
|
||||||
replyForUnauthorized,
|
|
||||||
} from "../config/blocks.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an acknowledgment button for alt-text reminders.
|
* Handles button interactions for acknowledgment buttons.
|
||||||
* @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.
|
|
||||||
* @param interaction - The button interaction to handle.
|
* @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(
|
const handleAckButton = async(
|
||||||
interaction: ButtonInteraction,
|
interaction: ButtonInteraction,
|
||||||
@@ -38,7 +23,7 @@ const handleAckButton = async(
|
|||||||
if (interaction.user.id !== authorizedUserId) {
|
if (interaction.user.id !== authorizedUserId) {
|
||||||
// Show error that auto-deletes after 2 seconds
|
// Show error that auto-deletes after 2 seconds
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: replyForUnauthorized,
|
content: "❌ This button is only for the recipient.",
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -53,4 +38,4 @@ const handleAckButton = async(
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { createAckButton, handleAckButton };
|
export { handleAckButton };
|
||||||
Reference in New Issue
Block a user