Documentation
¶
Index ¶
- func CheckPermissions(perms *CommandPermissions, userID string, roleIDs []string, chanID string) bool
- type Command
- type CommandPermissions
- type CommandSettings
- type Context
- type ErrorTexts
- type Middleware
- type Mux
- func (m *Mux) ClearSimple()
- func (m *Mux) Handle(session *discordgo.Session, message *discordgo.MessageCreate)
- func (m *Mux) Initialize()
- func (m *Mux) Register(commands ...Command)
- func (m *Mux) RegisterSimple(simpleCommands ...SimpleCommand)
- func (m *Mux) SetErrors(errorTexts *ErrorTexts)
- func (m *Mux) SetOptions(opt *Options)
- func (m *Mux) SetPermissions(perms map[string]*CommandPermissions)
- func (m *Mux) UseFuzzy()
- func (m *Mux) UseMiddleware(mw Middleware)
- type Options
- type SimpleCommand
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 ¶
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 ¶
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 ¶
ChannelSend is a helper function for easily sending a 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 (*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) 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 ¶
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 ¶
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.