From 580a80de1bf45235a84c4bb8ee0966a5189f30b2 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Sun, 5 Apr 2020 17:22:24 -0800 Subject: [PATCH] Change AddCommand to accept a command struct Change process to remove Aliases --- djpianalto.com/disgoman/command-manager.go | 17 +++-------------- djpianalto.com/disgoman/structs.go | 1 + 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/djpianalto.com/disgoman/command-manager.go b/djpianalto.com/disgoman/command-manager.go index e8836e8..b63f34f 100644 --- a/djpianalto.com/disgoman/command-manager.go +++ b/djpianalto.com/disgoman/command-manager.go @@ -15,26 +15,15 @@ import ( "strings" ) -func (c *CommandManager) AddCommand(name string, aliases []string, desc string, ownerOnly, hidden bool, perms Permission, command CommandInvokeFunc) error { - if _, ok := c.Commands[name]; ok { - return errors.New(fmt.Sprintf("A command named %v already exists", name)) - } +func (c *CommandManager) AddCommand(aliases []string, command *Command) error { 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)) } } - c.Commands[name] = &Command{ - Name: name, - Description: desc, - OwnerOnly: ownerOnly, - Hidden: hidden, - RequiredPermissions: perms, - Invoke: command, - } if len(aliases) > 0 { for _, alias := range aliases { - c.Aliases[alias] = name + c.Commands[alias] = command } } return nil diff --git a/djpianalto.com/disgoman/structs.go b/djpianalto.com/disgoman/structs.go index 76e806d..2ca3342 100644 --- a/djpianalto.com/disgoman/structs.go +++ b/djpianalto.com/disgoman/structs.go @@ -26,6 +26,7 @@ type StatusManager struct { type Command struct { Name string + Aliases []string Description string OwnerOnly bool Hidden bool