2024-03-05 09:59:46 -06:00
|
|
|
import { Locale, SlashCommandBuilder } from 'discord.js';
|
|
|
|
|
import { translator } from '../localization/translator';
|
|
|
|
|
import { localizationObject } from './localizationObject';
|
|
|
|
|
|
|
|
|
|
interface CreateLocalizedCommandSubcommand {
|
|
|
|
|
subcommand: string;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 10:51:14 -06:00
|
|
|
export function createLocalizedCommand(
|
2024-03-05 09:59:46 -06:00
|
|
|
command: string,
|
|
|
|
|
subcommands?: CreateLocalizedCommandSubcommand[],
|
|
|
|
|
) {
|
2024-03-05 10:51:14 -06:00
|
|
|
const { translate } = translator(Locale.EnglishUS);
|
2024-03-05 09:59:46 -06:00
|
|
|
const slashCommand = new SlashCommandBuilder()
|
|
|
|
|
.setName(command)
|
2024-03-05 10:51:14 -06:00
|
|
|
.setNameLocalizations(localizationObject(`bot.commands.${command}`))
|
2024-03-05 09:59:46 -06:00
|
|
|
.setDescription(translate(`bot.commands.${command}.description`))
|
|
|
|
|
.setDescriptionLocalizations(
|
2024-03-05 10:51:14 -06:00
|
|
|
localizationObject(`bot.commands.${command}.description`),
|
2024-03-05 09:59:46 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (subcommands) {
|
2024-03-05 10:51:14 -06:00
|
|
|
subcommands.map(({ subcommand }) => {
|
|
|
|
|
const subcommandNameLocalizations = localizationObject(
|
|
|
|
|
`bot.commands.${command}.subcommands.${subcommand}`,
|
|
|
|
|
);
|
|
|
|
|
const subcommandDescriptionLocalizations = localizationObject(
|
|
|
|
|
`bot.commands.${command}.subcommands.${subcommand}.description`,
|
|
|
|
|
);
|
2024-03-05 09:59:46 -06:00
|
|
|
|
2024-03-05 10:51:14 -06:00
|
|
|
slashCommand.addSubcommand((option) =>
|
|
|
|
|
option
|
|
|
|
|
.setName(subcommand)
|
|
|
|
|
.setNameLocalizations(subcommandNameLocalizations)
|
|
|
|
|
.setDescription(
|
|
|
|
|
translate(
|
|
|
|
|
`bot.commands.${command}.subcommands.${subcommand}.description`,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.setDescriptionLocalizations(subcommandDescriptionLocalizations),
|
|
|
|
|
);
|
|
|
|
|
});
|
2024-03-05 09:59:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slashCommand;
|
|
|
|
|
}
|