feat: add button to acknowledge reminders
Node.js CI / Lint and Test (push) Successful in 40s

This commit is contained in:
2025-11-02 09:13:04 -08:00
parent d5d419b06c
commit a915f50f1a
3 changed files with 61 additions and 3 deletions
+6 -3
View File
@@ -10,6 +10,7 @@ import {
GatewayIntentBits, GatewayIntentBits,
Events, Events,
} from "discord.js"; } from "discord.js";
import { processButton } from "./modules/processButton.js";
import { processInteraction } from "./modules/processInteraction.js"; import { processInteraction } from "./modules/processInteraction.js";
import { processMessage } from "./server/processMessage.js"; import { processMessage } from "./server/processMessage.js";
import { instantiateServer } from "./server/serve.js"; import { instantiateServer } from "./server/serve.js";
@@ -36,10 +37,12 @@ caelia.on(Events.MessageCreate, (message) => {
caelia.on(Events.InteractionCreate, (interaction) => { caelia.on(Events.InteractionCreate, (interaction) => {
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction }); void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
if (!interaction.isChatInputCommand()) { if (interaction.isChatInputCommand()) {
return;
}
void processInteraction(interaction); void processInteraction(interaction);
}
if (interaction.isButton()) {
void processButton(interaction);
}
}); });
await caelia.login(process.env.BOT_TOKEN); await caelia.login(process.env.BOT_TOKEN);
+47
View File
@@ -0,0 +1,47 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { logger } from "../utils/logger.js";
import type {
ButtonInteraction,
} from "discord.js";
/**
* Handles a slash command. Only responds with the about information,
* because that's all we need.
* @param interaction - The interaction payload from Discord.
*/
/**
* Handles a button interaction. If the user is not the author of the reminder,
* they cannot acknowledge it.
* @param interaction - The interaction payload from Discord.
*/
export const processButton = async(
interaction: ButtonInteraction,
): Promise<void> => {
try {
await interaction.deferReply();
const { customId, user, message } = interaction;
if (customId !== user.id) {
await interaction.reply({
content: "You cannot acknowledge someone else's reminder.",
ephemeral: true,
});
}
await message.delete();
await interaction.editReply({
content: "Acknowledged!",
});
} catch (error) {
if (error instanceof Error) {
await logger.error("process interaction module", error);
}
await interaction.editReply({
content: "Oh dear, something went wrong.",
});
}
};
+8
View File
@@ -62,6 +62,14 @@ export const processMessage = async(message: Message): Promise<void> => {
}, },
{ {
components: [ components: [
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API
custom_id: author.id,
disabled: false,
label: "Okie Dokie!",
style: 3,
type: 2,
},
{ {
label: "Is this inaccurate? Let us know!", label: "Is this inaccurate? Let us know!",
style: 5, style: 5,