Documentation ¶
Index ¶
- type CmdContext
- type CmdParser
- type Commander
- type Middlewarer
- type Prefixer
- type Route
- func (r *Route) Do(c Commander) *Route
- func (r *Route) Find(subAlias string) *Route
- func (r *Route) Has(subroutes ...*Route) *Route
- func (r *Route) HasAlias(a string) bool
- func (r *Route) IsDefault() bool
- func (r *Route) On(aliases ...string) *Route
- func (r *Route) Use(middlewares ...Middlewarer) *Route
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdContext ¶
type CmdContext struct { Ses *discordgo.Session Msg *discordgo.Message Prefix string Alias []string Args []string Err error }
CmdContext is an aux structure for storing invocation values extracted from a given Context to reduce boilerplate.
This need not be manually initialized; simply call CmdFromContext.
func CmdFromContext ¶
func CmdFromContext(ctx context.Context) *CmdContext
CmdFromContext derives all Command invocation values from given Context.
type CmdParser ¶
CmdParser parses the content of a Discord message into a string slice.
Optionally implemented by Commander
type Commander ¶
Commander is used by a route to handle Discord's Message Create events. https://discord.com/developers/docs/topics/gateway#message-create
Can optionally implement CmdParser, but is not required.
Handle is where a command's business logic should belong.
Resolve is where an error in ctx.Err can be handled, along with any other necessary cleanup. It is run if (custom) parsing fails, middleware fails, or if Handle fails.
type Middlewarer ¶
Middlewarer allows execution of a handler before Handle is executed.
Do accepts a context and returns an error. If error is nil, will execute the next Middlewarer or Handle. Otherwise, it will enter the Resolve function.
Context mutated from within a middleware will only persist within scope.
type Prefixer ¶
Prefixer identifies the prefix based on the guildID and removes the prefix of the command string if matched.
Load fetches a prefix that matches the guildID and returns the prefix mapped to the guildID with an ok bool.
Default returns the default prefix
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route represents a command.
func NewRoute ¶
NewRoute returns a new Route. If Prefixer is nil, the route's prefix will be assumed to be empty.
func (*Route) Do ¶
Do the execution of a Commander implementation when there is a Message Create event. https://discord.com/developers/docs/topics/gateway#message-create
A Commander can optionally implement CmdParser for custom parsing of message content. Parsing errors will be handled by Resolve.
No-ops if Commander is nil.
If Do is called multiple times, the previous Do call will be overwritten.
func (*Route) Find ¶
Find the first subroute of this route matching the given subroute alias. Subroute match is prioritized by order of the subroute appends. If alias is not found, will return nil.
func (*Route) Has ¶
Has binds subroutes to the current route. Subroutes with duplicate aliases will be prioritized in order of which they were added.
func (*Route) HasAlias ¶
HasAlias returns if the given string is a case-insensitive alias of the current route
func (*Route) IsDefault ¶
IsDefault returns true if a route will always be executed when Discord produces a Message Create event with respect to the Prefixer (if provided).
https://discord.com/developers/docs/topics/gateway#message-create
A default route will only be executed if it is not a subroute. Any subroutes it might contain will be ignored.
func (*Route) On ¶
On adds new identifiers for a Route. By default, aliases with whitespaces will not be matched unless a Commander also implements the CmdParser interface
func (*Route) Use ¶
func (r *Route) Use(middlewares ...Middlewarer) *Route
Use adds middlewares to the route. Middlewares are executed in order of which they were added, and will always run immediately before the core handler. Middleware errors can be handled by Resolve.
type Router ¶
Router maps commands to handlers.
func (*Router) HasDefault ¶
func (r *Router) HasDefault(h interface{})
HasDefault binds a default discordgo event handler to the builder.
func (*Router) HasOnce ¶
HasOnce binds binds a Route to the Router, but the route will only fire at most once.
func (*Router) HasOnceDefault ¶
func (r *Router) HasOnceDefault(h interface{})
HasOnceDefault binds a default discordgo event handler to the builder.
func (*Router) Open ¶
Open creates a websocket connection to Discord. See: https://discordapp.com/developers/docs/topics/gateway#connecting