command

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPrivateMessageFromContext added in v0.5.0

func GetPrivateMessageFromContext(ctx context.Context) *twitch.PrivateMessage

Types

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 and execute it, if find one.

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

type Filter func(Handler) Handler

Filter represents a function that is called after all middlewares and before a command. It is used for validation.

func Cooldown added in v0.7.0

func Cooldown(cooldown time.Duration) Filter

Cooldown stops from calling a command, when not enough time passed.

func HasRole

func HasRole(roles []string) Filter

type Handler added in v0.5.0

type Handler func(ctx context.Context, args []string, chatClient chatClient) error

Handler represents a function for a command.

var Ping Handler = func(ctx context.Context, _ []string, chatClient chatClient) error {
	privMsg := GetPrivateMessageFromContext(ctx)
	chatClient.Say(privMsg.Channel, fmt.Sprintf("Pong! @%s", privMsg.User.DisplayName))

	return nil
}

type Middleware added in v0.5.0

type Middleware func(Handler) Handler

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(logger *zap.Logger) Middleware

Jump to

Keyboard shortcuts

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