Add comments for godocs
This commit is contained in:
parent
51cbfd618f
commit
1cd65ac003
@ -15,6 +15,8 @@ import (
|
|||||||
"strings"
|
"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 {
|
func (c *CommandManager) AddCommand(command *Command) error {
|
||||||
var aliases = []string{command.Name}
|
var aliases = []string{command.Name}
|
||||||
if command.Aliases != nil {
|
if command.Aliases != nil {
|
||||||
@ -33,6 +35,7 @@ func (c *CommandManager) AddCommand(command *Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes the command named from the Commands array
|
||||||
func (c *CommandManager) RemoveCommand(name string) error {
|
func (c *CommandManager) RemoveCommand(name string) error {
|
||||||
deleted := false
|
deleted := false
|
||||||
if _, ok := c.Commands[name]; ok {
|
if _, ok := c.Commands[name]; ok {
|
||||||
@ -45,6 +48,7 @@ func (c *CommandManager) RemoveCommand(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the user ID is in the Owners array
|
||||||
func (c *CommandManager) IsOwner(id string) bool {
|
func (c *CommandManager) IsOwner(id string) bool {
|
||||||
for _, o := range c.Owners {
|
for _, o := range c.Owners {
|
||||||
if o == id {
|
if o == id {
|
||||||
@ -54,6 +58,12 @@ func (c *CommandManager) IsOwner(id string) bool {
|
|||||||
return false
|
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) {
|
func (c *CommandManager) OnMessage(session *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
if m.Author.Bot && c.IgnoreBots {
|
if m.Author.Bot && c.IgnoreBots {
|
||||||
return // If the author is a bot and ignore bots is set then just exit
|
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
|
s.Interval = interval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the status now
|
||||||
func (s *StatusManager) UpdateStatus(session *discordgo.Session) error {
|
func (s *StatusManager) UpdateStatus(session *discordgo.Session) error {
|
||||||
i := rand.Intn(len(s.Values))
|
i := rand.Intn(len(s.Values))
|
||||||
err := session.UpdateStatus(0, s.Values[i])
|
err := session.UpdateStatus(0, s.Values[i])
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default StatusManager ready function which updates the status at the specified interval
|
||||||
func (s *StatusManager) OnReady(session *discordgo.Session, _ *discordgo.Ready) {
|
func (s *StatusManager) OnReady(session *discordgo.Session, _ *discordgo.Ready) {
|
||||||
interval, err := time.ParseDuration(s.Interval)
|
interval, err := time.ParseDuration(s.Interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ package disgoman
|
|||||||
|
|
||||||
import "github.com/bwmarrin/discordgo"
|
import "github.com/bwmarrin/discordgo"
|
||||||
|
|
||||||
|
// Create a CommandManager which will hold the info and structures required for handling command messages
|
||||||
type CommandManager struct {
|
type CommandManager struct {
|
||||||
Prefixes PrefixesFunc
|
Prefixes PrefixesFunc
|
||||||
Owners []string
|
Owners []string
|
||||||
@ -18,11 +19,13 @@ type CommandManager struct {
|
|||||||
CheckPermissions bool
|
CheckPermissions bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a StatusManager which will update the status of the bot
|
||||||
type StatusManager struct {
|
type StatusManager struct {
|
||||||
Values []string
|
Values []string
|
||||||
Interval string
|
Interval string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a Command with all of the info specific to this command
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Name string
|
Name string
|
||||||
Aliases []string
|
Aliases []string
|
||||||
@ -33,6 +36,7 @@ type Command struct {
|
|||||||
Invoke CommandInvokeFunc
|
Invoke CommandInvokeFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Structure containing all the context that a command needs to run
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Session *discordgo.Session
|
Session *discordgo.Session
|
||||||
Channel *discordgo.Channel
|
Channel *discordgo.Channel
|
||||||
|
|||||||
1
types.go
1
types.go
@ -15,6 +15,7 @@ type PrefixesFunc func(string) []string
|
|||||||
// Function to run on command error
|
// Function to run on command error
|
||||||
type OnErrorFunc func(Context, string, error)
|
type OnErrorFunc func(Context, string, error)
|
||||||
|
|
||||||
|
// Permission type to help with managing permissions for commands
|
||||||
type Permission int
|
type Permission int
|
||||||
|
|
||||||
// Defining permissions based on the Discord API
|
// Defining permissions based on the Discord API
|
||||||
|
|||||||
10
utils.go
10
utils.go
@ -8,6 +8,16 @@ package disgoman
|
|||||||
|
|
||||||
import "github.com/bwmarrin/discordgo"
|
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
|
// 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 {
|
func CheckPermissions(session *discordgo.Session, member discordgo.Member, channel discordgo.Channel, perms Permission) bool {
|
||||||
if perms == 0 {
|
if perms == 0 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user