diff --git a/packages/bot/src/index.ts b/packages/bot/src/index.ts index 994653bd8..9cae2c845 100644 --- a/packages/bot/src/index.ts +++ b/packages/bot/src/index.ts @@ -3,6 +3,8 @@ export * from '@discordeno/rest' export * from '@discordeno/types' export * from '@discordeno/utils' export * from './bot.js' +export * from './handlers/index.js' export * from './handlers.js' +export * from './transformers/index.js' export * from './transformers.js' export * from './utils.js' diff --git a/packages/bot/src/transformers.ts b/packages/bot/src/transformers.ts index 0273d98e6..a0e0f1ce0 100644 --- a/packages/bot/src/transformers.ts +++ b/packages/bot/src/transformers.ts @@ -1,7 +1,5 @@ import type { AllowedMentions, - ApplicationCommandOption, - ApplicationCommandOptionChoice, BigString, CreateApplicationCommand, DiscordActivity, @@ -48,8 +46,8 @@ import { bigintToSnowflake, snowflakeToBigint, type Bot } from './index.js' import { transformActivity, type Activity } from './transformers/activity.js' import { transformApplication, type Application } from './transformers/application.js' import { transformApplicationCommand, type ApplicationCommand } from './transformers/applicationCommand.js' -import { transformApplicationCommandOption } from './transformers/applicationCommandOption.js' -import { transformApplicationCommandOptionChoice } from './transformers/applicationCommandOptionChoice.js' +import { transformApplicationCommandOption, type ApplicationCommandOption } from './transformers/applicationCommandOption.js' +import { transformApplicationCommandOptionChoice, type ApplicationCommandOptionChoice } from './transformers/applicationCommandOptionChoice.js' import { transformApplicationCommandPermission, type ApplicationCommandPermission } from './transformers/applicationCommandPermission.js' import { transformAttachment, type Attachment } from './transformers/attachment.js' import { transformAuditLogEntry, type AuditLogEntry } from './transformers/auditLogEntry.js' diff --git a/packages/bot/src/transformers/reverse/applicationCommandOptionChoice.ts b/packages/bot/src/transformers/reverse/applicationCommandOptionChoice.ts index f734f120b..6931f231e 100644 --- a/packages/bot/src/transformers/reverse/applicationCommandOptionChoice.ts +++ b/packages/bot/src/transformers/reverse/applicationCommandOptionChoice.ts @@ -1,9 +1,9 @@ -import type { Bot, DiscordApplicationCommandOptionChoice } from '../../index.js' +import type { Bot, Camelize, DiscordApplicationCommandOptionChoice } from '../../index.js' import type { ApplicationCommandOptionChoice } from '../applicationCommandOptionChoice.js' export function transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice( bot: Bot, - payload: ApplicationCommandOptionChoice, + payload: ApplicationCommandOptionChoice | Camelize, ): DiscordApplicationCommandOptionChoice { return { name: payload.name, diff --git a/packages/bot/src/transformers/reverse/createApplicationCommand.ts b/packages/bot/src/transformers/reverse/createApplicationCommand.ts index 7a126e64c..2fe7c06bc 100644 --- a/packages/bot/src/transformers/reverse/createApplicationCommand.ts +++ b/packages/bot/src/transformers/reverse/createApplicationCommand.ts @@ -1,5 +1,5 @@ import { calculateBits } from '@discordeno/utils' -import type { Bot, CreateApplicationCommand, DiscordCreateApplicationCommand } from '../../index.js' +import type { ApplicationCommandOption, Bot, CreateApplicationCommand, DiscordCreateApplicationCommand } from '../../index.js' import { isContextApplicationCommand } from '../../typings.js' export function transformCreateApplicationCommandToDiscordCreateApplicationCommand( @@ -24,7 +24,7 @@ export function transformCreateApplicationCommandToDiscordCreateApplicationComma description: payload.description, description_localizations: payload.descriptionLocalizations, type: payload.type, - options: payload.options?.map((option) => bot.transformers.reverse.applicationCommandOption(bot, option)), + options: payload.options?.map((option) => bot.transformers.reverse.applicationCommandOption(bot, option as unknown as ApplicationCommandOption)), default_member_permissions: payload.defaultMemberPermissions ? calculateBits(payload.defaultMemberPermissions) : null, dm_permission: payload.dmPermission, } diff --git a/packages/bot/src/typings.ts b/packages/bot/src/typings.ts index 4196c88bf..5582e9af4 100644 --- a/packages/bot/src/typings.ts +++ b/packages/bot/src/typings.ts @@ -1,7 +1,6 @@ import { ApplicationCommandTypes, type AllowedMentions, - type ApplicationCommandOptionChoice, type ButtonStyles, type CreateApplicationCommand, type CreateContextApplicationCommand, @@ -23,6 +22,7 @@ import { } from '@discordeno/types' import type * as handlers from './handlers/index.js' import type { Embed } from './transformers/embed.js' +import type { ApplicationCommandOptionChoice } from './transformers/applicationCommandOptionChoice.js' export function isContextApplicationCommand(command: CreateApplicationCommand): command is CreateContextApplicationCommand { return command.type === ApplicationCommandTypes.Message || command.type === ApplicationCommandTypes.User diff --git a/packages/types/src/discordeno.ts b/packages/types/src/discordeno.ts index c9f49c458..2321847d9 100644 --- a/packages/types/src/discordeno.ts +++ b/packages/types/src/discordeno.ts @@ -2,6 +2,8 @@ import type { AutoModerationActionType, AutoModerationEventTypes, AutoModerationTriggerTypes, + DiscordApplicationCommandOption, + DiscordApplicationCommandOptionChoice, DiscordAttachment, DiscordAutoModerationRuleTriggerMetadataPresets, DiscordChannel, @@ -10,7 +12,6 @@ import type { } from './discord.js' import type { AllowedMentionsTypes, - ApplicationCommandOptionTypes, ApplicationCommandPermissionTypes, ApplicationCommandTypes, AuditLogEvents, @@ -401,7 +402,7 @@ export interface CreateSlashApplicationCommand { /** Type of command, defaults `ApplicationCommandTypes.ChatInput` if not set */ type?: ApplicationCommandTypes /** Parameters for the command */ - options?: ApplicationCommandOption[] + options?: Camelize /** Set of permissions represented as a bit set */ defaultMemberPermissions?: PermissionStrings[] /** Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible. */ @@ -437,14 +438,7 @@ export interface InteractionCallbackData { /** Message flags combined as a bit field (only SUPPRESS_EMBEDS and EPHEMERAL can be set) */ flags?: number /** Autocomplete choices (max of 25 choices) */ - choices?: ApplicationCommandOptionChoice[] -} - -export interface ApplicationCommandOptionChoice { - /** The name of the choice */ - name: string - /** The value that this choice was represents. */ - value: string | number + choices?: Camelize } /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */ @@ -455,37 +449,6 @@ export interface InteractionResponse { data?: InteractionCallbackData } -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 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 - /** Minimum length desired. */ - minLength?: number - /** Maximum length desired. */ - maxLength?: number - /** if autocomplete interactions are enabled for this `String`, `Integer`, or `Number` type option */ - autocomplete?: boolean -} - /** https://discord.com/developers/docs/resources/emoji#create-guild-emoji */ export interface CreateGuildEmoji { /** Name of the emoji */