Documentation ¶
Overview ¶
Package muxer provides a simple Discord message route multiplexer that parses messages and then executes a matching registered handler, if found. dgMux can be used with both Disgord and the DiscordGo library. based on the code from https://github.com/bwmarrin/disgord/tree/master/x
Index ¶
- type Context
- type Fields
- type HandlerChain
- type HandlerFunc
- type Mux
- func (m *Mux) FuzzyMatch(msg string) (*Route, []string)
- func (m *Mux) Help(ctx *Context)
- func (m *Mux) Match(msg string) (*Route, []string)
- func (m *Mux) OnMessageCreate(ds *discordgo.Session, mc *discordgo.MessageCreate)
- func (m *Mux) RemoveRoute(pattern string) error
- func (m *Mux) Route(pattern, desc string, handlers ...HandlerFunc) (*Route, error)
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Session *discordgo.Session Message *discordgo.Message Fields Fields Content string GuildID string IsDirected bool IsPrivate bool HasPrefix bool HasMention bool HasMentionFirst bool FromUserID string FromUser string // contains filtered or unexported fields }
Context holds a bit of extra data we pass along to route handlers This way processing some of this only needs to happen once.
func (*Context) MentionCreator ¶
func (*Context) SendPrivately ¶
type HandlerChain ¶
type HandlerChain []HandlerFunc
type HandlerFunc ¶
type HandlerFunc func(*Context)
HandlerFunc is the function signature required for a message route handler.
type Mux ¶
type Mux struct { Routes []*Route Default *Route Prefix string // contains filtered or unexported fields }
Mux is the main struct for all dgMux methods.
func (*Mux) FuzzyMatch ¶
FuzzyMatch attepts to find the best route match for a givin message.
func (*Mux) Help ¶
Help function provides a build in "help" command that will display a list of all registered routes (commands). To use this function it must first be registered with the Mux.Route function.
func (*Mux) OnMessageCreate ¶
func (m *Mux) OnMessageCreate(ds *discordgo.Session, mc *discordgo.MessageCreate)
OnMessageCreate is a DiscordGo Event Handler function. This must be registered using the DiscordGo.Session.AddHandler function. This function will receive all Discord messages and parse them for matches to registered routes.
func (*Mux) RemoveRoute ¶
RemoveRoute allows you to unregister a route from the muxer
type Route ¶
type Route struct { Pattern string // match pattern that should trigger this route handler Description string // short description of this route Help string // detailed help string for this route Run HandlerFunc // route handler function to call Handlers HandlerChain }
Route holds information about a specific message route handler