diff --git a/packages/api-types/src/v10/index.ts b/packages/api-types/src/v10/index.ts index 8e8ff90..60a8386 100644 --- a/packages/api-types/src/v10/index.ts +++ b/packages/api-types/src/v10/index.ts @@ -1309,10 +1309,12 @@ export interface DiscordInteraction { message?: DiscordMessage; /** the command data payload */ data?: DiscordInteractionData; - /** The selected language of the invoking user */ - locale?: string; /** The guild's preferred locale, if invoked in a guild */ guild_locale?: string; + /** Bitwise set of permissions the app or bot has within the channel the interaction was sent from */ + app_permissions?: string; + /** Selected language of the invoking user */ + locale?: string; } /** https://discord.com/developers/docs/resources/guild#guild-member-object */ diff --git a/packages/core/src/builders/slash/ApplicationCommandOption.ts b/packages/core/src/builders/slash/ApplicationCommandOption.ts index 293e11f..0637cfd 100644 --- a/packages/core/src/builders/slash/ApplicationCommandOption.ts +++ b/packages/core/src/builders/slash/ApplicationCommandOption.ts @@ -1,6 +1,10 @@ -import { ApplicationCommandOptionTypes, ChannelTypes, Localization } from '@biscuitland/api-types'; +import type { ChannelTypes, Localization, Locales } from '@biscuitland/api-types'; +import { ApplicationCommandOptionTypes } from '@biscuitland/api-types'; import { ApplicationCommandOptionChoice } from '../../structures/interactions'; + +export type Localizations = typeof Locales[keyof typeof Locales] & string; + export class ChoiceBuilder { name?: string; value?: string; @@ -31,7 +35,9 @@ export class OptionBuilder { autocomplete?: boolean; type?: ApplicationCommandOptionTypes; name?: string; + nameLocalization?: Record; description?: string; + descriptionLocalization?: Record; constructor(type?: ApplicationCommandOptionTypes, name?: string, description?: string) { this.type = type; @@ -43,12 +49,18 @@ export class OptionBuilder { return (this.type = type), this; } - setName(name: string): this { - return (this.name = name), this; + setName(name: string, localization?: Record): this { + this.name = name; + this.nameLocalization = localization; + + return this; } - setDescription(description: string): this { - return (this.description = description), this; + setDescription(description: string, localization?: Record): this { + this.description = description; + this.descriptionLocalization = localization; + + return this; } setRequired(required: boolean): this { @@ -65,7 +77,9 @@ export class OptionBuilder { const applicationCommandOption: ApplicationCommandOption = { type: this.type, name: this.name, + name_localizations: this.nameLocalization, description: this.description, + description_localizations: this.descriptionLocalization, required: this.required ? true : false, }; diff --git a/packages/core/src/structures/interactions.ts b/packages/core/src/structures/interactions.ts index 0e87f64..bc81014 100644 --- a/packages/core/src/structures/interactions.ts +++ b/packages/core/src/structures/interactions.ts @@ -79,9 +79,9 @@ export abstract class BaseInteraction implements Model { this.channelId = data.channel_id; this.applicationId = data.application_id; this.version = data.version; + this.locale = data.locale; - // @ts-expect-error: vendor error - const perms = data.app_permissions as string; + const perms = data.app_permissions; if (perms) { this.appPermissions = new Permissions(BigInt(perms)); @@ -106,6 +106,11 @@ export abstract class BaseInteraction implements Model { member?: Member; appPermissions?: Permissions; + /** + * @virtual + */ + locale?: string; + readonly version: 1; responded = false; @@ -323,6 +328,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model { this.commandName = data.data!.name; this.commandType = data.data!.type; this.commandGuildId = data.data!.guild_id; + this.locale = super.locale!; } override type: InteractionTypes.ApplicationCommandAutocomplete; @@ -330,6 +336,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model { commandName: string; commandType: ApplicationCommandTypes; commandGuildId?: Snowflake; + override locale: string; async respondWithChoices( choices: ApplicationCommandOptionChoice[] @@ -415,6 +422,8 @@ export class CommandInteraction extends BaseInteraction implements Model { this.resolved.messages.set(id, new Message(session, m)); } } + + this.locale = super.locale!; } override type: InteractionTypes.ApplicationCommand; @@ -424,6 +433,7 @@ export class CommandInteraction extends BaseInteraction implements Model { commandGuildId?: Snowflake; resolved: CommandInteractionDataResolved; options: CommandInteractionOptionResolver; + override locale: string; } export type ModalInMessage = ModalSubmitInteraction & { @@ -446,6 +456,8 @@ export class ModalSubmitInteraction extends BaseInteraction implements Model { if (data.message) { this.message = new Message(session, data.message); } + + this.locale = super.locale!; } override type: InteractionTypes.MessageComponent; @@ -455,6 +467,7 @@ export class ModalSubmitInteraction extends BaseInteraction implements Model { values?: string[]; message?: Message; components; + override locale: string; static transformComponent(component: DiscordMessageComponents[number]) { return { @@ -482,6 +495,7 @@ export class PingInteraction extends BaseInteraction implements Model { this.commandName = data.data!.name; this.commandType = data.data!.type; this.commandGuildId = data.data!.guild_id; + this.locale = super.locale as undefined; } override type: InteractionTypes.Ping; @@ -489,6 +503,7 @@ export class PingInteraction extends BaseInteraction implements Model { commandName: string; commandType: ApplicationCommandTypes; commandGuildId?: Snowflake; + override locale: undefined; async pong(): Promise { await this.session.rest.post( @@ -509,6 +524,7 @@ export class ComponentInteraction extends BaseInteraction implements Model { this.targetId = data.data!.target_id; this.values = data.data!.values; this.message = new Message(session, data.message!); + this.locale = super.locale!; } override type: InteractionTypes.MessageComponent; @@ -517,6 +533,7 @@ export class ComponentInteraction extends BaseInteraction implements Model { targetId?: Snowflake; values?: string[]; message: Message; + override locale: string; isButton(): boolean { return this.componentType === MessageComponentTypes.Button;