Skip to content

Commit

Permalink
feat: add max/min option for number-based options (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Nov 2, 2021
1 parent 0f51d8e commit bc1d03e
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 30 deletions.
59 changes: 52 additions & 7 deletions deno/payloads/v8/_interactions/_applicationCommands/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ interface APIApplicationCommandOptionBase {
* https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
*/
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandStringArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase
| APIApplicationCommandChannelOptions
| APIApplicationCommandAutocompleteOptions;
| APIApplicationCommandOptionBase
| APIApplicationCommandNumberArgumentOptions
| APIApplicationCommandStringAutocompleteOptions
| APIApplicationCommandNumericAutocompleteOptions;

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
Expand All @@ -48,6 +51,31 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices` one
*/
export interface APIApplicationCommandStringArgumentOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
type: ApplicationCommandOptionType.String;
choices?: APIApplicationCommandOptionChoice[];
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices`, a `min_value` and `max_value` field
*/
export interface APIApplicationCommandNumberArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
choices?: APIApplicationCommandOptionChoice[];
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* if the option is an `INTEGER` or `NUMBER` type, the maximum value permitted
*/
max_value?: number;
autocomplete?: false;
}
export interface APIApplicationCommandArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
Expand All @@ -64,13 +92,30 @@ export interface APIApplicationCommandArgumentOptions
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandAutocompleteOptions
export interface APIApplicationCommandStringAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
type: ApplicationCommandOptionType.String;
autocomplete: true;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandNumericAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
autocomplete: true;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
max_value?: number;
}

/**
Expand Down
57 changes: 49 additions & 8 deletions deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ interface APIApplicationCommandOptionBase {
* https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
*/
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandStringArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase
| APIApplicationCommandChannelOptions
| APIApplicationCommandAutocompleteOptions;
| APIApplicationCommandOptionBase
| APIApplicationCommandNumberArgumentOptions
| APIApplicationCommandStringAutocompleteOptions
| APIApplicationCommandNumericAutocompleteOptions;

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
Expand All @@ -48,7 +51,7 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a either a `choices` or a `autocomplete` field where it's set to false.
*/
export interface APIApplicationCommandArgumentOptions
export interface APIApplicationCommandStringArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
Expand All @@ -64,15 +67,53 @@ export interface APIApplicationCommandArgumentOptions
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandAutocompleteOptions
export interface APIApplicationCommandStringAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
type: ApplicationCommandOptionType.String;
autocomplete: true;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandNumericAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
autocomplete: true;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
max_value?: number;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices`, a `min_value` and `max_value` field
*/
export interface APIApplicationCommandNumberArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
choices?: APIApplicationCommandOptionChoice[];
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* if the option is an `INTEGER` or `NUMBER` type, the maximum value permitted
*/
max_value?: number;
autocomplete?: false;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
Expand Down
59 changes: 52 additions & 7 deletions payloads/v8/_interactions/_applicationCommands/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ interface APIApplicationCommandOptionBase {
* https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
*/
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandStringArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase
| APIApplicationCommandChannelOptions
| APIApplicationCommandAutocompleteOptions;
| APIApplicationCommandOptionBase
| APIApplicationCommandNumberArgumentOptions
| APIApplicationCommandStringAutocompleteOptions
| APIApplicationCommandNumericAutocompleteOptions;

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
Expand All @@ -48,6 +51,31 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices` one
*/
export interface APIApplicationCommandStringArgumentOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
type: ApplicationCommandOptionType.String;
choices?: APIApplicationCommandOptionChoice[];
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices`, a `min_value` and `max_value` field
*/
export interface APIApplicationCommandNumberArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
choices?: APIApplicationCommandOptionChoice[];
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* if the option is an `INTEGER` or `NUMBER` type, the maximum value permitted
*/
max_value?: number;
autocomplete?: false;
}
export interface APIApplicationCommandArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
Expand All @@ -64,13 +92,30 @@ export interface APIApplicationCommandArgumentOptions
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandAutocompleteOptions
export interface APIApplicationCommandStringAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
type: ApplicationCommandOptionType.String;
autocomplete: true;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandNumericAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
autocomplete: true;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
max_value?: number;
}

/**
Expand Down
57 changes: 49 additions & 8 deletions payloads/v9/_interactions/_applicationCommands/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ interface APIApplicationCommandOptionBase {
* https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
*/
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandStringArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase
| APIApplicationCommandChannelOptions
| APIApplicationCommandAutocompleteOptions;
| APIApplicationCommandOptionBase
| APIApplicationCommandNumberArgumentOptions
| APIApplicationCommandStringAutocompleteOptions
| APIApplicationCommandNumericAutocompleteOptions;

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
Expand All @@ -48,7 +51,7 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a either a `choices` or a `autocomplete` field where it's set to false.
*/
export interface APIApplicationCommandArgumentOptions
export interface APIApplicationCommandStringArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
Expand All @@ -64,15 +67,53 @@ export interface APIApplicationCommandArgumentOptions
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandAutocompleteOptions
export interface APIApplicationCommandStringAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
type: ApplicationCommandOptionType.String;
autocomplete: true;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandNumericAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
autocomplete: true;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
max_value?: number;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices`, a `min_value` and `max_value` field
*/
export interface APIApplicationCommandNumberArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type: ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
choices?: APIApplicationCommandOptionChoice[];
/**
* If the option is an `INTEGER` or `NUMBER` type, the minimum value permitted.
*/
min_value?: number;
/**
* if the option is an `INTEGER` or `NUMBER` type, the maximum value permitted
*/
max_value?: number;
autocomplete?: false;
}

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
Expand Down

0 comments on commit bc1d03e

Please sign in to comment.