Documentation ¶
Index ¶
- type CommandInterceptor
- type Executor
- type Feature
- type Parser
- type Registry
- func (r *Registry) CommandInterceptors() []CommandInterceptor
- func (r *Registry) GetExecutorByType(commandType int) Executor
- func (r *Registry) GetInitialLoadFns() []func(api.DiscordSession) error
- func (r *Registry) GetInvokableFeatureNames() []string
- func (r *Registry) GetParserByName(name string) Parser
- func (r *Registry) IsInvokable(name string) bool
- func (r *Registry) Register(feature Feature) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandInterceptor ¶
type CommandInterceptor interface {
Intercept(*model.Command, api.DiscordSession) (*model.Command, error)
}
CommandInterceptor allows features to examine and replace the parsed command. For instance, moderation and command ACLs can be implemented this way.
type Executor ¶
type Executor interface { // The command type to execute. GetType() int // Execute the given command, for the session and channel name provided. Execute(api.DiscordSession, model.Snowflake, *model.Command) // Whether the command cannot be executed in private channels. PublicOnly() bool }
Executor actually performs the given action based on the given command.
type Feature ¶
type Feature interface { // Returns all parsers associated with this feature. Parsers() []Parser // FallbackParser returns the parser to execute if no other parser is // recognized by name. There can only be one system-wide. FallbackParser() Parser // CommandInterceptors returns the command interceptors for this feature. CommandInterceptors() []CommandInterceptor // Returns all executors associated with this feature. Executors() []Executor // A callback that allows the feature to perform work before the normal // command flow begins. OnInitialLoad(s api.DiscordSession) error }
Feature encapsulates all of the behavior necessary for a built-in feature.
type Parser ¶
type Parser interface { // The user-facing name of the command. Must be unique. GetName() string // Parses the given split command line. Parse([]string, *discordgo.MessageCreate) (*model.Command, error) // The user-facing help text for the given name. `command` is passed as an arg // so fallback parsers can provide custom help text. HelpText(command string) (string, error) }
Parser is used to multiplex on builtin ?* commands, and ensure that the commands are correctly formatted.
type Registry ¶
type Registry struct { // FallbackFeature is the feature that should attempt to parse the command // line if no named feature matches. FallbackParser Parser // contains filtered or unexported fields }
Registry stores all of the features.
func (*Registry) CommandInterceptors ¶
func (r *Registry) CommandInterceptors() []CommandInterceptor
CommandInterceptors return the execution interceptors.
func (*Registry) GetExecutorByType ¶
GetExecutorByType returns the executor with the given type, or null if no feature handles this type.
func (*Registry) GetInitialLoadFns ¶
func (r *Registry) GetInitialLoadFns() []func(api.DiscordSession) error
GetInitialLoadFns return the initial load functions for each feature
func (*Registry) GetInvokableFeatureNames ¶
GetInvokableFeatureNames returns invokable feature names.
func (*Registry) GetParserByName ¶
GetParserByName returns the feature with the given name, or null if no such feature exists.
func (*Registry) IsInvokable ¶
IsInvokable tests that the given string is a user-invokable command. Will pass whether the string is prefixed by a ? or not.