mux

package
v0.0.0-...-8bb0e6c Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var LoggerInstance *logger.Logger

LoggerInstance is for commands to be able to access the Log for commands

View Source
var WeeklyInstance *tasks.WeeklyInfo

WeeklyInstance just hooks into weekly info so we can manage tasks with commands

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

type HandlerFunc func(*discordgo.Session, *discordgo.Message, *Context)

HandlerFunc is the function signature required for a message route handler.

type Mux

type Mux struct {
	Routes  []*Route
	Default *Route
	Prefix  string
}

Mux is the main struct for all mux methods.

func New

func New() *Mux

New returns a new Discord message route mux

func (*Mux) Echo

func (m *Mux) Echo(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

Echo function just echos the passed in message

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(ds *discordgo.Session, dm *discordgo.Message, 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) LogManager

func (m *Mux) LogManager(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

LogManager allows you to manage the logger

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

func (*Mux) TaskManager

func (m *Mux) TaskManager(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Trials

func (m *Mux) Trials(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

Trials gets weekly information about trails stuff.

func (*Mux) Weekly

func (m *Mux) Weekly(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

Weekly gets Destiny 2 weekly information

func (*Mux) Xur

func (m *Mux) Xur(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

Xur returns where xur is in the current week

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

Jump to

Keyboard shortcuts

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