actions

package
v1.49.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package actions provides a fluent API for creating slackscot plugin actions. Typical usages will also involve using the plugin fluent API from github.com/alexandre-normand/slackscot/plugin.

Plugin examples using this API can be found in github.com/alexandre-normand/slackscot/plugins but a quick one could look like:

import (
	"github.com/alexandre-normand/slackscot"
	"github.com/alexandre-normand/slackscot/plugin"
	"github.com/alexandre-normand/slackscot/actions"
)

func newPlugin() (p *slackscot.Plugin) {
	p = plugin.New("maker").
	    WithCommand(actions.NewCommand().
			WithMatcher(func(m *slackscot.IncomingMessage) bool {
				return strings.HasPrefix(m.NormalizedText, "make")
			}).
			WithUsage("make <something>").
			WithDescription("Make the `<something>` you need").
			WithAnswerer(func(m *slackscot.IncomingMessage) *slackscot.Answer {
				return &slackscot.Answer{Text: fmt.Sprintf(":white_check_mark: It's ready for you!")}
			}).
			Build()
		 ).
		WithHearAction(actions.NewHearAction().
			Hidden().
			WithMatcher(func(m *slackscot.IncomingMessage) bool {
				return strings.HasPrefix(m.NormalizedText, "chirp")
			}).
			WithAnswerer(func(m *slackscot.IncomingMessage) *slackscot.Answer {
				return &slackscot.Answer{Text: "Did I hear a bird?"}
			}).
			Build()
	     ).
		WithScheduledAction(actions.NewScheduledAction().
			WithSchedule(schedule.New().Every(time.Monday.string()).AtTime("10:00").Build()).
			WithDescription("Start the week off").
			WithAction(weeklyKickoff).
			Build()
	     ).
		Build()
	return p
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionBuilder

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

ActionBuilder holds the action to build

func NewCommand

func NewCommand() (ab *ActionBuilder)

NewCommand returns a new ActionBuilder to build a new command

func NewHearAction

func NewHearAction() (ab *ActionBuilder)

NewHearAction returns a new ActionBuilder to build a new hear action

func (*ActionBuilder) Build

Build returns the ActionDefinition

func (*ActionBuilder) Hidden

func (ab *ActionBuilder) Hidden() *ActionBuilder

Hidden sets the action to hidden

func (*ActionBuilder) WithAnswerer

func (ab *ActionBuilder) WithAnswerer(answerer slackscot.Answerer) *ActionBuilder

WithAnswerer sets the action's answerer function

func (*ActionBuilder) WithDescription

func (ab *ActionBuilder) WithDescription(description string) *ActionBuilder

WithDescription sets the action description

func (*ActionBuilder) WithDescriptionf

func (ab *ActionBuilder) WithDescriptionf(format string, a ...interface{}) *ActionBuilder

WithDescriptionf sets the action description delegating format and arguments to fmt.Sprintf

func (*ActionBuilder) WithMatcher

func (ab *ActionBuilder) WithMatcher(matcher slackscot.Matcher) *ActionBuilder

WithMatcher sets the action's matcher function

func (*ActionBuilder) WithUsage

func (ab *ActionBuilder) WithUsage(usage string) *ActionBuilder

WithUsage sets the action usage

type ScheduledActionBuilder

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

ScheduledActionBuilder holds the scheduled action to build

func NewScheduledAction

func NewScheduledAction() (sab *ScheduledActionBuilder)

NewScheduledAction returns a new ScheduledActionBuilder to build a new ScheduledActionDefinition

func (*ScheduledActionBuilder) Build

Build returns the ScheduledActionDefinition

func (*ScheduledActionBuilder) WithAction

WithAction sets the action function to run on schedule

func (*ScheduledActionBuilder) WithDescription

func (sab *ScheduledActionBuilder) WithDescription(desc string) *ScheduledActionBuilder

WithDescription sets the scheduled action description

func (*ScheduledActionBuilder) WithDescriptionf

func (sab *ScheduledActionBuilder) WithDescriptionf(format string, a ...interface{}) *ScheduledActionBuilder

WithDescriptionf sets the scheduled action description delegating format and arguments to fmt.Sprintf

func (*ScheduledActionBuilder) WithSchedule

WithSchedule sets the schedule for the scheduled action

Jump to

Keyboard shortcuts

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