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 Bot
- type Command
- type Config
- type Ctx
- type DefaultRateLimiter
- type ExecutionHandler
- type Middleware
- type ObjectsMap
- type Options
- type RateLimiter
- type Router
- func (router *Router) GetCommand(name string) *Command
- func (router *Router) Handler() func(*dgo.Session, *dgo.MessageCreate)
- func (router *Router) Initialise(session *dgo.Session)
- func (router *Router) InitialiseStorage(name string)
- func (router *Router) RegisterCommand(command *Command)
- 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+)>") )
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
type Bot ¶
type Bot struct { Name string `json:"name"` Version string `json:"version"` Description string `json:"description"` GuildConfigs map[string]*Config UserConfigs map[string]*Config // contains filtered or unexported fields }
Bot represents a collection of commands
func (*Bot) AddCommands ¶
type Command ¶
type Command struct { Name string Description string Aliases []string Examples []string Tags []string IgnoreCase bool SubCommands []*Command RateLimiter RateLimiter Handler ExecutionHandler }
Command represents a simple command
func (*Command) GetSubCommand ¶
GetSubCommand returns the sub command with the given name if it exists
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 *dgo.Session Event *dgo.MessageCreate Arguments *Arguments CustomObjects *ObjectsMap Router *Router Command *Command }
Ctx represents the context for a command event
func (*Ctx) RespondEmbed ¶
RespondEmbed responds with the given embed message
func (*Ctx) RespondText ¶
RespondText responds with the given text message
func (*Ctx) RespondTextEmbed ¶
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 Options ¶
type Options struct { Name string `json:"name"` Description string `json:"description"` Version string `json:"version"` Prefix string `json:"prefix"` IgnoreDMs bool `json:"ignore_dms"` IgnoreMentions bool `json:"ignore_mentions"` IgnorePrefixCase bool `json:"ignore_prefix_case"` DeleteCommandMessage bool `json:"delete_command_message"` Token string `json:"token"` }
Options provides a set of options for initialising Discord bots
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 Commands []*Command Middlewares []Middleware PingHandler ExecutionHandler Storage map[string]*ObjectsMap }
Router represents a DiscordGo command router
func (*Router) GetCommand ¶
GetCommand returns the command with the given name if it exists
func (*Router) Handler ¶
func (router *Router) Handler() func(*dgo.Session, *dgo.MessageCreate)
Handler provides the dgo handler for the given router
func (*Router) Initialise ¶
Initialise initializes the message event listener
func (*Router) InitialiseStorage ¶
InitialiseStorage initializes a storage map
func (*Router) RegisterCommand ¶
RegisterCommand registers a new command
func (*Router) RegisterMiddleware ¶
func (router *Router) RegisterMiddleware(middleware Middleware)
RegisterMiddleware registers a new middleware