Documentation ¶
Index ¶
- Constants
- Variables
- func GetChannel(session *discordgo.Session, id string) *discordgo.Channel
- func GetGuild(session *discordgo.Session, id string) *discordgo.Guild
- type CommandCategory
- type CommandHandler
- type Context
- func (context *Context) Ban(query string) error
- func (context *Context) GetChannel(query string) *discordgo.Channel
- func (context *Context) GetMember(query string) *discordgo.Member
- func (context *Context) GetRole(query string) *discordgo.Role
- func (context *Context) GetVoiceState() (*discordgo.VoiceState, bool)
- func (context *Context) HandleError(err error) bool
- func (context *Context) HasPermission(permission int) bool
- func (context *Context) IsAdministrator() bool
- func (context *Context) IsOperator() bool
- func (context *Context) MakeVoiceConnection() (*discordgo.VoiceConnection, error)
- func (Context) NumericalRegex() *regexp.Regexp
- func (context *Context) Prefix() string
- func (context *Context) SendEmbed(message string, embed embedutil.Embed) *discordgo.Message
- func (context *Context) SendMessage(message string) *discordgo.Message
- func (context *Context) StitchFields(start int) string
- type Multiplexer
- func (mux *Multiplexer) IsAdministrator(id string) bool
- func (mux *Multiplexer) IsOperator(id string) bool
- func (mux *Multiplexer) MatchRoute(message string) (*Route, []string)
- func (mux *Multiplexer) NewContextMessage(session *discordgo.Session, message *discordgo.Message, event interface{}) *Context
- func (mux *Multiplexer) Route(route *Route) *Route
- func (mux *Multiplexer) SessionRegisterHandlers(session *discordgo.Session)
- type Route
Constants ¶
const AdminOnly = "This command is only available to system administrators!"
AdminOnly is the message sent when an unprivileged user invokes an admin-only request.
const ErrorOccurred = "Something went wrong and I am very confused! Please try again!"
ErrorOccurred is the message sent when the event handler catches an error.
const FeatureDisabled = "This feature is currently disabled."
FeatureDisabled is the message sent when a feature requested by the user is disabled.
const GuildOnly = "This command can only be issued from a guild."
GuildOnly is the message sent when a guild-only command is issued in private.
const InvalidArgument = "Invalid argument."
InvalidArgument is the message sent when the user passes an invalid argument.
const KappaColor = 0x3492c4
KappaColor is the primary color of the kappa.
const LackingPermission = "Lacking permission to perform specified action."
LackingPermission is the message sent when lacking permission for an operation.
const MissingUser = "Specified user does not exist."
MissingUser is the message sent when a specified user does not exist.
const OperatorOnly = "This command is only available to operators!"
OperatorOnly is the message sent when an unprivileged user invokes an operator-only request.
const PermissionDenied = "You are not allowed to issue this command!"
PermissionDenied is the message sent when the user invokes a request without sufficient permission.
Variables ¶
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.
ErrUserNotFound represents the error returned when a user is not found.
GetPrefix is the function used to get a prefix of a guild.
var NoCommandMatched = func(context *Context) {
context.SendMessage("Command not found.")
}
NoCommandMatched is called when no command is matched.
Functions ¶
func GetChannel ¶
GetChannel fetches channel from cache then API and returns nil if all fails.
Types ¶
type CommandCategory ¶
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 { Multiplexer *Multiplexer User *discordgo.User Member *discordgo.Member Message *discordgo.Message Session *discordgo.Session Guild *discordgo.Guild Channel *discordgo.Channel Event interface{} Text string Fields []string IsPrivate bool IsTargeted bool HasPrefix bool HasMention bool HasLeadingMention bool }
Context carries an event's information.
func (*Context) Ban ¶
Ban creates a ban on the specified user.
func (*Context) GetChannel ¶
GetChannel gets a channel from a string representing it.
func (*Context) GetMember ¶
GetMember gets a member from a string representing it.
func (*Context) GetRole ¶
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 ¶
HandleError handles a returned error and send the information of it if in debug mode.
func (*Context) HasPermission ¶
HasPermission checks a user for a permission.
func (*Context) IsAdministrator ¶
IsAdministrator checks of a user is the system administrator.
func (*Context) IsOperator ¶
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 ¶
NumericalRegex returns a compiled regular expression that matches only numbers.
func (*Context) Prefix ¶
Prefix returns the command prefix of a context.
func (*Context) SendEmbed ¶
SendEmbed sends an embedutil message in the current channel and returns the message.
func (*Context) SendMessage ¶
SendMessage sends a text message in the current channel and returns the message.
type Multiplexer ¶
type Multiplexer struct { // Prefix is the default command prefix. Prefix string // Routes is a slice of pointers to command routes. Routes []*Route // Categories is a slice of pointers to CommandCategory. Categories []*CommandCategory // EventHandlers is a slice of event handler functions registered to the library directly EventHandlers []interface{} NotTargeted []func(context *Context) Ready []func(context *Context) GuildMemberAdd []func(context *Context) GuildMemberRemove []func(context *Context) GuildDelete []func(context *Context) MessageCreate []func(context *Context) MessageDelete []func(context *Context) MessageUpdate []func(context *Context) MessageReactionAdd []func(context *Context) MessageReactionRemove []func(context *Context) VoiceStateUpdate []func(context *Context) // Administrator is the privileged administrator user with all privilege overrides and full access to all commands. Administrator *discordgo.User // Operator is a slice of operator users with all privilege overrides and access to some restricted commands. Operator []*discordgo.User }
Multiplexer represents the event router.
func (*Multiplexer) IsAdministrator ¶ added in v1.0.7
func (mux *Multiplexer) IsAdministrator(id string) bool
IsAdministrator checks of a user is the system administrator.
func (*Multiplexer) IsOperator ¶ added in v1.0.7
func (mux *Multiplexer) IsOperator(id string) bool
IsOperator checks of a user is an operator.
func (*Multiplexer) MatchRoute ¶
func (mux *Multiplexer) MatchRoute(message string) (*Route, []string)
MatchRoute fuzzy matches a message to a route.
func (*Multiplexer) NewContextMessage ¶
func (mux *Multiplexer) NewContextMessage(session *discordgo.Session, message *discordgo.Message, event interface{}) *Context
NewContextMessage returns pointer to Context generated from a message.
func (*Multiplexer) Route ¶
func (mux *Multiplexer) Route(route *Route) *Route
Route registers a route to the router.
func (*Multiplexer) SessionRegisterHandlers ¶
func (mux *Multiplexer) SessionRegisterHandlers(session *discordgo.Session)
type Route ¶
type Route struct { Pattern string AliasPatterns []string Description string Category *CommandCategory Handler CommandHandler }
Route represents a command route.