Files
hikari/bot/src/events/interactionCreate.ts
T
naomi 5bd6e03a8d
Node.js CI / Lint and Test (push) Successful in 1m39s
feat: add analytics, fix mcp logic
2025-10-09 20:36:39 -07:00

43 lines
1.3 KiB
TypeScript

/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { about } from "../commands/about.js";
import { dm } from "../commands/dm.js";
import { logger } from "../utils/logger.js";
import type { Command } from "../interfaces/command.js";
import type { ChatInputCommandInteraction, Client } from "discord.js";
const handlers: { _default: Command } & Record<string, Command> = {
_default: async(_, interaction): Promise<void> => {
await interaction.reply({
content: `Unknown command: ${interaction.commandName}`,
ephemeral: true,
});
},
about: about,
dm: dm,
};
/**
* Processes a slash command.
* @param hikari - Hikari's Discord instance.
* @param interaction - The command interaction payload from Discord.
*/
const chatInputInteractionCreate = async(
hikari: Client,
interaction: ChatInputCommandInteraction,
): Promise<void> => {
const name = interaction.commandName;
// eslint-disable-next-line no-underscore-dangle -- We use _default as a fallback handler.
const handler = handlers[name] ?? handlers._default;
await handler(hikari, interaction);
await logger.metric("interaction_create", 1, {
command: name,
guild: interaction.guild?.id ?? "unknown",
});
};
export { chatInputInteractionCreate };