/** * @copyright NHCarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { MessageFlags, type ChatInputCommandInteraction } from "discord.js"; import { ids } from "../config/ids.js"; import { logger } from "../utils/logger.js"; import { makeAiRequest } from "../utils/makeAiRequest.js"; import type { Amari } from "../interfaces/amari.js"; const fallbackResponse = "I'm sorry, I don't have an answer for that." + " Please try again later."; /** * Accepts an arbitrary question and sends it to Claude to be answered. * @param _amari - The Amari instance (unused but kept for handler consistency). * @param interaction - The Discord slash command interaction. */ export const query = async( _amari: Amari, interaction: ChatInputCommandInteraction, ): Promise => { if (interaction.user.id !== ids.users.naomi) { await interaction.reply({ content: "This command is restricted to Naomi.", flags: [ MessageFlags.Ephemeral ], }); return; } const prompt = interaction.options.getString("prompt", true); await interaction.deferReply({ flags: [ MessageFlags.Ephemeral ] }); try { const response = await makeAiRequest({ maxTokens: 2000, systemPrompt: "Your role in this conversation is to answer the user's" + " question to the best of your abilities. When possible, include" + " links to relevant sources.", userMessage: prompt, }); await interaction.editReply({ content: response ?? fallbackResponse, }); } catch (error) { await logger.error("query command", error instanceof Error ? error : new Error(String(error))); await interaction.editReply({ content: "Something went wrong whilst processing your question.", }); } };