Skip to content

Commit

Permalink
chore: make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Apr 9, 2022
1 parent 2d025a3 commit 0a330f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import is from '@sindresorhus/is';
import { type APIApplicationCommandOptionChoice, Locale, type LocaleString } from 'discord-api-types/v10';
import { type APIApplicationCommandOptionChoice, Locale } from 'discord-api-types/v10';
import { s } from '@sapphire/shapeshift';
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
Expand All @@ -22,8 +22,8 @@ export function validateDescription(description: unknown): asserts description i
}

const maxArrayLengthPredicate = s.unknown.array.lengthLe(25);
export function validateLocale(locale: unknown): asserts locale is LocaleString {
localePredicate.parse(locale);
export function validateLocale(locale: unknown) {
return localePredicate.parse(locale);
}

export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
APIApplicationCommandOption,
LocaleString,
LocalizationMap,
RESTPostAPIApplicationCommandsJSONBody,
} from 'discord-api-types/v10';
import { mix } from 'ts-mixer';
Expand All @@ -24,7 +24,7 @@ export class SlashCommandBuilder {
/**
* The localized names for this command
*/
public readonly name_localizations?: Partial<Record<LocaleString, string>> = undefined;
public readonly name_localizations?: LocalizationMap;

/**
* The description of this slash command
Expand All @@ -34,7 +34,7 @@ export class SlashCommandBuilder {
/**
* The localized descriptions for this command
*/
public readonly description_localizations?: Partial<Record<LocaleString, string>> = undefined;
public readonly description_localizations?: LocalizationMap;

/**
* The options of this slash command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ export class SharedNameAndDescription {
Reflect.set(this, 'name_localizations', {});
}

validateLocale(locale);

if (localizedName === null) {
this.name_localizations![locale] = null;
return this;
}

validateName(localizedName);

this.name_localizations![locale] = localizedName;
this.name_localizations![validateLocale(locale)] = localizedName;
return this;
}

Expand Down Expand Up @@ -87,16 +85,14 @@ export class SharedNameAndDescription {
Reflect.set(this, 'description_localizations', {});
}

validateLocale(locale);

if (localizedDescription === null) {
this.description_localizations![locale] = null;
return this;
}

validateDescription(localizedDescription);

this.description_localizations![locale] = localizedDescription;
this.description_localizations![validateLocale(locale)] = localizedDescription;
return this;
}

Expand Down

0 comments on commit 0a330f6

Please sign in to comment.