/** * @copyright NHCarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { MessageFlags, type ChatInputCommandInteraction, type Interaction, } from "discord.js"; import { createIssue } from "../commands/createIssue.js"; import { createTask } from "../commands/createTask.js"; import { forwardToOwner } from "../commands/forwardToOwner.js"; import { onboardMentee } from "../commands/onboardMentee.js"; import { ids } from "../config/ids.js"; import type { Amari } from "../interfaces/amari.js"; /** * Routes a chat input command to the appropriate handler. * @param amari -- Amari's instance. * @param interaction -- The incoming slash command to dispatch. */ const handleChatInputCommand = ( amari: Amari, interaction: ChatInputCommandInteraction, ): void => { const { commandName } = interaction; if (commandName === "onboard-mentee") { void onboardMentee(amari, interaction); return; } if (commandName === "create-task") { void createTask(interaction); return; } if (commandName === "create-issue") { void createIssue(interaction); } }; /** * Handles the interaction create event from Discord. * Bootstraps all of our custom interaction logic. * @param amari -- Amari's instance. * @param interaction -- The incoming Discord gateway event to dispatch. */ export const handleInteractionCreate = ( amari: Amari, interaction: Interaction, ): void => { if ( interaction.isMessageContextMenuCommand() && interaction.commandName === "Forward to Naomi" ) { void forwardToOwner(interaction); return; } if (interaction.isButton() && interaction.customId === "resolve") { if (interaction.user.id !== ids.users.naomi) { void interaction.reply({ content: "Who are you????", flags: [ MessageFlags.Ephemeral ], }); return; } void interaction.message.delete(); return; } if (interaction.isChatInputCommand()) { handleChatInputCommand(amari, interaction); return; } if (interaction.isAutocomplete()) { return; } void interaction.reply({ content: "What?", flags: [ MessageFlags.Ephemeral ], }); };