Skip to content

Commit

Permalink
feat: add Locales to Interactions (#7131)
Browse files Browse the repository at this point in the history
Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com>
  • Loading branch information
2 people authored and iCrawl committed Jan 13, 2022
1 parent ac8c122 commit 233084a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/structures/Interaction.js
Expand Up @@ -74,6 +74,18 @@ class Interaction extends Base {
* @type {?Readonly<Permissions>}
*/
this.memberPermissions = data.member?.permissions ? new Permissions(data.member.permissions).freeze() : null;

/**
* The locale of the user who invoked this interaction
* @type {string}
*/
this.locale = data.locale;

/**
* The preferred locale from the guild this interaction was sent in
* @type {?string}
*/
this.guildLocale = data.guild_locale ?? null;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions typings/index.d.ts
Expand Up @@ -469,10 +469,9 @@ export type KeyedEnum<K, T> = {
[Key in keyof K]: T | string;
};

export type EnumValueMapped<E extends KeyedEnum<T, number>, T extends Partial<Record<keyof E, unknown>>> = T &
{
[Key in keyof T as E[Key]]: T[Key];
};
export type EnumValueMapped<E extends KeyedEnum<T, number>, T extends Partial<Record<keyof E, unknown>>> = T & {
[Key in keyof T as E[Key]]: T[Key];
};

export type MappedChannelCategoryTypes = EnumValueMapped<
typeof ChannelTypes,
Expand Down Expand Up @@ -1330,6 +1329,8 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
public user: User;
public version: number;
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
public locale: string;
public guildLocale: CacheTypeReducer<Cached, string, string, string>;
public inGuild(): this is Interaction<'present'>;
public inCachedGuild(): this is Interaction<'cached'>;
public inRawGuild(): this is Interaction<'raw'>;
Expand Down
5 changes: 5 additions & 0 deletions typings/index.test-d.ts
Expand Up @@ -949,12 +949,17 @@ client.on('interactionCreate', async interaction => {
expectAssignable<GuildMember>(interaction.member);
expectNotType<CommandInteraction<'cached'>>(interaction);
expectAssignable<Interaction>(interaction);
expectType<string>(interaction.guildLocale);
} else if (interaction.inRawGuild()) {
expectAssignable<APIInteractionGuildMember>(interaction.member);
expectNotAssignable<Interaction<'cached'>>(interaction);
expectType<string>(interaction.guildLocale);
} else if (interaction.inGuild()) {
expectType<string>(interaction.guildLocale);
} else {
expectType<APIInteractionGuildMember | GuildMember | null>(interaction.member);
expectNotAssignable<Interaction<'cached'>>(interaction);
expectType<string | null>(interaction.guildId);
}

if (interaction.isContextMenu()) {
Expand Down

0 comments on commit 233084a

Please sign in to comment.