diff --git a/lib/command_chat.go b/lib/command_chat.go index 3080995..f3a2073 100644 --- a/lib/command_chat.go +++ b/lib/command_chat.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "slices" + "unicode/utf8" "github.com/bwmarrin/discordgo" ) @@ -219,6 +220,24 @@ func (o *ChatCommandIntegerOption) ApplicationCommandOption() *discordgo.Applica } func (o *ChatCommandIntegerOption) Validate() (bool, error) { + for _, c := range o.Choices { + if c.Value < o.MinValue { + return false, fmt.Errorf( + "Choice %q has value (%v) smaller than allowed by property \"MinValue\" (%v)", + c.Name, + c.Value, + o.MinValue, + ) + } else if c.Value > o.MaxValue { + return false, fmt.Errorf( + "Choice %q has value (%v) bigger than allowed by property \"MaxValue\" (%v)", + c.Name, + c.Value, + o.MaxValue, + ) + } + } + return validateOption(o) } @@ -303,6 +322,24 @@ func (o *ChatCommandNumberOption) ApplicationCommandOption() *discordgo.Applicat } func (o *ChatCommandNumberOption) Validate() (bool, error) { + for _, c := range o.Choices { + if c.Value < o.MinValue { + return false, fmt.Errorf( + "Choice %q has value (%v) smaller than allowed by property \"MinValue\" (%v)", + c.Name, + c.Value, + o.MinValue, + ) + } else if c.Value > o.MaxValue { + return false, fmt.Errorf( + "Choice %q has value (%v) bigger than allowed by property \"MaxValue\" (%v)", + c.Name, + c.Value, + o.MaxValue, + ) + } + } + return validateOption(o) } @@ -397,6 +434,27 @@ func (o *ChatCommandStringOption) Validate() (bool, error) { ) } + for _, c := range o.Choices { + l := utf8.RuneCountInString(c.Value) + if l < o.MinLength { + return false, fmt.Errorf( + "Choice %q has value (%q) with length (%v) smaller than allowed by \"MinLength\" property (%v)", + c.Name, + l, + c.Value, + o.MinLength, + ) + } else if l > o.MaxLength { + return false, fmt.Errorf( + "Choice %q has value (%q) with length (%v) bigger than allowed by \"MaxLength\" property (%v)", + c.Name, + l, + c.Value, + o.MaxLength, + ) + } + } + return validateOption(o) }