fix: Interaction.locale was poorly implemented

This commit is contained in:
Yuzu 2022-08-29 19:24:19 -05:00
parent 116666c99c
commit 9d4b543c8b

View File

@ -79,7 +79,10 @@ export abstract class BaseInteraction implements Model {
this.channelId = data.channel_id;
this.applicationId = data.application_id;
this.version = data.version;
this.locale = data.locale;
Object.defineProperty(this, "locale", {
value: data.locale,
});
const perms = data.app_permissions;
@ -113,11 +116,10 @@ export abstract class BaseInteraction implements Model {
member?: Member;
appPermissions?: Permissions;
/**
* @virtual
*/
locale?: string;
// must be implemented
abstract locale?: string;
// readonly property according to docs
readonly version: 1;
responded = false;
@ -335,10 +337,10 @@ 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!;
this.options = new InteractionOptions(
data.data!.options ?? []
);
this.locale = data.locale;
}
override type: InteractionTypes.ApplicationCommandAutocomplete;
@ -346,8 +348,8 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
commandName: string;
commandType: ApplicationCommandTypes;
commandGuildId?: Snowflake;
override locale: string;
options: InteractionOptions;
override locale?: string;
async respondWithChoices(
choices: ApplicationCommandOptionChoice[]
@ -434,7 +436,7 @@ export class CommandInteraction extends BaseInteraction implements Model {
}
}
this.locale = super.locale!;
this.locale = data.locale;
}
override type: InteractionTypes.ApplicationCommand;
@ -444,7 +446,7 @@ export class CommandInteraction extends BaseInteraction implements Model {
commandGuildId?: Snowflake;
resolved: CommandInteractionDataResolved;
options: InteractionOptions;
override locale: string;
override locale?: string;
}
export type ModalInMessage = ModalSubmitInteraction & {
@ -468,7 +470,7 @@ export class ModalSubmitInteraction extends BaseInteraction implements Model {
this.message = new Message(session, data.message);
}
this.locale = super.locale!;
this.locale = data.locale;
}
override type: InteractionTypes.MessageComponent;
@ -478,7 +480,7 @@ export class ModalSubmitInteraction extends BaseInteraction implements Model {
values?: string[];
message?: Message;
components;
override locale: string;
override locale?: string;
static transformComponent(component: DiscordMessageComponents[number]) {
return {
@ -506,7 +508,6 @@ 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;
@ -514,7 +515,7 @@ export class PingInteraction extends BaseInteraction implements Model {
commandName: string;
commandType: ApplicationCommandTypes;
commandGuildId?: Snowflake;
override locale: undefined;
override locale = undefined as never;
async pong(): Promise<void> {
await this.session.rest.post<undefined>(
@ -535,7 +536,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!;
this.locale = data.locale;
}
override type: InteractionTypes.MessageComponent;
@ -544,7 +545,7 @@ export class ComponentInteraction extends BaseInteraction implements Model {
targetId?: Snowflake;
values?: string[];
message: Message;
override locale: string;
override locale?: string;
isButton(): boolean {
return this.componentType === MessageComponentTypes.Button;