diff --git a/src/index.ts b/src/index.ts index fe2b334..eadf6c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import { GatewayIntentBits, Events, } from "discord.js"; +import { processButton } from "./modules/processButton.js"; import { processInteraction } from "./modules/processInteraction.js"; import { processMessage } from "./server/processMessage.js"; import { instantiateServer } from "./server/serve.js"; @@ -36,10 +37,12 @@ caelia.on(Events.MessageCreate, (message) => { caelia.on(Events.InteractionCreate, (interaction) => { void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction }); - if (!interaction.isChatInputCommand()) { - return; + if (interaction.isChatInputCommand()) { + void processInteraction(interaction); + } + if (interaction.isButton()) { + void processButton(interaction); } - void processInteraction(interaction); }); await caelia.login(process.env.BOT_TOKEN); diff --git a/src/modules/processButton.ts b/src/modules/processButton.ts new file mode 100644 index 0000000..a2d29d8 --- /dev/null +++ b/src/modules/processButton.ts @@ -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 => { + 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.", + }); + } +}; diff --git a/src/server/processMessage.ts b/src/server/processMessage.ts index 49acba3..76e7b5d 100644 --- a/src/server/processMessage.ts +++ b/src/server/processMessage.ts @@ -62,6 +62,14 @@ export const processMessage = async(message: Message): Promise => { }, { 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!", style: 5,