command

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Answer answer

Functions

This section is empty.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command is a bot command.

func New

func New(text string, handler Handler, options ...Options) (command Command, _ error)

New creates a new Command with the given text, non-nil handler, and optional Options.

func (*Command) Description

func (c *Command) Description() string

func (*Command) Handler

func (c *Command) Handler() Handler

func (*Command) SetHandler

func (c *Command) SetHandler(h Handler)

func (*Command) Text

func (c *Command) Text() string

type ErrorHandler added in v0.2.0

type ErrorHandler func(err error, joinErrs ...error)

ErrorHandler is an error handler. The first parameter is an error that causes the handling. The rest parameters are errors that have been occurred before and have not been processed because of the first error.

type Handler

type Handler func(ctx context.Context, req *Request) (Responser, error)

func NewAddReactionAndReplyTextHandler added in v0.2.0

func NewAddReactionAndReplyTextHandler(
	client core.Client,
	reaction, message string,
) Handler

NewAddReactionAndReplyTextHandler returns a new Handler that adds the given reaction to the user message with the incoming command and sends the given message to a new thread for the user message.

func NewInvalidUserCommandHandler

func NewInvalidUserCommandHandler(client core.Client, err error) Handler

NewInvalidUserCommandHandler returns a new Handler in case the command is invalid.

func NewLongRunningHandler added in v0.2.0

func NewLongRunningHandler(
	client core.Client,
	wait time.Duration,
	do LongTask,
	errorHandler ...ErrorHandler,
) Handler

NewLongRunningHandler returns a new Handler that runs a long task. It does the following:

  • runs the long task in a separate goroutine where the checks described below take place;
  • adds the "🤖" reaction to the user command.

Checks:

  • if the given context.Context is cancelled, or a deadline is expired, or a timeout is elapsed, then it changes the reaction from "🤖" to "❌" and replies with error message;
  • if the task is failed, then it changes the reaction from "🤖" to "❌"
  • if the task is done, then it changes the reaction from "🤖" to "✅"; and replies with the error message;
  • otherwise, it waits the given duration and runs the checks again.

If requests after the checks are failed, then it calls the given ErrorHandler, if any, otherwise, it does nothing.

func NewNotFoundCommandHandler

func NewNotFoundCommandHandler(client core.Client) Handler

NewNotFoundCommandHandler returns a new Handler in case the command is not found.

func (Handler) CommandPost

func (h Handler) CommandPost(ctx context.Context, req *Request) (Responser, error)

type List

type List []Command

func (List) Commands

func (ls List) Commands() []api.Command

Commands returns the slice of the underlying core.Command's.

func (List) HandlerLookup

func (ls List) HandlerLookup(
	ctx context.Context,
	client core.Client,
	userCommandText api.Command,
) (context.Context, Handler)

HandlerLookup is looking for Handler corresponding the given core.Command. It returns:

type LongTask added in v0.2.0

type LongTask func(
	ctx context.Context,
	client core.Client,
	req *Request,
	chDone chan<- struct{},
	chErr chan<- error,
)

LongTask is a function that runs a long task.

If it is tied to cycles, it should check context.Context.Done and send the error to chErr:

select {
case <- ctx.Done():
	chErr <- ctx.Err()
	return
default:
	...
}

If the task is completed successfully, it should send an empty struct to chDone:

	chDone <- struct{}{}
 return

If the task is completed with an error, it should send the error to chErr:

	chErr <- err
 return

type NoContentResponse

type NoContentResponse = api.CommandPostNoContent

type Options

type Options struct {
	Description           string
	AllowLongCommand      bool
	AllowUnsupportedChars bool
}

type Request

type Request = api.WebhookRequest

type Responser

type Responser = api.CommandPostRes

type Variables

type Variables map[string]string

func VariablesFromContext

func VariablesFromContext(ctx context.Context) (vars Variables, found bool)

VariablesFromContext gets Variables from the given context.Context, if any.

Jump to

Keyboard shortcuts

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