From 02de7d6670e1aa2f0969ba89f8b87ad1fd19d393 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Fri, 5 Nov 2021 17:58:48 +0300 Subject: [PATCH 01/11] feat: min and max constraints for slash command options --- examples/slash_commands/main.go | 2 ++ interactions.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/slash_commands/main.go b/examples/slash_commands/main.go index 1cb3dead0..50c75dfa1 100644 --- a/examples/slash_commands/main.go +++ b/examples/slash_commands/main.go @@ -59,6 +59,8 @@ var ( Type: discordgo.ApplicationCommandOptionInteger, Name: "integer-option", Description: "Integer option", + MinValue: 1, + MaxValue: 10, Required: true, }, { diff --git a/interactions.go b/interactions.go index 06aca23d8..d352d55e0 100644 --- a/interactions.go +++ b/interactions.go @@ -89,10 +89,15 @@ type ApplicationCommandOption struct { // NOTE: This feature was on the API, but at some point developers decided to remove it. // So I commented it, until it will be officially on the docs. // Default bool `json:"default"` - Required bool `json:"required"` - Choices []*ApplicationCommandOptionChoice `json:"choices"` - Options []*ApplicationCommandOption `json:"options"` - ChannelTypes []ChannelType `json:"channel_types"` + Required bool `json:"required"` + Choices []*ApplicationCommandOptionChoice `json:"choices"` + Options []*ApplicationCommandOption `json:"options"` + + ChannelTypes []ChannelType `json:"channel_types"` + // Minimal value of number/integer option. + MinValue interface{} `json:"min_value,omitempty"` + // Maximum valeu of number/integer option. + MaxValue interface{} `json:"max_value,omitempty"` } // ApplicationCommandOptionChoice represents a slash command option choice. From 73c18a86d9bccdffaba02e7030672554b29570b2 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Fri, 5 Nov 2021 18:03:55 +0300 Subject: [PATCH 02/11] fix: typo --- interactions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions.go b/interactions.go index d352d55e0..33bb170db 100644 --- a/interactions.go +++ b/interactions.go @@ -96,7 +96,7 @@ type ApplicationCommandOption struct { ChannelTypes []ChannelType `json:"channel_types"` // Minimal value of number/integer option. MinValue interface{} `json:"min_value,omitempty"` - // Maximum valeu of number/integer option. + // Maximum value of number/integer option. MaxValue interface{} `json:"max_value,omitempty"` } From 945a56b9fb589f3446f24ddfcd14cc2ca39bfd1f Mon Sep 17 00:00:00 2001 From: nitroflap Date: Fri, 5 Nov 2021 18:15:13 +0300 Subject: [PATCH 03/11] feat: changed slash command options min-max values to float --- interactions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interactions.go b/interactions.go index 33bb170db..eb420a145 100644 --- a/interactions.go +++ b/interactions.go @@ -95,9 +95,9 @@ type ApplicationCommandOption struct { ChannelTypes []ChannelType `json:"channel_types"` // Minimal value of number/integer option. - MinValue interface{} `json:"min_value,omitempty"` + MinValue float64 `json:"min_value,omitempty"` // Maximum value of number/integer option. - MaxValue interface{} `json:"max_value,omitempty"` + MaxValue float64 `json:"max_value,omitempty"` } // ApplicationCommandOptionChoice represents a slash command option choice. From f592e168016a8d8d77beace3c1b5b4e211a2de16 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Thu, 16 Dec 2021 11:18:55 +0300 Subject: [PATCH 04/11] feat: improved min max constraints --- components.go | 4 ++-- examples/components/main.go | 4 ++-- examples/slash_commands/main.go | 4 ++-- interactions.go | 6 +++--- types.go | 10 ++++++++++ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/components.go b/components.go index 124e95e5c..ccdba4cc2 100644 --- a/components.go +++ b/components.go @@ -166,10 +166,10 @@ type SelectMenu struct { // The text which will be shown in the menu if there's no default options or all options was deselected and component was closed. Placeholder string `json:"placeholder"` // This value determines the minimal amount of selected items in the menu. - MinValues int `json:"min_values,omitempty"` + MinValues *int `json:"min_values,omitempty"` // This value determines the maximal amount of selected items in the menu. // If MaxValues or MinValues are greater than one then the user can select multiple items in the component. - MaxValues int `json:"max_values,omitempty"` + MaxValues *int `json:"max_values,omitempty"` Options []SelectMenuOption `json:"options"` } diff --git a/examples/components/main.go b/examples/components/main.go index 2e80c6411..f3011b1ec 100644 --- a/examples/components/main.go +++ b/examples/components/main.go @@ -328,8 +328,8 @@ var ( Placeholder: "Select tags to search on StackOverflow", // This is where confusion comes from. If you don't specify these things you will get single item select. // These fields control the minimum and maximum amount of selected items. - MinValues: 1, - MaxValues: 3, + MinValues: discordgo.NewOptionalInt(1), + MaxValues: discordgo.NewOptionalInt(3), Options: []discordgo.SelectMenuOption{ { Label: "Go", diff --git a/examples/slash_commands/main.go b/examples/slash_commands/main.go index 50c75dfa1..a3d7a7737 100644 --- a/examples/slash_commands/main.go +++ b/examples/slash_commands/main.go @@ -59,8 +59,8 @@ var ( Type: discordgo.ApplicationCommandOptionInteger, Name: "integer-option", Description: "Integer option", - MinValue: 1, - MaxValue: 10, + MinValue: discordgo.NewOptionalFloat(1), + MaxValue: discordgo.NewOptionalFloat(10), Required: true, }, { diff --git a/interactions.go b/interactions.go index 5e2ff76c4..55856cabb 100644 --- a/interactions.go +++ b/interactions.go @@ -97,10 +97,10 @@ type ApplicationCommandOption struct { // NOTE: mutually exclusive with Choices. Autocomplete bool `json:"autocomplete"` Choices []*ApplicationCommandOptionChoice `json:"choices"` - // Minimal value of number/integer option. - MinValue float64 `json:"min_value,omitempty"` + // Minimal value of number/integer option. + MinValue *float64 `json:"min_value,omitempty"` // Maximum value of number/integer option. - MaxValue float64 `json:"max_value,omitempty"` + MaxValue *float64 `json:"max_value,omitempty"` } // ApplicationCommandOptionChoice represents a slash command option choice. diff --git a/types.go b/types.go index c0ce01315..898bf3e69 100644 --- a/types.go +++ b/types.go @@ -55,3 +55,13 @@ func newRestError(req *http.Request, resp *http.Response, body []byte) *RESTErro func (r RESTError) Error() string { return "HTTP " + r.Response.Status + ", " + string(r.ResponseBody) } + +// NewOptionalInt is a helper function for constructing an optional (pointer) int value +func NewOptionalInt(v int) *int { + return &v +} + +// NewOptionalInt is a helper function for constructing an optional (pointer) float value +func NewOptionalFloat(v float64) *float64 { + return &v +} From c2f246d90ff16ddf33129258a127b5c74dff84f6 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Sat, 26 Feb 2022 01:52:05 +0300 Subject: [PATCH 05/11] feat: removed helper functions --- types.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/types.go b/types.go index 898bf3e69..c0ce01315 100644 --- a/types.go +++ b/types.go @@ -55,13 +55,3 @@ func newRestError(req *http.Request, resp *http.Response, body []byte) *RESTErro func (r RESTError) Error() string { return "HTTP " + r.Response.Status + ", " + string(r.ResponseBody) } - -// NewOptionalInt is a helper function for constructing an optional (pointer) int value -func NewOptionalInt(v int) *int { - return &v -} - -// NewOptionalInt is a helper function for constructing an optional (pointer) float value -func NewOptionalFloat(v float64) *float64 { - return &v -} From 1127ff82ecc6f52b0560de0a83641d0426e943e6 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Sat, 26 Feb 2022 01:54:17 +0300 Subject: [PATCH 06/11] fix(examples): helper functions --- examples/components/main.go | 8 ++++++-- examples/slash_commands/main.go | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/components/main.go b/examples/components/main.go index f3011b1ec..bf685d11b 100644 --- a/examples/components/main.go +++ b/examples/components/main.go @@ -31,6 +31,10 @@ func init() { } } +func newOptionalInt(v int) *int { + return &v +} + // Important note: call every command in order it's placed in the example. var ( @@ -328,8 +332,8 @@ var ( Placeholder: "Select tags to search on StackOverflow", // This is where confusion comes from. If you don't specify these things you will get single item select. // These fields control the minimum and maximum amount of selected items. - MinValues: discordgo.NewOptionalInt(1), - MaxValues: discordgo.NewOptionalInt(3), + MinValues: newOptionalInt(1), + MaxValues: newOptionalInt(3), Options: []discordgo.SelectMenuOption{ { Label: "Go", diff --git a/examples/slash_commands/main.go b/examples/slash_commands/main.go index a3d7a7737..6c951bfa9 100644 --- a/examples/slash_commands/main.go +++ b/examples/slash_commands/main.go @@ -31,6 +31,10 @@ func init() { } } +func newOptionalFloat(v float64) *float64 { + return &v +} + var ( commands = []*discordgo.ApplicationCommand{ { @@ -59,8 +63,8 @@ var ( Type: discordgo.ApplicationCommandOptionInteger, Name: "integer-option", Description: "Integer option", - MinValue: discordgo.NewOptionalFloat(1), - MaxValue: discordgo.NewOptionalFloat(10), + MinValue: newOptionalFloat(1), + MaxValue: newOptionalFloat(10), Required: true, }, { From ca6d46a0c1286a1741c21ef9b57f14557fdc37ca Mon Sep 17 00:00:00 2001 From: nitroflap Date: Sat, 26 Feb 2022 03:01:19 +0300 Subject: [PATCH 07/11] feat(components): made MaxValues int in SelectMenu --- components.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components.go b/components.go index ccdba4cc2..415e98c5b 100644 --- a/components.go +++ b/components.go @@ -169,7 +169,7 @@ type SelectMenu struct { MinValues *int `json:"min_values,omitempty"` // This value determines the maximal amount of selected items in the menu. // If MaxValues or MinValues are greater than one then the user can select multiple items in the component. - MaxValues *int `json:"max_values,omitempty"` + MaxValues int `json:"max_values,omitempty"` Options []SelectMenuOption `json:"options"` } From c408aedde5113ac67a9c9c2b658092c283d71f8d Mon Sep 17 00:00:00 2001 From: nitroflap Date: Sat, 26 Feb 2022 03:24:45 +0300 Subject: [PATCH 08/11] fix(examples/components): MaxValues --- examples/components/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/components/main.go b/examples/components/main.go index bf685d11b..6e159ebfb 100644 --- a/examples/components/main.go +++ b/examples/components/main.go @@ -333,7 +333,7 @@ var ( // This is where confusion comes from. If you don't specify these things you will get single item select. // These fields control the minimum and maximum amount of selected items. MinValues: newOptionalInt(1), - MaxValues: newOptionalInt(3), + MaxValues: 3, Options: []discordgo.SelectMenuOption{ { Label: "Go", From 914d6e96e581fcf87e5020e922bee7208a585809 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Sat, 26 Feb 2022 20:28:22 +0300 Subject: [PATCH 09/11] feat(interactions#ApplicationCommandOption): removed pointer from MaxValue --- interactions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions.go b/interactions.go index 55856cabb..153018cd7 100644 --- a/interactions.go +++ b/interactions.go @@ -100,7 +100,7 @@ type ApplicationCommandOption struct { // Minimal value of number/integer option. MinValue *float64 `json:"min_value,omitempty"` // Maximum value of number/integer option. - MaxValue *float64 `json:"max_value,omitempty"` + MaxValue float64 `json:"max_value,omitempty"` } // ApplicationCommandOptionChoice represents a slash command option choice. From 088035a3cb2cbf6647d9f69387688624eefd4cdd Mon Sep 17 00:00:00 2001 From: nitroflap Date: Sat, 26 Feb 2022 20:59:45 +0300 Subject: [PATCH 10/11] feat(examples): removed helper functions for MinValue and MinValues --- examples/components/main.go | 3 ++- examples/slash_commands/main.go | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/components/main.go b/examples/components/main.go index 6e159ebfb..170be2204 100644 --- a/examples/components/main.go +++ b/examples/components/main.go @@ -318,6 +318,7 @@ var ( }, } case "multi": + minValues := 1 response = &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ @@ -332,7 +333,7 @@ var ( Placeholder: "Select tags to search on StackOverflow", // This is where confusion comes from. If you don't specify these things you will get single item select. // These fields control the minimum and maximum amount of selected items. - MinValues: newOptionalInt(1), + MinValues: &minValues, MaxValues: 3, Options: []discordgo.SelectMenuOption{ { diff --git a/examples/slash_commands/main.go b/examples/slash_commands/main.go index 6c951bfa9..4e59a6077 100644 --- a/examples/slash_commands/main.go +++ b/examples/slash_commands/main.go @@ -31,11 +31,9 @@ func init() { } } -func newOptionalFloat(v float64) *float64 { - return &v -} - var ( + integerOptionMinValue = 1.0 + commands = []*discordgo.ApplicationCommand{ { Name: "basic-command", @@ -63,8 +61,8 @@ var ( Type: discordgo.ApplicationCommandOptionInteger, Name: "integer-option", Description: "Integer option", - MinValue: newOptionalFloat(1), - MaxValue: newOptionalFloat(10), + MinValue: &integerOptionMinValue, + MaxValue: 10, Required: true, }, { From 63d3163076fe3d40d4102f22a3e091ffb0028e61 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Sat, 26 Feb 2022 21:00:42 +0300 Subject: [PATCH 11/11] fix(examples): removed newOptionalInt --- examples/components/main.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/components/main.go b/examples/components/main.go index 170be2204..d3c20f7f9 100644 --- a/examples/components/main.go +++ b/examples/components/main.go @@ -31,10 +31,6 @@ func init() { } } -func newOptionalInt(v int) *int { - return &v -} - // Important note: call every command in order it's placed in the example. var (