Documentation ¶
Index ¶
- Variables
- type Argument
- func (argument *Argument) AsBool() (bool, error)
- func (argument *Argument) AsChannelMentionID() string
- func (argument *Argument) AsDuration() (time.Duration, error)
- func (argument *Argument) AsInt() (int, error)
- func (argument *Argument) AsInt64() (int64, error)
- func (argument *Argument) AsRoleMentionID() string
- func (argument *Argument) AsUserMentionID() string
- func (argument *Argument) Raw() string
- type Arguments
- type Codeblock
- type Command
- type Ctx
- type DefaultRateLimiter
- type ExecutionHandler
- type Middleware
- type ObjectsMap
- type RateLimiter
- type Router
- func (router *Router) GetCmd(name string) *Command
- func (router *Router) Handler() func(*discordgo.Session, *discordgo.MessageCreate)
- func (router *Router) Initialize(session *discordgo.Session)
- func (router *Router) InitializeStorage(name string)
- func (router *Router) RegisterCmd(command *Command)
- func (router *Router) RegisterDefaultHelpCommand(session *discordgo.Session, rateLimiter RateLimiter)
- func (router *Router) RegisterMiddleware(middleware Middleware)
Constants ¶
This section is empty.
Variables ¶
var ( // RegexArguments defines the regex the argument string has to match RegexArguments = regexp.MustCompile("(\"[^\"]+\"|[^\\s]+)") // RegexUserMention defines the regex a user mention has to match RegexUserMention = regexp.MustCompile("<@!?(\\d+)>") // RegexRoleMention defines the regex a role mention has to match RegexRoleMention = regexp.MustCompile("<@&(\\d+)>") // RegexChannelMention defines the regex a channel mention has to match RegexChannelMention = regexp.MustCompile("<#(\\d+)>") // RegexBigCodeblock defines the regex a big codeblock has to match RegexBigCodeblock = regexp.MustCompile("(?s)\\n*```(?:([\\w.\\-]*)\\n)?(.*)```") // RegexSmallCodeblock defines the regex a small codeblock has to match RegexSmallCodeblock = regexp.MustCompile("(?s)\\n*`(.*)`") // CodeblockLanguages defines which languages are valid codeblock languages CodeblockLanguages = []string{}/* 315 elements not displayed */ )
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct {
// contains filtered or unexported fields
}
Argument represents a single argument
func (*Argument) AsChannelMentionID ¶
AsChannelMentionID returns the ID of the mentioned channel or an empty string if it is no mention
func (*Argument) AsDuration ¶
AsDuration parses the given argument into a duration
func (*Argument) AsRoleMentionID ¶
AsRoleMentionID returns the ID of the mentioned role or an empty string if it is no mention
func (*Argument) AsUserMentionID ¶
AsUserMentionID returns the ID of the mentioned user or an empty string if it is no mention
type Arguments ¶
type Arguments struct {
// contains filtered or unexported fields
}
Arguments represents the arguments that may be used in a command context
func ParseArguments ¶
ParseArguments parses the raw string into several arguments
func (*Arguments) AsCodeblock ¶
AsCodeblock parses the given arguments as a codeblock
type Command ¶
type Command struct { Name string Aliases []string Description string Usage string Example string Flags []string IgnoreCase bool SubCommands []*Command RateLimiter RateLimiter Handler ExecutionHandler }
Command represents a simple command
func (*Command) NotifyRateLimiter ¶
NotifyRateLimiter notifies the rate limiter about a new execution and returns false if the user is being rate limited
type Ctx ¶
type Ctx struct { Session *discordgo.Session Event *discordgo.MessageCreate Arguments *Arguments CustomObjects *ObjectsMap Router *Router Command *Command }
Ctx represents the context for a command event
func (*Ctx) RespondEmbed ¶
func (ctx *Ctx) RespondEmbed(embed *discordgo.MessageEmbed) error
RespondEmbed responds with the given embed message
func (*Ctx) RespondText ¶
RespondText responds with the given text message
func (*Ctx) RespondTextEmbed ¶
func (ctx *Ctx) RespondTextEmbed(text string, embed *discordgo.MessageEmbed) error
RespondTextEmbed responds with the given text and embed message
type DefaultRateLimiter ¶
type DefaultRateLimiter struct { Cooldown time.Duration RateLimitedHandler ExecutionHandler // contains filtered or unexported fields }
DefaultRateLimiter represents an internal rate limiter
func (*DefaultRateLimiter) NotifyExecution ¶
func (rateLimiter *DefaultRateLimiter) NotifyExecution(ctx *Ctx) bool
NotifyExecution notifies the rate limiter about a new execution and returns whether or not the execution is allowed
type ExecutionHandler ¶
type ExecutionHandler func(*Ctx)
ExecutionHandler represents a handler for a context execution
type Middleware ¶
type Middleware func(following ExecutionHandler) ExecutionHandler
Middleware defines how a middleware looks like
type ObjectsMap ¶
type ObjectsMap struct {
// contains filtered or unexported fields
}
ObjectsMap wraps a map[string]interface to provide thread safe access endpoints.
func (*ObjectsMap) Delete ¶
func (om *ObjectsMap) Delete(key string)
Delete removes a key-value pair from the map.
func (*ObjectsMap) Get ¶
func (om *ObjectsMap) Get(key string) (interface{}, bool)
Get tries to get a value from the map. If a value was found, the value and true is returned. Else, nil and false is returned.
func (*ObjectsMap) MustGet ¶
func (om *ObjectsMap) MustGet(key string) interface{}
MustGet wraps Get but only returns the value, if found, or nil otherwise.
func (*ObjectsMap) Set ¶
func (om *ObjectsMap) Set(key string, val interface{})
Set sets a value to the map by key.
type RateLimiter ¶
RateLimiter represents a general rate limiter
func NewRateLimiter ¶
func NewRateLimiter(cooldown, cleanupInterval time.Duration, onRateLimited ExecutionHandler) RateLimiter
NewRateLimiter creates a new rate limiter
type Router ¶
type Router struct { Prefixes []string IgnorePrefixCase bool BotsAllowed bool Commands []*Command Middlewares []Middleware PingHandler ExecutionHandler Storage map[string]*ObjectsMap }
Router represents a DiscordGo command router
func (*Router) Handler ¶
func (router *Router) Handler() func(*discordgo.Session, *discordgo.MessageCreate)
Handler provides the discordgo handler for the given router
func (*Router) Initialize ¶
Initialize initializes the message event listener
func (*Router) InitializeStorage ¶
InitializeStorage initializes a storage map
func (*Router) RegisterCmd ¶
RegisterCmd registers a new command
func (*Router) RegisterDefaultHelpCommand ¶
func (router *Router) RegisterDefaultHelpCommand(session *discordgo.Session, rateLimiter RateLimiter)
RegisterDefaultHelpCommand registers the default help command
func (*Router) RegisterMiddleware ¶
func (router *Router) RegisterMiddleware(middleware Middleware)
RegisterMiddleware registers a new middleware