Documentation
¶
Overview ¶
The Commands package both contains the Manager framework and the bot commands. Everything is pretty modular and can be adapted to your own use cases.
Index ¶
- type Command
- type CommandArgFunc
- type CommandFunc
- type CommandType
- type Context
- type Manager
- func (cmdm *Manager) AddCommand(cmd *Command)
- func (cmdm *Manager) AddNewCommand(name string, aliases []string, desc string, owneronly, hidden bool, ...)
- func (cmdm *Manager) AddPrefix(prefix string)
- func (cmdm *Manager) CommandHandler(s *discordgo.Session, m *discordgo.MessageCreate)
- func (cmdm *Manager) GetCommand(name string) (cmd *Command, exists bool, index int)
- func (cmdm *Manager) GetPrefixes() []string
- func (cmdm *Manager) IsOwner(id string) bool
- func (cmdm *Manager) RemoveCommand(name string)
- func (cmdm *Manager) RemovePrefix(prefix string)
- func (cmdm *Manager) SetPrefixes(prefixes []string)
- type ManagerOnErrorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { // The name of the command (What it will be triggered by). Name string // Command aliases Aliases []string // The command's description. Description string // If the command is only able to be ran by an owner. OwnerOnly bool // If the command is hidden from help. Hidden bool // The permissions the user is required to have to execute the command. UserPermissions permissions.Permission // The permissions the bot is required to have to execute the command. BotPermissions permissions.Permission // The CommandType designates where the command can be ran. Type CommandType // The function that will be executed whenever a message fits the criteria to execute the command. Run CommandFunc // The function that will be ran to process arguments ProcessArgs CommandArgFunc }
A Command represents any given command contained in a bot.
func DefaultHelp ¶
func RemoveCommandFromSlice ¶ added in v0.3.0
type CommandArgFunc ¶ added in v0.3.0
type CommandArgFunc func([]string) interface{}
type CommandFunc ¶
A CommandFunc is ran whenever a CommandManager gets a message supposed to run the given command.
type CommandType ¶
type CommandType int
A CommandType represents the locations commands can be used.
const ( // A Command that is only supposed to run in a personal message CommandTypePM CommandType = iota // A command that is only supposed to run in a Guild CommandTypeGuild // A Command that is able to run anywhere CommandTypeEverywhere )
type Context ¶
type Context struct { // The connection to Discord. Session *discordgo.Session // The event that fired the CommandHandler. Event *discordgo.MessageCreate // The CommandManager that handled this command. Manager *Manager // The custom args struct for this command Args interface{} // The Message that fired this event. Message *discordgo.Message // The User that fired this event. User *discordgo.User // The Channel the event was fired in. Channel *discordgo.Channel // The guild the Channel belongs to. Guild *discordgo.Guild // The User's guild member. Member *discordgo.Member }
A Context is passed to a CommandRunFunc. It contains the information needed for a command to execute.
func (*Context) PurgeMessages ¶ added in v0.3.0
PurgeMessages purges 'x' number of messages from the Channel a Context was initiated for.
func (*Context) ReplyEmbed ¶
ReplyEmbed sends an embed to the channel a Context was initiated for.
type Manager ¶
type Manager struct { // The array of prefixes a Manager will respond to. Prefixes []string // The array of IDs that will be considered a bot owner. Owners []string // The bot instance Logger. Logger *logrus.Logger // The map of Commands in the Manager. Commands *[]*Command // If the Manager ignores bots or not. IgnoreBots bool // The function that will be ran when the Manager encounters an error. OnErrorFunc ManagerOnErrorFunc }
A Manager represents a set of prefixes, owners and commands, with some extra utility to create a command handler.
func NewManager ¶
func NewManager(l *logrus.Logger, ignoreBots bool, errorFunc ManagerOnErrorFunc) Manager
NewManager instantiates a new Manager. It returns a Manager.
func (*Manager) AddCommand ¶ added in v0.3.0
AddCommand adds an existent command to the Manager's command list. It returns nothing.
func (*Manager) AddNewCommand ¶ added in v0.3.0
func (cmdm *Manager) AddNewCommand(name string, aliases []string, desc string, owneronly, hidden bool, userperms, botperms permissions.Permission, cmdType CommandType, run CommandFunc)
AddNewCommand adds a new command to the Manager's command list. It returns nothing.
func (*Manager) AddPrefix ¶
AddPrefix adds a new prefix to the Manager's prefix list. It returns nothing.
func (*Manager) CommandHandler ¶ added in v0.3.0
func (cmdm *Manager) CommandHandler(s *discordgo.Session, m *discordgo.MessageCreate)
CommandHandler works as the Manager's message listener. It returns nothing.
func (*Manager) GetCommand ¶
func (*Manager) GetPrefixes ¶
GetPrefixes gets the Manager's prefix list. It returns a string array.
func (*Manager) RemoveCommand ¶ added in v0.3.0
RemoveCommand removes a command from the Manager's command list. It returns nothing.
func (*Manager) RemovePrefix ¶
RemovePrefix removes a prefix from the Manager's prefix list. It returns nothing.
func (*Manager) SetPrefixes ¶
SetPrefixes sets the Manager's prefix list. It returns nothing.
type ManagerOnErrorFunc ¶ added in v0.3.0
A ManagerOnErrorFunc is a function that will run whenever the Manager encounters an error.