diff --git a/command-manager.go b/command-manager.go index df1b44d..b53a143 100644 --- a/command-manager.go +++ b/command-manager.go @@ -15,6 +15,8 @@ import ( "strings" ) +// Adds the Command at the address passed in to the Commands array on the CommandManager. +// - Will error if the command's name or any of the aliases already exist. func (c *CommandManager) AddCommand(command *Command) error { var aliases = []string{command.Name} if command.Aliases != nil { @@ -33,6 +35,7 @@ func (c *CommandManager) AddCommand(command *Command) error { return nil } +// Removes the command named from the Commands array func (c *CommandManager) RemoveCommand(name string) error { deleted := false if _, ok := c.Commands[name]; ok { @@ -45,6 +48,7 @@ func (c *CommandManager) RemoveCommand(name string) error { return nil } +// Checks if the user ID is in the Owners array func (c *CommandManager) IsOwner(id string) bool { for _, o := range c.Owners { if o == id { @@ -54,6 +58,12 @@ func (c *CommandManager) IsOwner(id string) bool { return false } +// The OnMessage event handler +// Checks if the message has one of the specified prefixes +// Checks if the message contains one of the commands +// Processes the arguments to pass into the command +// Checks the permissions for the command +// Runs the command function with the current Context func (c *CommandManager) OnMessage(session *discordgo.Session, m *discordgo.MessageCreate) { if m.Author.Bot && c.IgnoreBots { return // If the author is a bot and ignore bots is set then just exit diff --git a/disgoman.go b/disgoman.go deleted file mode 100644 index 52e0e39..0000000 --- a/disgoman.go +++ /dev/null @@ -1,18 +0,0 @@ -package disgoman - -/* Package Disgoman: - * Command Handler for DisgordGo. - * Inspired by: - * - Anpan (https://github.com/MikeModder/anpan) - * - * Disgoman (c) 2020 Dusty.P/dustinpianalto - */ - -func GetDefaultStatusManager() StatusManager { - return StatusManager{ - []string{ - "Golang!", - "DiscordGo!", - "Disgoman!", - }, "10s"} -} diff --git a/status-manager.go b/status-manager.go index 70e1267..2c57a09 100644 --- a/status-manager.go +++ b/status-manager.go @@ -34,12 +34,14 @@ func (s *StatusManager) SetInterval(interval string) { s.Interval = interval } +// Update the status now func (s *StatusManager) UpdateStatus(session *discordgo.Session) error { i := rand.Intn(len(s.Values)) err := session.UpdateStatus(0, s.Values[i]) return err } +// Default StatusManager ready function which updates the status at the specified interval func (s *StatusManager) OnReady(session *discordgo.Session, _ *discordgo.Ready) { interval, err := time.ParseDuration(s.Interval) if err != nil { diff --git a/structs.go b/structs.go index ee47694..1e7312b 100644 --- a/structs.go +++ b/structs.go @@ -8,6 +8,7 @@ package disgoman import "github.com/bwmarrin/discordgo" +// Create a CommandManager which will hold the info and structures required for handling command messages type CommandManager struct { Prefixes PrefixesFunc Owners []string @@ -18,11 +19,13 @@ type CommandManager struct { CheckPermissions bool } +// Create a StatusManager which will update the status of the bot type StatusManager struct { Values []string Interval string } +// Create a Command with all of the info specific to this command type Command struct { Name string Aliases []string @@ -33,6 +36,7 @@ type Command struct { Invoke CommandInvokeFunc } +// Structure containing all the context that a command needs to run type Context struct { Session *discordgo.Session Channel *discordgo.Channel diff --git a/types.go b/types.go index a1d4d1d..06e7d47 100644 --- a/types.go +++ b/types.go @@ -15,6 +15,7 @@ type PrefixesFunc func(string) []string // Function to run on command error type OnErrorFunc func(Context, string, error) +// Permission type to help with managing permissions for commands type Permission int // Defining permissions based on the Discord API diff --git a/utils.go b/utils.go index d841a21..a3d0760 100644 --- a/utils.go +++ b/utils.go @@ -8,6 +8,16 @@ package disgoman import "github.com/bwmarrin/discordgo" +// Returns a default Status Manager +func GetDefaultStatusManager() StatusManager { + return StatusManager{ + []string{ + "Golang!", + "DiscordGo!", + "Disgoman!", + }, "10s"} +} + // Checks the channel and guild permissions to see if the member has the needed permissions func CheckPermissions(session *discordgo.Session, member discordgo.Member, channel discordgo.Channel, perms Permission) bool { if perms == 0 {