Documentation
¶
Overview ¶
Package bot contains some generically useful bot rigging for Discord chatbots.
This package works by defining command handlers in a CommandSet, and then dispatching based on message contents. If the bot's command prefix is `;`, then `;foo` activates the command handler for command `foo`.
A CommandSet has a mutex baked into it for convenience of command implementation.
Index ¶
Constants ¶
const (
DefaultPrefix = "."
)
The default command prefix. Command `foo` becomes `.foo` in chat, etc.
Variables ¶
var ( ErrAlreadyExists = errors.New("bot: command already exists") ErrNoSuchCommand = errors.New("bot: no such command exists") ErrNoPermissions = errors.New("bot: you do not have permissions for this command") ErrParvCountMismatch = errors.New("bot: parameter count mismatch") )
Command handling errors.
var (
DefaultCommandSet = NewCommandSet()
)
The "default" command set, useful for simple bot projects.
var (
ErrRateLimitExceeded = errors.New("bot: per-command rate limit exceeded")
)
Functions ¶
func NewCommand ¶
NewCommand creates an anonymous command and adds it to the default CommandSet.
Types ¶
type CommandHandler ¶
type CommandHandler interface { Verb() string Helptext() string Handler(*discordgo.Session, *discordgo.Message, []string) error Permissions(*discordgo.Session, *discordgo.Message, []string) error }
CommandHandler is a generic interface for types that implement a bot command. It is akin to http.Handler, but more comprehensive.
func NewBasicCommand ¶
func NewBasicCommand(verb, helptext string, permissions, handler Handler) CommandHandler
NewBasicCommand creates a CommandHandler instance using the implementation functions supplied as arguments.
type CommandSet ¶
CommandSet is a group of bot commands similar to an http.ServeMux.
func NewCommandSet ¶
func NewCommandSet() *CommandSet
NewCommandSet creates a new command set with the `help` command pre-loaded.
func (*CommandSet) Add ¶
func (cs *CommandSet) Add(h CommandHandler) error
Add adds a single command handler to the CommandSet. This can be done at runtime but it is suggested to only add commands on application boot.