Documentation ¶
Overview ¶
Package mux provides a simple Discord message route multiplexer that parses messages and then executes a matching registered handler, if found. mux can be used with both Disgord and the DiscordGo library.
Index ¶
- Variables
- type Context
- type HandlerFunc
- type Mux
- func (m *Mux) FuzzyMatch(msg string) (*Route, []string)
- func (m *Mux) OnMessageCreate(ds *discordgo.Session, mc *discordgo.MessageCreate)
- func (m *Mux) Ping(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)
- func (m *Mux) Route(pattern, desc string, cb HandlerFunc) (*Route, error)
- func (m *Mux) Weather(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)
- func (m *Mux) WeatherHelp(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)
- type Route
Constants ¶
This section is empty.
Variables ¶
var (
WeatherAPIToken string
)
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Fields []string Content string IsDirected bool IsPrivate bool HasPrefix bool HasMention bool HasMentionFirst bool }
Context holds a bit of extra data we pass along to route handlers This way processing some of this only needs to happen once.
type HandlerFunc ¶
HandlerFunc is the function signature required for a message route handler.
type Mux ¶
Mux is the main struct for all mux methods.
func (*Mux) FuzzyMatch ¶
FuzzyMatch attempts to find the best route match for a given message.
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) Route ¶
func (m *Mux) Route(pattern, desc string, cb HandlerFunc) (*Route, error)
Route allows you to register a route
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 }
Route holds information about a specific message route handler