multiplexer

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package multiplexer does command related stuff.

Index

Constants

This section is empty.

Variables

View Source
var (
	AudioCategory = NewCategory("Audio",
		"Audio related utilities.")
	ExperienceCategory = NewCategory("Experience",
		"Chat experience and ranking system.")
	ManualsCategory = NewCategory("Manuals",
		"The operation manual pager utility.")
	MediaCategory = NewCategory("Media",
		"Media related utilities.")
	ModerationCategory = NewCategory("Moderation",
		"Chat moderation utilities.")
	SystemCategory = NewCategory("System",
		"System-related utilities.")
)

Predefined command categories.

View Source
var (
	EventHandlers         []interface{}
	NotTargeted           []func(context *Context)
	Ready                 []func(session *discordgo.Session, ready *discordgo.Ready)
	GuildMemberAdd        []func(session *discordgo.Session, add *discordgo.GuildMemberAdd)
	GuildMemberRemove     []func(session *discordgo.Session, remove *discordgo.GuildMemberRemove)
	GuildDelete           []func(session *discordgo.Session, delete *discordgo.GuildDelete)
	MessageCreate         []func(session *discordgo.Session, create *discordgo.MessageCreate)
	MessageDelete         []func(session *discordgo.Session, delete *discordgo.MessageDelete)
	MessageUpdate         []func(session *discordgo.Session, update *discordgo.MessageUpdate)
	MessageReactionAdd    []func(session *discordgo.Session, add *discordgo.MessageReactionAdd)
	MessageReactionRemove []func(session *discordgo.Session, remove *discordgo.MessageReactionRemove)
)

Slice of event handlers.

Categories is a slice of pointers to command categories.

View Source
var ErrUserNotFound = errors.New("user not found")

ErrUserNotFound represents the error returned when a user is not found.

View Source
var Router = New()

Router is the command router instance.

Functions

This section is empty.

Types

type CommandCategory

type CommandCategory struct {
	Routes      []*Route
	Title       string
	Description string
}

CommandCategory represents a category of Route.

func NewCategory

func NewCategory(name string, description string) *CommandCategory

NewCategory returns a new command category

type CommandHandler

type CommandHandler func(*Context)

CommandHandler represents the handler function of a Route.

type Context

type Context struct {
	Message           *discordgo.Message
	Session           *discordgo.Session
	Guild             *discordgo.Guild
	Author            *discordgo.User
	Create            *discordgo.MessageCreate
	Fields            []string
	Content           string
	IsPrivate         bool
	IsTargeted        bool
	HasPrefix         bool
	HasMention        bool
	HasLeadingMention bool
}

Context holds information of an event.

func (*Context) Ban added in v1.9.1

func (context *Context) Ban(query string) error

Ban creates a ban on the specified user.

func (*Context) GetChannel added in v1.9.0

func (context *Context) GetChannel(query string) *discordgo.Channel

GetChannel gets a channel from a string representing it.

func (*Context) GetMember

func (context *Context) GetMember(query string) *discordgo.Member

GetMember gets a member from a string representing it.

func (*Context) GetRole added in v1.9.0

func (context *Context) GetRole(query string) *discordgo.Role

GetRole gets a channel from a string representing it.

func (*Context) GetVoiceState

func (context *Context) GetVoiceState() (*discordgo.VoiceState, bool)

GetVoiceState returns the voice state of a user if found.

func (*Context) HandleError

func (context *Context) HandleError(err error) bool

HandleError handles a returned error and send the information of it if in debug mode.

func (*Context) HasPermission

func (context *Context) HasPermission(permission int) bool

HasPermission checks a user for a permission.

func (*Context) IsAdministrator

func (context *Context) IsAdministrator() bool

IsAdministrator checks of a user is the system administrator.

func (*Context) IsOperator

func (context *Context) IsOperator() bool

IsOperator checks of a user is an operator.

func (*Context) MakeVoiceConnection

func (context *Context) MakeVoiceConnection() (*discordgo.VoiceConnection, error)

MakeVoiceConnection returns the voice connection to a user's voice channel if join-able.

func (Context) NumericalRegex added in v1.9.1

func (Context) NumericalRegex() *regexp.Regexp

NumericalRegex returns a compiled regular expression that matches only numbers.

func (*Context) Prefix added in v1.5.0

func (context *Context) Prefix() string

Prefix returns the command prefix of a context.

func (*Context) SendEmbed

func (context *Context) SendEmbed(message string, embed embedutil.Embed) *discordgo.Message

SendEmbed sends an embedutil message in the current channel and returns the message.

func (*Context) SendMessage

func (context *Context) SendMessage(message string) *discordgo.Message

SendMessage sends a text message in the current channel and returns the message.

func (*Context) StitchFields

func (context *Context) StitchFields(start int) string

StitchFields stitches together fields of the message.

type Multiplexer

type Multiplexer struct {
	Routes []*Route
	Prefix string
}

Multiplexer represents the command router.

func New

func New() *Multiplexer

New returns a router.

func (*Multiplexer) MatchRoute

func (mux *Multiplexer) MatchRoute(message string) (*Route, []string)

MatchRoute fuzzy matches a message to a route.

func (*Multiplexer) Route

func (mux *Multiplexer) Route(route *Route) *Route

Route registers a route to the router.

type Route

type Route struct {
	Pattern       string
	AliasPatterns []string
	Description   string
	Category      *CommandCategory
	Handler       CommandHandler
}

Route represents a command route.

Jump to

Keyboard shortcuts

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