feat(lib,commands): UserCommand struct
This commit is contained in:
41
lib/command_user.go
Normal file
41
lib/command_user.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
type UserCommand struct {
|
||||
Name string
|
||||
NameLocalizations *map[discordgo.Locale]string
|
||||
DefaultMemberPermissions *int64
|
||||
NSFW *bool
|
||||
Description string
|
||||
DescriptionLocalizations *map[discordgo.Locale]string
|
||||
Handler Handler
|
||||
}
|
||||
|
||||
func (c *UserCommand) ApplicationCommand() *discordgo.ApplicationCommand {
|
||||
return &discordgo.ApplicationCommand{
|
||||
Type: discordgo.UserApplicationCommand,
|
||||
Name: c.Name,
|
||||
NameLocalizations: c.NameLocalizations,
|
||||
DefaultMemberPermissions: c.DefaultMemberPermissions,
|
||||
NSFW: c.NSFW,
|
||||
Description: c.Description,
|
||||
DescriptionLocalizations: c.DescriptionLocalizations,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *UserCommand) Validate() (bool, error) {
|
||||
switch {
|
||||
case c.Name == "":
|
||||
return false, errors.New("Required property \"Name\" is empty")
|
||||
case c.Description == "":
|
||||
return false, errors.New("Required property \"Description\" is empty")
|
||||
case c.Handler == nil:
|
||||
return false, errors.New("Required property \"Handler\" is empty")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
Reference in New Issue
Block a user