import { buildCommandCatalog } from "./catalog.js";
import { commandMatches } from "../types/command.js";
export function getCommands(context) {
    return buildCommandCatalog(context);
}
export async function runSlashCommand(input, context) {
    const trimmed = input.trim();
    const [nameWithSlash = ""] = trimmed.split(/\s+/);
    const name = nameWithSlash.replace(/^\//, "");
    const args = trimmed.slice(nameWithSlash.length).trim();
    const command = getCommands(context).find((candidate) => commandMatches(candidate, name));
    if (!command) {
        return {
            message: `Unknown command /${name}. Run /help to see available commands.`,
        };
    }
    return command.execute(args, context);
}
