guess

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package guess provides example code to setup stateful command.

This command returns sarah.UserContext as part of sarah.CommandResponse until user inputs correct number. As long as sarah.UserContext is returned, the next input from the same user is fed to the function defined in sarah.UserContext. When user guesses right number or input .abort, the context is removed and user is free to input next desired command.

This example uses in-memory storage to store user context. See https://github.com/oklahomer/go-sarah-rediscontext to use external storage.

Index

Constants

This section is empty.

Variables

View Source
var SlackProps = sarah.NewCommandPropsBuilder().
	BotType(slack.SLACK).
	Identifier("guess").
	InputExample(".guess").
	MatchFunc(func(input sarah.Input) bool {
		return strings.HasPrefix(strings.TrimSpace(input.Message()), ".guess")
	}).
	Func(func(ctx context.Context, input sarah.Input) (*sarah.CommandResponse, error) {

		rand.Seed(time.Now().UnixNano())
		answer := rand.Intn(10)

		return slack.NewStringResponseWithNext("Input number.", func(c context.Context, i sarah.Input) (*sarah.CommandResponse, error) {
			return guessFunc(c, i, answer)
		}), nil
	}).
	MustBuild()

SlackProps is a pre-built guess command properties for Slack.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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