muxer

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 10 Imported by: 0

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

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) Abort

func (s *Context) Abort()

func (*Context) MentionCreator

func (s *Context) MentionCreator() string

func (*Context) Next

func (s *Context) Next()

func (*Context) Send

func (s *Context) Send(message string) error

func (*Context) SendPrivately

func (s *Context) SendPrivately(message string) error

type Fields

type Fields []string

func (Fields) Get

func (s Fields) Get(key string) string

func (Fields) GetDefault

func (s Fields) GetDefault(key, defaultValue string) string

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 New

func New() *Mux

New returns a new Discord message route mux

func (*Mux) FuzzyMatch

func (m *Mux) FuzzyMatch(msg string) (*Route, []string)

FuzzyMatch attepts to find the best route match for a givin message.

func (*Mux) Help

func (m *Mux) Help(ctx *Context)

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) Match

func (m *Mux) Match(msg string) (*Route, []string)

Match returns an exact match for the route

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

func (m *Mux) RemoveRoute(pattern string) error

RemoveRoute allows you to unregister a route from the muxer

func (*Mux) Route

func (m *Mux) Route(pattern, desc string, handlers ...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
	Handlers    HandlerChain
}

Route holds information about a specific message route handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL