diff --git a/apps/discord-bot/src/commands/evaluate.ts b/apps/discord-bot/src/commands/evaluate.ts index 3fdb432..fe536df 100644 --- a/apps/discord-bot/src/commands/evaluate.ts +++ b/apps/discord-bot/src/commands/evaluate.ts @@ -1,9 +1,11 @@ import { ApplicationCommandOptionType, + type AutocompleteInteraction, Command, type CommandInteraction, type CommandOptions, } from '@buape/carbon'; +import { fetchRuntimes, searchRuntimes } from '@evaluate/engine/runtimes'; import { EditEvaluationButton } from '~/components/edit-evaluation-button'; import { EvaluateModal, EvaluateModalEdit } from '~/components/evaluate-modal'; import { handleEvaluating } from '~/handlers/evaluate'; @@ -20,6 +22,7 @@ export class EvaluateCommand extends Command { name: 'runtime', description: 'The runtime in which the code is written.', required: false, + autocomplete: true, }, { type: ApplicationCommandOptionType.String, @@ -44,6 +47,22 @@ export class EvaluateCommand extends Command { components = [EditEvaluationButton]; modals = [EvaluateModal, EvaluateModalEdit]; + async autocomplete(interaction: AutocompleteInteraction) { + const runtime = interaction.options.getString('runtime'); + + if (runtime) { + const runtimes = await searchRuntimes(runtime); + return interaction.respond( + runtimes.slice(0, 25).map((r) => ({ name: r.name, value: r.id })), + ); + } else { + const runtimes = await fetchRuntimes(); + return interaction.respond( + runtimes.slice(0, 25).map((r) => ({ name: r.name, value: r.id })), + ); + } + } + async run(use: CommandInteraction) { captureEvent(getInteractionContext(use.rawData), 'used_command', { command_name: this.name, diff --git a/apps/discord-bot/src/index.ts b/apps/discord-bot/src/index.ts index 4e0ac61..b50e7fc 100644 --- a/apps/discord-bot/src/index.ts +++ b/apps/discord-bot/src/index.ts @@ -33,6 +33,8 @@ export default async function handler(request: Request) { await client.componentHandler.handleInteraction(interaction); if (interaction.type === InteractionType.ModalSubmit) await client.modalHandler.handleInteraction(interaction); + if (interaction.type === InteractionType.ApplicationCommandAutocomplete) + await client.commandHandler.handleAutocompleteInteraction(interaction); await posthog?.shutdown(); return new Response(':)', { status: 200 });