feat(lib,commands,context): add Value of options for ChatCommandContext
This commit is contained in:
@@ -27,6 +27,67 @@ type Context struct {
|
||||
|
||||
type ChatCommandContext struct {
|
||||
Context
|
||||
Options ChatCommandContextOptions
|
||||
}
|
||||
|
||||
var (
|
||||
ErrChatCommandOptionNotExists = errors.New("Chat command option does not exist")
|
||||
ErrChatCommandOptionInvalidType = errors.New("Chat command option is not of the type requested")
|
||||
)
|
||||
|
||||
type ChatCommandContextOptions map[string]ChatCommandOption
|
||||
|
||||
func get[T ChatCommandOption](opts ChatCommandContextOptions, key string) (T, error) {
|
||||
var v T
|
||||
|
||||
mv, ok := opts[key]
|
||||
if !ok {
|
||||
return v, ErrChatCommandOptionNotExists
|
||||
}
|
||||
|
||||
if v, ok := mv.(T); !ok {
|
||||
return v, ErrChatCommandOptionInvalidType
|
||||
} else {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetAttachement(
|
||||
key string,
|
||||
) (*ChatCommandAttachmentOption, error) {
|
||||
return get[*ChatCommandAttachmentOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetBoolean(key string) (*ChatCommandBooleanOption, error) {
|
||||
return get[*ChatCommandBooleanOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetChannel(key string) (*ChatCommandChannelOption, error) {
|
||||
return get[*ChatCommandChannelOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetInteger(key string) (*ChatCommandIntegerOption, error) {
|
||||
return get[*ChatCommandIntegerOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetMentionable(
|
||||
key string,
|
||||
) (*ChatCommandMentionableOption, error) {
|
||||
return get[*ChatCommandMentionableOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetNumber(key string) (*ChatCommandNumberOption, error) {
|
||||
return get[*ChatCommandNumberOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetRole(key string) (*ChatCommandRoleOption, error) {
|
||||
return get[*ChatCommandRoleOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetString(key string) (*ChatCommandStringOption, error) {
|
||||
return get[*ChatCommandStringOption](opts, key)
|
||||
}
|
||||
|
||||
func (opts ChatCommandContextOptions) GetUser(key string) (*ChatCommandUserOption, error) {
|
||||
return get[*ChatCommandUserOption](opts, key)
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ type ChatCommandOption interface {
|
||||
|
||||
type ChatCommandStringOption struct {
|
||||
Name string
|
||||
Value string
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -129,6 +130,7 @@ func (o *ChatCommandStringOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandIntegerOption struct {
|
||||
Name string
|
||||
Value int
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -177,6 +179,7 @@ func (o *ChatCommandIntegerOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandBooleanOption struct {
|
||||
Name string
|
||||
Value bool
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -217,6 +220,7 @@ func (o *ChatCommandBooleanOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandUserOption struct {
|
||||
Name string
|
||||
Value string
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -253,6 +257,7 @@ func (o *ChatCommandUserOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandChannelOption struct {
|
||||
Name string
|
||||
Value string
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -289,6 +294,7 @@ func (o *ChatCommandChannelOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandRoleOption struct {
|
||||
Name string
|
||||
Value string
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -325,6 +331,7 @@ func (o *ChatCommandRoleOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandMentionableOption struct {
|
||||
Name string
|
||||
Value string
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -361,6 +368,7 @@ func (o *ChatCommandMentionableOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandNumberOption struct {
|
||||
Name string
|
||||
Value float64
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
@@ -407,6 +415,7 @@ func (o *ChatCommandNumberOption) Validate() (bool, error) {
|
||||
|
||||
type ChatCommandAttachmentOption struct {
|
||||
Name string
|
||||
Value string
|
||||
NameLocalizations map[discordgo.Locale]string
|
||||
Description string
|
||||
DescriptionLocalizations map[discordgo.Locale]string
|
||||
|
||||
Reference in New Issue
Block a user