refactor(lib,commands,options): create generic ChatCommandOptionChoice type

This commit is contained in:
Guz
2024-11-22 18:46:16 -03:00
parent 38709bb4bf
commit 84dad980a9

View File

@@ -152,17 +152,11 @@ type ChatCommandIntegerOption struct {
DescriptionLocalizations map[discordgo.Locale]string
Required bool
Autocomplete bool
Choices []*ChatCommandIntegerOptionChoice
Choices []*ChatCommandOptionChoice[int]
MinValue int
MaxValue int
}
type ChatCommandIntegerOptionChoice struct {
Name string
NameLocalizations map[discordgo.Locale]string
Value int
}
func (o *ChatCommandIntegerOption) ApplicationCommandOption() *discordgo.ApplicationCommandOption {
choices := make([]*discordgo.ApplicationCommandOptionChoice, len(o.Choices))
for i, v := range o.Choices {
@@ -243,17 +237,11 @@ type ChatCommandNumberOption struct {
DescriptionLocalizations map[discordgo.Locale]string
Required bool
Autocomplete bool
Choices []*ChatCommandNumberOptionChoice
Choices []*ChatCommandOptionChoice[float64]
MinValue float64
MaxValue float64
}
type ChatCommandNumberOptionChoice struct {
Name string
NameLocalizations map[discordgo.Locale]string
Value float64
}
func (o *ChatCommandNumberOption) ApplicationCommandOption() *discordgo.ApplicationCommandOption {
choices := make([]*discordgo.ApplicationCommandOptionChoice, len(o.Choices))
for i, v := range o.Choices {
@@ -332,17 +320,11 @@ type ChatCommandStringOption struct {
DescriptionLocalizations map[discordgo.Locale]string
Required bool
Autocomplete bool
Choices []*ChatCommandStringOptionChoice
Choices []*ChatCommandOptionChoice[string]
MinLength int
MaxLength int
}
type ChatCommandStringOptionChoice struct {
Name string
NameLocalizations map[discordgo.Locale]string
Value string
}
func (o *ChatCommandStringOption) ApplicationCommandOption() *discordgo.ApplicationCommandOption {
choices := make([]*discordgo.ApplicationCommandOptionChoice, len(o.Choices))
for i, v := range o.Choices {
@@ -445,3 +427,12 @@ func validateOption(opt interface {
return true, nil
}
type (
optionTypes interface{ string | int | float64 }
ChatCommandOptionChoice[T optionTypes] struct {
Name string
NameLocalizations map[discordgo.Locale]string
Value T
}
)