multiplexer

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Integrated command handlers.

Event multiplexer.

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.")
)

Define the categories here

View Source
var (
	EventHandlers     []interface{}
	Router            = New()
	NotTargeted       []interface{}
	GuildMemberAdd    []interface{}
	GuildMemberRemove []interface{}
	GuildDelete       []interface{}
)

Functions

This section is empty.

Types

type CommandCategory

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

Command categories

func NewCategory

func NewCategory(name string, description string) *CommandCategory

Returns a new command category

type CommandHandler

type CommandHandler func(*Context)

Function signature for functions that handle commands

type CommandHandlers

type CommandHandlers struct{}

Some structures to save some registering work

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 information passed to the handlers

func (*Context) GenerateGuildPrefix

func (context *Context) GenerateGuildPrefix() string

GenerateGuildPrefix returns the command prefix of a context.

func (*Context) GetMember

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

GetMember gets a member 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) SendEmbed

func (context *Context) SendEmbed(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
}

Structure the multiplexer

func New

func New() *Multiplexer

Returns a new message route multiplexer

func (*Multiplexer) MatchRoute

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

This matches routes for the message

func (*Multiplexer) OnGuildDelete

func (mux *Multiplexer) OnGuildDelete(session *discordgo.Session, delete *discordgo.GuildDelete)

Event handler that fires when a guild is deleted

func (*Multiplexer) OnGuildMemberAdd

func (mux *Multiplexer) OnGuildMemberAdd(session *discordgo.Session, add *discordgo.GuildMemberAdd)

Event handler that fires when a guild member is added

func (*Multiplexer) OnGuildMemberRemove

func (mux *Multiplexer) OnGuildMemberRemove(session *discordgo.Session, remove *discordgo.GuildMemberRemove)

Event handler that fires when a guild member is removed

func (*Multiplexer) OnMessageCreate

func (mux *Multiplexer) OnMessageCreate(session *discordgo.Session, create *discordgo.MessageCreate)

DiscordGo library event handler registered into the session

func (*Multiplexer) Route

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

Register a route

type Route

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

Information about a handler

Jump to

Keyboard shortcuts

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