Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶ added in v0.8.0
type Context struct {
CommandName string // CommandName represents a name of a current command.
PrivMsg *twitch.PrivateMessage // PrivMsg represents metadata of the sent message.
Logger *zap.Logger // Logger records and captures events.
}
Context represents a struct with helping fields for validating and recording a command workflow.
func NewContext ¶ added in v0.8.0
NewContext returns a new instance of a struct with metadata and a logger to a command lifecycle.
func UnwrapContext ¶ added in v0.8.0
UnwrapContext returns Command Context from a context.
type Controller ¶ added in v0.3.1
type Controller struct {
// contains filtered or unexported fields
}
Controller represents a manager to commands.
func NewController ¶
func NewController(prefix string, logger *zap.Logger) *Controller
NewController creates an instance of Controller for managing commands.
func (*Controller) AddCommand ¶ added in v0.3.1
func (c *Controller) AddCommand(commandName string, handler Handler, filters []Filter)
AddCommand adds a command handler to a map in Controller. The handler is being wrapped with filters and middlewares, before it is added to commands. The order of functions in wrapped handler goes like this: Middlewares -> Filters -> Handler.
func (*Controller) CallCommand ¶ added in v0.3.1
func (c *Controller) CallCommand(ctx context.Context, userMessage string, privateMessage twitch.PrivateMessage, chatClient chatClient)
CallCommand searches for a command in the commands. If the method finds one, it sets up a context and executes the command.
func (*Controller) UseWith ¶ added in v0.5.0
func (c *Controller) UseWith(middleware Middleware)
UseWith adds a middleware to a middlewares. The order when a middleware is added matters.
type Filter ¶ added in v0.5.0
Filter represents a function that is called after all middlewares and before a command. It is used for validation.
type Handler ¶ added in v0.5.0
Handler represents a function for a command.
var Ping Handler = func(ctx context.Context, _ []string, chatClient chatClient) error { _, span := tracer.Start(ctx, "ping") defer span.End() cmdCtx := UnwrapContext(ctx) chatClient.Say(cmdCtx.PrivMsg.Channel, fmt.Sprintf("Pong! @%s", cmdCtx.PrivMsg.User.DisplayName)) span.SetStatus(codes.Ok, "successfully sent a ping") return nil }
type Middleware ¶ added in v0.5.0
Middleware represents a function that is called before any filters and a handler. It can be used for logging handler's parameters, error handling or measure how much time a command took to execute.
func ErrorHandler ¶ added in v0.5.0
func ErrorHandler() Middleware
ErrorHandler takes care of returned errors (if it's present) from a executed command.