plugin

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

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

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 PluginBuilder

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

PluginBuilder holds a plugin to build. This is used to set up a plugin that can be returned using Build

func New

func New(name string) (pb *PluginBuilder)

New creates a new PluginBuilder with a plugin with the given name and empty set of actions

func (*PluginBuilder) Build

func (pb *PluginBuilder) Build() (p *slackscot.Plugin)

Build returns the created Plugin instance

func (*PluginBuilder) WithCommand

func (pb *PluginBuilder) WithCommand(command slackscot.ActionDefinition) *PluginBuilder

WithCommand adds a command to the plugin

func (*PluginBuilder) WithCommandNamespacing

func (pb *PluginBuilder) WithCommandNamespacing() *PluginBuilder

WithCommandNamespacing enables command namespacing for that plugin

func (*PluginBuilder) WithHearAction

func (pb *PluginBuilder) WithHearAction(hearAction slackscot.ActionDefinition) *PluginBuilder

WithHearAction adds an hear action to the plugin

func (*PluginBuilder) WithScheduledAction

func (pb *PluginBuilder) WithScheduledAction(scheduledAction slackscot.ScheduledActionDefinition) *PluginBuilder

WithScheduledAction adds a scheduled action to the plugin

Jump to

Keyboard shortcuts

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