Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/discord-bot/src/commands/evaluate.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions apps/discord-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down