From a4d694738fd1f33f3c3091aede2e76e76d94c59f Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Sat, 26 Feb 2022 21:02:33 +0300 Subject: [PATCH] feat: min and max constraints for slash command options (#1026) * feat: min and max constraints for slash command options * fix: typo * feat: changed slash command options min-max values to float * feat: improved min max constraints * feat: removed helper functions * fix(examples): helper functions * feat(components): made MaxValues int in SelectMenu * fix(examples/components): MaxValues * feat(interactions#ApplicationCommandOption): removed pointer from MaxValue * feat(examples): removed helper functions for MinValue and MinValues * fix(examples): removed newOptionalInt --- components.go | 2 +- examples/components/main.go | 3 ++- examples/slash_commands/main.go | 4 ++++ interactions.go | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/components.go b/components.go index 2ebbdec..00cbbf1 100644 --- a/components.go +++ b/components.go @@ -175,7 +175,7 @@ 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"` diff --git a/examples/components/main.go b/examples/components/main.go index 2e80c64..d3c20f7 100644 --- a/examples/components/main.go +++ b/examples/components/main.go @@ -314,6 +314,7 @@ var ( }, } case "multi": + minValues := 1 response = &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ @@ -328,7 +329,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: 1, + MinValues: &minValues, MaxValues: 3, Options: []discordgo.SelectMenuOption{ { diff --git a/examples/slash_commands/main.go b/examples/slash_commands/main.go index 69dcd83..3d49477 100644 --- a/examples/slash_commands/main.go +++ b/examples/slash_commands/main.go @@ -32,6 +32,8 @@ func init() { } var ( + integerOptionMinValue = 1.0 + commands = []*discordgo.ApplicationCommand{ { Name: "basic-command", @@ -59,6 +61,8 @@ var ( Type: discordgo.ApplicationCommandOptionInteger, Name: "integer-option", Description: "Integer option", + MinValue: &integerOptionMinValue, + MaxValue: 10, Required: true, }, { diff --git a/interactions.go b/interactions.go index 9ce3d48..b263291 100644 --- a/interactions.go +++ b/interactions.go @@ -94,6 +94,7 @@ 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"` + ChannelTypes []ChannelType `json:"channel_types"` Required bool `json:"required"` Options []*ApplicationCommandOption `json:"options"` @@ -101,6 +102,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"` + // Maximum value of number/integer option. + MaxValue float64 `json:"max_value,omitempty"` } // ApplicationCommandOptionChoice represents a slash command option choice.