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