Change AddCommand to accept a command struct

Change process to remove Aliases
master
DustyP 6 years ago
parent 28adfdeb09
commit 580a80de1b

@ -15,26 +15,15 @@ import (
"strings" "strings"
) )
func (c *CommandManager) AddCommand(name string, aliases []string, desc string, ownerOnly, hidden bool, perms Permission, command CommandInvokeFunc) error { func (c *CommandManager) AddCommand(aliases []string, command *Command) error {
if _, ok := c.Commands[name]; ok {
return errors.New(fmt.Sprintf("A command named %v already exists", name))
}
for _, alias := range aliases { for _, alias := range aliases {
if _, ok := c.Aliases[alias]; ok { if _, ok := c.Commands[alias]; ok {
return errors.New(fmt.Sprintf("An alias named %v already exists", alias)) return errors.New(fmt.Sprintf("An alias named %v already exists", alias))
} }
} }
c.Commands[name] = &Command{
Name: name,
Description: desc,
OwnerOnly: ownerOnly,
Hidden: hidden,
RequiredPermissions: perms,
Invoke: command,
}
if len(aliases) > 0 { if len(aliases) > 0 {
for _, alias := range aliases { for _, alias := range aliases {
c.Aliases[alias] = name c.Commands[alias] = command
} }
} }
return nil return nil

@ -26,6 +26,7 @@ type StatusManager struct {
type Command struct { type Command struct {
Name string Name string
Aliases []string
Description string Description string
OwnerOnly bool OwnerOnly bool
Hidden bool Hidden bool

Loading…
Cancel
Save