go-sarah: github.com/oklahomer/go-sarah/examples/simple/plugins/morning Index | Files

package morning

import "github.com/oklahomer/go-sarah/examples/simple/plugins/morning"

Package morning provides example code to setup sarah.CommandProps with relatively complex matching function.

This setting does not simply provide regular expression via CommandPropsBuilder.MatchPattern, but instead provide whole matching function to implement complex matcher.

Index

Package Files

props.go

Variables

var SlackProps = sarah.NewCommandPropsBuilder().
    BotType(slack.SLACK).
    Identifier("morning").
    InstructionFunc(func(input *sarah.HelpInput) string {
        hour := time.Now().Hour()
        if 12 < hour {

            return ""
        }

        return "Input .morning to greet."
    }).
    MatchFunc(func(input sarah.Input) bool {

        match := strings.HasPrefix(input.Message(), ".morning")
        if !match {
            return false
        }

        hour := time.Now().Hour()
        return hour >= 0 && hour < 12
    }).
    Func(func(_ context.Context, input sarah.Input) (*sarah.CommandResponse, error) {
        return slack.NewResponse(input, "Good morning.")
    }).
    MustBuild()

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

Package morning imports 5 packages (graph). Updated 2020-09-27. Refresh now. Tools for package owners.