feature

package
v0.0.0-...-bf34452 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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 NewRegistry

func NewRegistry() *Registry

NewRegistry works as advertised.

func (*Registry) CommandInterceptors

func (r *Registry) CommandInterceptors() []CommandInterceptor

CommandInterceptors return the execution interceptors.

func (*Registry) GetExecutorByType

func (r *Registry) GetExecutorByType(commandType int) Executor

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

func (r *Registry) GetInvokableFeatureNames() []string

GetInvokableFeatureNames returns invokable feature names.

func (*Registry) GetParserByName

func (r *Registry) GetParserByName(name string) Parser

GetParserByName returns the feature with the given name, or null if no such feature exists.

func (*Registry) IsInvokable

func (r *Registry) IsInvokable(name string) bool

IsInvokable tests that the given string is a user-invokable command. Will pass whether the string is prefixed by a ? or not.

func (*Registry) Register

func (r *Registry) Register(feature Feature) error

Register attempts to register the given feature by name. If a feature with the given name exists, then error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL