Add comments for godocs
This commit is contained in:
parent
51cbfd618f
commit
1cd65ac003
@ -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
|
||||
|
||||
18
disgoman.go
18
disgoman.go
@ -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"}
|
||||
}
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
1
types.go
1
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
|
||||
|
||||
10
utils.go
10
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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user