multiplexer

package
v0.0.0-...-3e389c1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPermissions

func CheckPermissions(
	perms *CommandPermissions,
	userID string, roleIDs []string, chanID string,
) bool

CheckPermissions takes the user, role(s), and channel IDs and checks them against the supplied permissions struct.

Types

type Command

type Command interface {
	Init(m *Mux)
	Handle(ctx *Context)
	HandleHelp(ctx *Context)
	Settings() *CommandSettings
}

Command specifies the functions for a multiplexed command

type CommandPermissions

type CommandPermissions struct {
	UserIDs []string
	RoleIDs []string
	ChanIDs []string
}

CommandPermissions holds the specific ID arrays for a given command in whitelist format. UserID takes priority over all other permissions. RoleID takes priority over ChanID.

type CommandSettings

type CommandSettings struct {
	Command, HelpText string

	RateLimitMax int
	RateLimitDB  *cache.Cache
}

CommandSettings contain command-specific settings the multiplexer should know.

type Context

type Context struct {
	Prefix, Command string
	Arguments       []string
	Session         *discordgo.Session
	Message         *discordgo.MessageCreate
}

Context is the contexual values supplied to middlewares and handlers

func (*Context) ChannelSend

func (ctx *Context) ChannelSend(message string) (*discordgo.Message, error)

ChannelSend is a helper function for easily sending a message to the current channel.

func (*Context) ChannelSendf

func (ctx *Context) ChannelSendf(
	format string,
	a ...interface{},
) (*discordgo.Message, error)

ChannelSendf is a helper function like ChannelSend for sending a formatted message to the current channel.

type ErrorTexts

type ErrorTexts struct {
	CommandNotFound, NoPermissions, RateLimited string
}

ErrorTexts holds strings used when an error occurs

type Middleware

type Middleware func(*Context)

Middleware specifies a special middleware function that is called anytime handle() is called from DiscordGo

type Mux

type Mux struct {
	Prefix         string
	Commands       map[string]Command
	SimpleCommands map[string]SimpleCommand
	Middleware     []Middleware
	// contains filtered or unexported fields
}

Mux is the multiplexer object. Initialized with New().

func New

func New(prefix string) (*Mux, error)

New initlaizes a new Mux object

func (*Mux) ClearSimple

func (m *Mux) ClearSimple()

func (*Mux) Handle

func (m *Mux) Handle(
	session *discordgo.Session,
	message *discordgo.MessageCreate,
)

Handle is passed to DiscordGo to handle actions

func (*Mux) Initialize

func (m *Mux) Initialize()

Initialize calls the init functions of all registered commands to do any preloading or setup before commands are to be handled. Must be called before Mux.Handle() and after Mux.Register()

func (*Mux) Register

func (m *Mux) Register(commands ...Command)

Register registers one or more commands to the multiplexer

func (*Mux) RegisterSimple

func (m *Mux) RegisterSimple(simpleCommands ...SimpleCommand)

RegisterSimple registers one or more simple commands to the multiplexer

func (*Mux) SetErrors

func (m *Mux) SetErrors(errorTexts *ErrorTexts)

SetErrors sets the error texts for the multiplexer using the supplied struct

func (*Mux) SetOptions

func (m *Mux) SetOptions(opt *Options)

SetOptions allows configuration of the multiplexer. Must be called before Initialize()

func (*Mux) SetPermissions

func (m *Mux) SetPermissions(perms map[string]*CommandPermissions)

SetPermissions allows defining permissions for each command. Must be called before Initialize()

func (*Mux) UseFuzzy

func (m *Mux) UseFuzzy()

UseFuzzy both enables and builds a list of commands to fuzzy match against. May result in a small performance hit

func (*Mux) UseMiddleware

func (m *Mux) UseMiddleware(mw Middleware)

UseMiddleware adds a middleware to the multiplexer. Middlewares are called before a command is handled.

type Options

type Options struct {
	IgnoreBots       bool
	IgnoreDMs        bool
	IgnoreEmpty      bool
	IgnoreNonDefault bool
}

Options is a set of config options to use when handling a message. All properties true by default.

type SimpleCommand

type SimpleCommand struct {
	Command, Content, HelpText string
}

SimpleCommand contains the content and helptext of a logic-less command. Simple commands have no support for permissions.

Jump to

Keyboard shortcuts

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