disgomux

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 4 Imported by: 0

README

disgomux

A multiplexer for DiscordGo

Why choose this over any other DiscordGo Mux?

You really shouldn't, but if you're considering it, here are a few reasons I think mine is cool.

  • It makes use of interfaces to have fine-tuned control over how command handlers are managed.
  • It has support for custom loggers.
  • It's reasonably straightforward to understand.
  • It supports help commands quite nicely.
  • An example of it in action can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

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

Command specifies the functions for a multiplexed command

type CommandPermissions

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

CommandPermissions holds permissions 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
}

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 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) 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(commands ...Command)

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) InitializeFuzzy added in v0.2.0

func (m *Mux) InitializeFuzzy()

InitializeFuzzy both enables and builds a list of commands to fuzzy match against. This _will_ mean taking a performance hit, so use with caution.

func (*Mux) Options added in v0.2.0

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

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

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

func (m *Mux) UseMiddleware(mw Middleware)

UseMiddleware adds a middleware to the multiplexer. //TODO: Improve this desc

type Options added in v0.2.0

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