Documentation
¶
Index ¶
- Variables
- func AddCommand(cmd *BasicCommand) bool
- func AddPattern(cmd *PatternCommand) bool
- func AddReactionHandler(cmd *ReactionCommand) bool
- func FormatTime(d time.Time) string
- func MustAddCommand(cmd *BasicCommand)
- func MustAddPattern(cmd *PatternCommand)
- func MustAddReactionHandler(cmd *ReactionCommand)
- func ParseFlags(text string, flagSet *flag.FlagSet) string
- type BasicCommand
- type CommandHandler
- type CommandRegistry
- func (c *CommandRegistry) AddCommand(cmd *BasicCommand) bool
- func (c *CommandRegistry) AddPattern(cmd *PatternCommand) bool
- func (c *CommandRegistry) AddReactionHandler(cmd *ReactionCommand) bool
- func (c CommandRegistry) GetCommand(cmdName string) *BasicCommand
- func (c CommandRegistry) GetCommands() []*BasicCommand
- func (c CommandRegistry) GetConfigurables() []Configurable
- func (c CommandRegistry) GetPattern(patternName string) *PatternCommand
- func (c CommandRegistry) GetPatterns() []*PatternCommand
- func (c CommandRegistry) GetReactionHandler(cmdName string) *ReactionCommand
- func (c CommandRegistry) GetReactionHandlers() []*ReactionCommand
- type Configurable
- type PatternCommand
- type PatternHandler
- type ReactionCommand
- type ReactionHandler
- type RunContext
- type RunResult
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the global registry instance used by default.
var ErrNilMessage = errors.New("message was nil")
Functions ¶
func AddCommand ¶
func AddCommand(cmd *BasicCommand) bool
AddCommand adds a command to the default registry.
func AddPattern ¶
func AddPattern(cmd *PatternCommand) bool
AddPattern adds a pattern command to the default registry.
func AddReactionHandler ¶
func AddReactionHandler(cmd *ReactionCommand) bool
AddReactionHandler adds a reaction command to the default registry.
func FormatTime ¶
FormatTime formats a given time.Time instance as UTC in a simple format.
func MustAddCommand ¶
func MustAddCommand(cmd *BasicCommand)
MustAddCommand adds a command to the default registry or panics.
func MustAddPattern ¶
func MustAddPattern(cmd *PatternCommand)
MustAddPattern adds a pattern command to the default registry or panics.
func MustAddReactionHandler ¶
func MustAddReactionHandler(cmd *ReactionCommand)
AddReactionHandler adds a reaction command to the default registry or panics.
Types ¶
type BasicCommand ¶
type BasicCommand struct { // Name is the name of the command and how it is invoked. // TODO: Support aliases. Name string // Description is a short description of the command for help output. Description string // Icon is an emoji (no ":" delimiters) to use for this command in help // output. Icon string // Handler is a CommandHandler invoked when a command invocation for Name is // performed by a user. Handler CommandHandler }
BasicCommand describes a basic bot command that can be invoked on demand with "!<cmd name>". Remaining text is passed to the command handler so that it can be parsed further (e.g. to have CLI options for the command).
type CommandHandler ¶
type CommandHandler interface { Configurable // Run is called for command matches with the text that appeared in the // message after the command name and a run context. Run(text string, runCtx RunContext) (RunResult, error) }
CommandHandler describes a configurable that expects to be run with some text when the associated basic command is invoked.
type CommandRegistry ¶
type CommandRegistry struct {
// contains filtered or unexported fields
}
CommandRegistry describes a collection of basic commands, pattern commands and reaction handlers. It is not thread safe - do not use concurrently.
func NewRegistry ¶
func NewRegistry() *CommandRegistry
NewRegistry constructs a new CommandRegistry.
func (*CommandRegistry) AddCommand ¶
func (c *CommandRegistry) AddCommand(cmd *BasicCommand) bool
AddCommand adds a basic command to the registry. It returns false if the command is invalid or if the name was already registered.
func (*CommandRegistry) AddPattern ¶
func (c *CommandRegistry) AddPattern(cmd *PatternCommand) bool
AddPattern adds a pattern command to the registry. It returns false if the pattern command is invalid or if the pattern name was already registered.
func (*CommandRegistry) AddReactionHandler ¶
func (c *CommandRegistry) AddReactionHandler(cmd *ReactionCommand) bool
AddReactionHandler adds a reaction handler to the registry. It returns false if the reaction command is invalid or if the reaction command name was already registered.
func (CommandRegistry) GetCommand ¶
func (c CommandRegistry) GetCommand(cmdName string) *BasicCommand
GetCommand returns the BasicCommand registered with the given cmdName (or nil if there was no such cmd).
func (CommandRegistry) GetCommands ¶
func (c CommandRegistry) GetCommands() []*BasicCommand
GetCommands returns a list of the registered BasicCommands.
func (CommandRegistry) GetConfigurables ¶
func (c CommandRegistry) GetConfigurables() []Configurable
GetConfigurables returns a list of all of the configurables in the registry. This includes basic commands, patterns and reaction handlers.
func (CommandRegistry) GetPattern ¶
func (c CommandRegistry) GetPattern(patternName string) *PatternCommand
GetPattern returns the Pattern Command registered with the given patternName (or nil if there was no such pattern).
func (CommandRegistry) GetPatterns ¶
func (c CommandRegistry) GetPatterns() []*PatternCommand
GetPatterns returns a list of the registered PatternCommands.
func (CommandRegistry) GetReactionHandler ¶
func (c CommandRegistry) GetReactionHandler(cmdName string) *ReactionCommand
GetReactionHandler returns the Reaction Command registered with the given cmdName (or nil if there was no such handler).
func (CommandRegistry) GetReactionHandlers ¶
func (c CommandRegistry) GetReactionHandlers() []*ReactionCommand
GetReactionHandlers returns a list of the registered ReactionCommands.
type Configurable ¶
type Configurable interface { // Configure is called with a log and config instance once they are available and // before any Run calls are made. Configure(log *logrus.Logger, c *config.Config) error }
Configurable is a common interface for anything (cmd, pattern cmd, reaction handler, etc) that can be configured with a logger and config instance.
type PatternCommand ¶
type PatternCommand struct { // Name of the PatternCommand. NOTE: used in help output. Name string // PatternHandler to invoke with matches. Handler PatternHandler // Pattern regexp. Messages matching this pattern will have the Handler invoked. Pattern *regexp.Regexp }
PatternCommand describes a pattern handler and its associated pattern. Any messages that match the pattern will have the handler's Run function invoked with all of the submatches.
type PatternHandler ¶
type PatternHandler interface { Configurable // Run accepts a list of all of the submatches from a regexp and a runCtx. Run(allSubmatches [][]string, runCtx RunContext) (RunResult, error) }
PatternHandler describes a configurable that expects to be run with all submatches of a regex pattern.
type ReactionCommand ¶
type ReactionCommand struct { // Name of the reaction handler. Used in help, should describe purpose of handler. Name string // Handler is invoked when reactions are added/removed. Handler ReactionHandler }
ReactionCommand describes a named reacton handler that is run when reactions are added/removed.
type ReactionHandler ¶
type ReactionHandler interface { Configurable // Run is called when a reaction is added or removed. Run(reaction *slack.Reaction, runCtx RunContext) error }
ReactionHandler describes a configurable that has its Run function called when reactions are added/removed.
type RunContext ¶
RunContext binds together all of the contextual information a botcmd's Run function might need. Typically this is a message instance, a handle to storage, and a handle to a slack client to interact with.
Directories
¶
Path | Synopsis |
---|---|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |