Files
discordeno/plugins/bot/transformers/applicationCommandOption.ts
Skillz4Killz ffe7cdbc6f feat: base plugin lib idea (#2308)
* feat: base plugin lib idea

* fix: stuff

* fmt

* fix: imports and exports

* fix: errors & tests

* fix: remove logs
2022-06-18 18:46:37 -04:00

54 lines
2.4 KiB
TypeScript

import { Bot } from "../bot.ts";
import { ApplicationCommandOptionTypes, ChannelTypes, DiscordApplicationCommandOption, Localization } from "../deps.ts";
import { ApplicationCommandOptionChoice } from "./applicationCommandOptionChoice.ts";
export function transformApplicationCommandOption(
bot: Bot,
payload: DiscordApplicationCommandOption,
): ApplicationCommandOption {
return {
type: payload.type,
name: payload.name,
nameLocalizations: payload.name_localizations ?? undefined,
description: payload.description,
descriptionLocalizations: payload.description_localizations ?? undefined,
required: payload.required ?? false,
choices: payload.choices?.map((choice) => bot.transformers.applicationCommandOptionChoice(bot, choice)),
autocomplete: payload.autocomplete,
channelTypes: payload.channel_types,
minValue: payload.min_value,
maxValue: payload.max_value,
options: payload.options?.map((option) => bot.transformers.applicationCommandOption(bot, option)),
};
}
// THIS TRANSFORMER HAS A CIRCULAR REFERENCE TO CALL ITSELF FOR OPTIONS SO AN AUTOMATED TYPE CAN NOT BE CREATED!
export interface ApplicationCommandOption {
/** Value of Application Command Option Type */
type: ApplicationCommandOptionTypes;
/** 1-32 character name matching lowercase `^[\w-]{1,32}$` */
name: string;
/** Localization object for the `name` field. Values follow the same restrictions as `name` */
nameLocalizations?: Localization;
/** 1-100 character description */
description: string;
/** Localization object for the `description` field. Values follow the same restrictions as `description` */
descriptionLocalizations?: Localization;
/** If the parameter is required or optional--default `false` */
required?: boolean;
/** Choices for `string` and `int` types for the user to pick from */
choices?: ApplicationCommandOptionChoice[];
/** If the option is a subcommand or subcommand group type, this nested options will be the parameters */
options?: ApplicationCommandOption[];
/** if autocomplete interactions are enabled for this `String`, `Integer`, or `Number` type option */
autocomplete?: boolean;
/** If the option is a channel type, the channels shown will be restricted to these types */
channelTypes?: ChannelTypes[];
/** Minimum number desired. */
minValue?: number;
/** Maximum number desired. */
maxValue?: number;
}