Documentation
¶
Index ¶
- Variables
- type Command
- type ErrorHandler
- type Handler
- func NewAddReactionAndReplyTextHandler(client core.Client, reaction, message string) Handler
- func NewInvalidUserCommandHandler(client core.Client, err error) Handler
- func NewLongRunningHandler(client core.Client, wait time.Duration, do LongTask, ...) Handler
- func NewNotFoundCommandHandler(client core.Client) Handler
- type List
- type LongTask
- type NoContentResponse
- type Options
- type Request
- type Responser
- type Variables
Constants ¶
This section is empty.
Variables ¶
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 (*Command) Description ¶
func (*Command) SetHandler ¶
type ErrorHandler ¶ added in v0.2.0
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 ¶
func NewAddReactionAndReplyTextHandler ¶ added in v0.2.0
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 ¶
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 ¶
NewNotFoundCommandHandler returns a new Handler in case the command is not found.
type List ¶
type List []Command
func (List) Commands ¶
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:
- the given context if the command has no variables, otherwise, a derived context.Context with Variables;
- NewInvalidUserCommandHandler if the command is invalid, or NewNotFoundCommandHandler if the command is not found, otherwise corresponding Handler.
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 Request ¶
type Request = api.WebhookRequest
type Responser ¶
type Responser = api.CommandPostRes