Skip to content

Commit

Permalink
refactor: use Locale only (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite authored Nov 12, 2024
1 parent 092cf01 commit f698404
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 28 deletions.
4 changes: 2 additions & 2 deletions deno/payloads/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LocaleString } from '../rest/common.ts';
import type { Locale } from '../rest/common.ts';

/**
* https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags
Expand Down Expand Up @@ -297,7 +297,7 @@ export const PermissionFlagsBits = {
*/
Object.freeze(PermissionFlagsBits);

export type LocalizationMap = Partial<Record<LocaleString, string | null>>;
export type LocalizationMap = Partial<Record<Locale, string | null>>;

/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#json
Expand Down
6 changes: 3 additions & 3 deletions deno/payloads/v10/_interactions/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Permissions, Snowflake } from '../../../globals.ts';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../../v10.ts';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, Locale } from '../../../v10.ts';
import type {
APIAttachment,
APIChannel,
Expand Down Expand Up @@ -160,11 +160,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* The selected language of the invoking user
*/
locale: LocaleString;
locale: Locale;
/**
* The guild's preferred locale, if invoked in a guild
*/
guild_locale?: LocaleString;
guild_locale?: Locale;
/**
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
*/
Expand Down
3 changes: 2 additions & 1 deletion deno/payloads/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Permissions, Snowflake } from '../../globals.ts';
import type { Locale } from '../../rest/common.ts';
import type { APIEmoji, APIPartialEmoji } from './emoji.ts';
import type { PresenceUpdateReceiveStatus } from './gateway.ts';
import type { OAuth2Scopes } from './oauth2.ts';
Expand Down Expand Up @@ -227,7 +228,7 @@ export interface APIGuild extends APIPartialGuild {
*
* @default "en-US"
*/
preferred_locale: string;
preferred_locale: Locale;
/**
* The id of the channel where admins and moderators of Community guilds receive notices from Discord
*/
Expand Down
3 changes: 2 additions & 1 deletion deno/payloads/v10/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Snowflake } from '../../globals.ts';
import type { Locale } from '../../rest/common.ts';
import type { RESTPostAPIGuildsJSONBody } from '../../rest/v10/mod.ts';
import type { APIUser } from './user.ts';

Expand Down Expand Up @@ -60,6 +61,6 @@ export interface APITemplate {

export interface APITemplateSerializedSourceGuild extends Omit<RESTPostAPIGuildsJSONBody, 'icon'> {
description: string | null;
preferred_locale: string;
preferred_locale: Locale;
icon_hash: string | null;
}
6 changes: 3 additions & 3 deletions deno/payloads/v9/_interactions/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Permissions, Snowflake } from '../../../globals.ts';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../../v9.ts';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, Locale } from '../../../v9.ts';
import type {
APIAttachment,
APIChannel,
Expand Down Expand Up @@ -160,11 +160,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* The selected language of the invoking user
*/
locale: LocaleString;
locale: Locale;
/**
* The guild's preferred locale, if invoked in a guild
*/
guild_locale?: LocaleString;
guild_locale?: Locale;
/**
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
*/
Expand Down
3 changes: 2 additions & 1 deletion deno/payloads/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Permissions, Snowflake } from '../../globals.ts';
import type { Locale } from '../../rest/common.ts';
import type { APIEmoji, APIPartialEmoji } from './emoji.ts';
import type { PresenceUpdateReceiveStatus } from './gateway.ts';
import type { OAuth2Scopes } from './oauth2.ts';
Expand Down Expand Up @@ -227,7 +228,7 @@ export interface APIGuild extends APIPartialGuild {
*
* @default "en-US"
*/
preferred_locale: string;
preferred_locale: Locale;
/**
* The id of the channel where admins and moderators of Community guilds receive notices from Discord
*/
Expand Down
3 changes: 2 additions & 1 deletion deno/payloads/v9/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Snowflake } from '../../globals.ts';
import type { Locale } from '../../rest/common.ts';
import type { RESTPostAPIGuildsJSONBody } from '../../rest/v9/mod.ts';
import type { APIUser } from './user.ts';

Expand Down Expand Up @@ -60,6 +61,6 @@ export interface APITemplate {

export interface APITemplateSerializedSourceGuild extends Omit<RESTPostAPIGuildsJSONBody, 'icon'> {
description: string | null;
preferred_locale: string;
preferred_locale: Locale;
icon_hash: string | null;
}
3 changes: 3 additions & 0 deletions deno/rest/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,7 @@ export enum Locale {
Vietnamese = 'vi',
}

/**
* @deprecated Use {@apilink Locale} instead.
*/
export type LocaleString = `${Locale}`;
3 changes: 2 additions & 1 deletion deno/rest/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
StrictPartial,
StrictRequired,
} from '../../utils/internals.ts';
import type { Locale } from '../common.ts';
import type { RESTPutAPIChannelPermissionJSONBody } from './channel.ts';

export interface RESTAPIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand Down Expand Up @@ -315,7 +316,7 @@ export interface RESTPatchAPIGuildJSONBody {
*
* @default "en-US" (if the value is set to `null`)
*/
preferred_locale?: string | null | undefined;
preferred_locale?: Locale | null | undefined;
/**
* Enabled guild features
*
Expand Down
3 changes: 2 additions & 1 deletion deno/rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
StrictPartial,
StrictRequired,
} from '../../utils/internals.ts';
import type { Locale } from '../common.ts';
import type { RESTPutAPIChannelPermissionJSONBody } from './channel.ts';

export interface RESTAPIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand Down Expand Up @@ -315,7 +316,7 @@ export interface RESTPatchAPIGuildJSONBody {
*
* @default "en-US" (if the value is set to `null`)
*/
preferred_locale?: string | null | undefined;
preferred_locale?: Locale | null | undefined;
/**
* Enabled guild features
*
Expand Down
4 changes: 2 additions & 2 deletions payloads/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LocaleString } from '../rest/common';
import type { Locale } from '../rest/common';

/**
* https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags
Expand Down Expand Up @@ -297,7 +297,7 @@ export const PermissionFlagsBits = {
*/
Object.freeze(PermissionFlagsBits);

export type LocalizationMap = Partial<Record<LocaleString, string | null>>;
export type LocalizationMap = Partial<Record<Locale, string | null>>;

/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#json
Expand Down
6 changes: 3 additions & 3 deletions payloads/v10/_interactions/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Permissions, Snowflake } from '../../../globals';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../../v10';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, Locale } from '../../../v10';
import type {
APIAttachment,
APIChannel,
Expand Down Expand Up @@ -160,11 +160,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* The selected language of the invoking user
*/
locale: LocaleString;
locale: Locale;
/**
* The guild's preferred locale, if invoked in a guild
*/
guild_locale?: LocaleString;
guild_locale?: Locale;
/**
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
*/
Expand Down
3 changes: 2 additions & 1 deletion payloads/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Permissions, Snowflake } from '../../globals';
import type { Locale } from '../../rest/common';
import type { APIEmoji, APIPartialEmoji } from './emoji';
import type { PresenceUpdateReceiveStatus } from './gateway';
import type { OAuth2Scopes } from './oauth2';
Expand Down Expand Up @@ -227,7 +228,7 @@ export interface APIGuild extends APIPartialGuild {
*
* @default "en-US"
*/
preferred_locale: string;
preferred_locale: Locale;
/**
* The id of the channel where admins and moderators of Community guilds receive notices from Discord
*/
Expand Down
3 changes: 2 additions & 1 deletion payloads/v10/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Snowflake } from '../../globals';
import type { Locale } from '../../rest/common';
import type { RESTPostAPIGuildsJSONBody } from '../../rest/v10/index';
import type { APIUser } from './user';

Expand Down Expand Up @@ -60,6 +61,6 @@ export interface APITemplate {

export interface APITemplateSerializedSourceGuild extends Omit<RESTPostAPIGuildsJSONBody, 'icon'> {
description: string | null;
preferred_locale: string;
preferred_locale: Locale;
icon_hash: string | null;
}
6 changes: 3 additions & 3 deletions payloads/v9/_interactions/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Permissions, Snowflake } from '../../../globals';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../../v9';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, Locale } from '../../../v9';
import type {
APIAttachment,
APIChannel,
Expand Down Expand Up @@ -160,11 +160,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* The selected language of the invoking user
*/
locale: LocaleString;
locale: Locale;
/**
* The guild's preferred locale, if invoked in a guild
*/
guild_locale?: LocaleString;
guild_locale?: Locale;
/**
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
*/
Expand Down
3 changes: 2 additions & 1 deletion payloads/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Permissions, Snowflake } from '../../globals';
import type { Locale } from '../../rest/common';
import type { APIEmoji, APIPartialEmoji } from './emoji';
import type { PresenceUpdateReceiveStatus } from './gateway';
import type { OAuth2Scopes } from './oauth2';
Expand Down Expand Up @@ -227,7 +228,7 @@ export interface APIGuild extends APIPartialGuild {
*
* @default "en-US"
*/
preferred_locale: string;
preferred_locale: Locale;
/**
* The id of the channel where admins and moderators of Community guilds receive notices from Discord
*/
Expand Down
3 changes: 2 additions & 1 deletion payloads/v9/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Snowflake } from '../../globals';
import type { Locale } from '../../rest/common';
import type { RESTPostAPIGuildsJSONBody } from '../../rest/v9/index';
import type { APIUser } from './user';

Expand Down Expand Up @@ -60,6 +61,6 @@ export interface APITemplate {

export interface APITemplateSerializedSourceGuild extends Omit<RESTPostAPIGuildsJSONBody, 'icon'> {
description: string | null;
preferred_locale: string;
preferred_locale: Locale;
icon_hash: string | null;
}
3 changes: 3 additions & 0 deletions rest/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,7 @@ export enum Locale {
Vietnamese = 'vi',
}

/**
* @deprecated Use {@apilink Locale} instead.
*/
export type LocaleString = `${Locale}`;
3 changes: 2 additions & 1 deletion rest/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
StrictPartial,
StrictRequired,
} from '../../utils/internals';
import type { Locale } from '../common';
import type { RESTPutAPIChannelPermissionJSONBody } from './channel';

export interface RESTAPIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand Down Expand Up @@ -315,7 +316,7 @@ export interface RESTPatchAPIGuildJSONBody {
*
* @default "en-US" (if the value is set to `null`)
*/
preferred_locale?: string | null | undefined;
preferred_locale?: Locale | null | undefined;
/**
* Enabled guild features
*
Expand Down
3 changes: 2 additions & 1 deletion rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
StrictPartial,
StrictRequired,
} from '../../utils/internals';
import type { Locale } from '../common';
import type { RESTPutAPIChannelPermissionJSONBody } from './channel';

export interface RESTAPIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand Down Expand Up @@ -315,7 +316,7 @@ export interface RESTPatchAPIGuildJSONBody {
*
* @default "en-US" (if the value is set to `null`)
*/
preferred_locale?: string | null | undefined;
preferred_locale?: Locale | null | undefined;
/**
* Enabled guild features
*
Expand Down

0 comments on commit f698404

Please sign in to comment.