33 lines
892 B
TypeScript
33 lines
892 B
TypeScript
import { CommandsCollection } from "@avocadi/bot-core/entities/commands/commands.entity";
|
|
import type { Command } from "@avocadi/bot-core/entities/commands/commands.schema";
|
|
import { SlashCommandBuilder } from "discord.js";
|
|
import type { z } from "zod";
|
|
|
|
const convertCommandToDiscordFormat = (
|
|
command: z.output<typeof Command>,
|
|
key: string,
|
|
) => {
|
|
const slashCommand = new SlashCommandBuilder()
|
|
.setName(command.name || key)
|
|
.setDescription(command.description);
|
|
|
|
if (command.options) {
|
|
command.options.forEach((option) => {
|
|
slashCommand.addStringOption((opt) =>
|
|
opt
|
|
.setName(option.name)
|
|
.setDescription(option.description)
|
|
.setRequired(option.required),
|
|
);
|
|
});
|
|
}
|
|
|
|
return slashCommand;
|
|
};
|
|
|
|
export default function getCommands() {
|
|
return Object.entries(CommandsCollection).map(([key, command]) =>
|
|
convertCommandToDiscordFormat(command, key),
|
|
);
|
|
}
|