From dde62d4171162ccb55d7b3b88398ff6611e71328 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Fri, 22 Aug 2025 14:52:41 -0700 Subject: [PATCH] feat: add a slash command so we can be discoverable --- src/index.ts | 8 +++ src/modules/processInteraction.ts | 88 +++++++++++++++++++++++++++++++ src/modules/processMessage.ts | 3 +- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/modules/processInteraction.ts diff --git a/src/index.ts b/src/index.ts index 7e67c24..105a21c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { GatewayIntentBits, Events, } from "discord.js"; +import { processInteraction } from "./modules/processInteraction.js"; import { processMessage } from "./modules/processMessage.js"; import { instantiateServer } from "./server/serve.js"; import { logger } from "./utils/logger.js"; @@ -29,5 +30,12 @@ caelia.on(Events.MessageCreate, (message) => { void processMessage(message); }); +caelia.on(Events.InteractionCreate, (interaction) => { + if (!interaction.isChatInputCommand()) { + return; + } + void processInteraction(interaction); +}); + await caelia.login(process.env.BOT_TOKEN); instantiateServer(); diff --git a/src/modules/processInteraction.ts b/src/modules/processInteraction.ts new file mode 100644 index 0000000..cc8cd4d --- /dev/null +++ b/src/modules/processInteraction.ts @@ -0,0 +1,88 @@ +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ + +import { + type ChatInputCommandInteraction, + ContainerBuilder, + TextDisplayBuilder, + SeparatorBuilder, + SeparatorSpacingSize, + ButtonBuilder, + ButtonStyle, + ActionRowBuilder, + MessageFlags, +} from "discord.js"; +import { logger } from "../utils/logger.js"; + +/** + * Handles a slash command. Only responds with the about information, + * because that's all we need. + * @param interaction - The interaction payload from Discord. + */ +// eslint-disable-next-line max-lines-per-function -- Mostly components. +export const processInteraction = async( + interaction: ChatInputCommandInteraction, +): Promise => { + try { + const components = [ + new ContainerBuilder(). + addTextDisplayComponents( + new TextDisplayBuilder().setContent("# About Caelia"), + ). + addTextDisplayComponents( + new TextDisplayBuilder().setContent( + // eslint-disable-next-line stylistic/max-len -- Big boi string. + "Hi there~! I am Caelia, a bot that gives you gentle reminders when you use language that is not inclusive.", + ), + ). + addSeparatorComponents( + new SeparatorBuilder(). + setSpacing(SeparatorSpacingSize.Small). + setDivider(true), + ). + addTextDisplayComponents( + new TextDisplayBuilder().setContent("## What can I do?"), + ). + addTextDisplayComponents( + new TextDisplayBuilder().setContent( + // eslint-disable-next-line stylistic/max-len -- Big boi string. + "This is super duper quick! All you need to do is add me to your server, give me access to see messages and respond in channels you want me to monitor, and I will take care of the rest~!", + ), + ). + addSeparatorComponents( + new SeparatorBuilder(). + setSpacing(SeparatorSpacingSize.Small). + setDivider(true), + ). + addTextDisplayComponents( + new TextDisplayBuilder().setContent("## What if I need help?"), + ). + addTextDisplayComponents( + new TextDisplayBuilder().setContent( + // eslint-disable-next-line stylistic/max-len -- Big boi string. + "My deepest apologies if I have made a mistake! Please reach out to us in our Discord server and we will do our best to assist you.", + ), + ), + new ActionRowBuilder().addComponents( + new ButtonBuilder(). + setStyle(ButtonStyle.Link). + setLabel("Discord Server"). + setURL("https://chat.nhcarrigan.com"), + ), + ]; + await interaction.reply({ + components: components, + flags: MessageFlags.IsComponentsV2, + }); + } 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/modules/processMessage.ts b/src/modules/processMessage.ts index 456826f..3825c12 100644 --- a/src/modules/processMessage.ts +++ b/src/modules/processMessage.ts @@ -39,7 +39,8 @@ export const processMessage = async(message: Message): Promise => { ? match.reason : "I said so."}${[ null, "", undefined, "undefined", "null" ].includes(match.note) ? "" - : ` -- ${match.note}`}`; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Fuck off + : ` -- ${match.note!}`}`; }); await message.reply({ components: [