skit: github.com/spy16/skit Index | Files

package skit

import "github.com/spy16/skit"

Index

Package Files

command.go handler.go simple.go skit.go utils.go

func CaptureAll Uses

func CaptureAll(regEx *regexp.Regexp, s string) map[string]interface{}

CaptureAll matches s with the regex and returns all named capture values. Returns nil if the s was not a match.

func ParseExprs Uses

func ParseExprs(exprs []string) ([]*regexp.Regexp, error)

ParseExprs parses given list of regular expressions and returns the compiled objects.

func Render Uses

func Render(tpl template.Template, data interface{}) (string, error)

Render executes the template with data and returns the rendered string.

func RenderAll Uses

func RenderAll(tpls []template.Template, data interface{}) ([]string, error)

RenderAll executes all templates passed in with the data and returns the rendered strings. Returns nil and an error on first execution failure.

func RenderString Uses

func RenderString(tplStr string, data interface{}) (string, error)

RenderString creates template from tplStr and executes the template with data and returns the rendered string.

type Command Uses

type Command struct {
    Timeout     time.Duration
    RedirectErr bool
    WorkingDir  string
    // contains filtered or unexported fields
}

Command runs configured command when the message matches the regular expressions.

func CommandHandler Uses

func CommandHandler(cmd string, args []string, patterns []string) (*Command, error)

CommandHandler executes a configured command when input message matches one of the regex patterns. cmd and args both will be parsed as golang text templates. Named captures from pattern that matches the input message will be used as data for rendering command name and every argument.

func (*Command) Handle Uses

func (cmd *Command) Handle(ctx context.Context, sk *Skit, ev *MessageEvent) bool

Handle executes the command when the message matches the regular expressions.

type Handler Uses

type Handler interface {

    // Handle should return true if the message event was handled by it. If this
    // function returns false, skit will execute the next Handler available and
    // so on.
    Handle(ctx context.Context, sk *Skit, ev *MessageEvent) bool
}

Handler is responsible for handling slack message events.

func SimpleHandler Uses

func SimpleHandler(tplStr string, exps ...string) (Handler, error)

SimpleHandler responds with a simple message if the input message matches one of the regular expressions. The message (argument tplStr) can be a golang text template. Named captures from the regex that matches the input message will be used as data for rendering the message template.

type HandlerFunc Uses

type HandlerFunc func(ctx context.Context, sk *Skit, ev *MessageEvent) bool

HandlerFunc implements Handler interface using function type.

func (HandlerFunc) Handle Uses

func (hf HandlerFunc) Handle(ctx context.Context, sk *Skit, ev *MessageEvent) bool

Handle dispatches the call to the wrapped function.

type Logger Uses

type Logger interface {
    Debugf(msg string, args ...interface{})
    Infof(msg string, args ...interface{})
    Warnf(msg string, args ...interface{})
    Errorf(msg string, args ...interface{})
}

Logger implementation is responsible for providing logging functions.

type MessageEvent Uses

type MessageEvent slack.MessageEvent

MessageEvent represents a slack message event.

type Skit Uses

type Skit struct {
    Logger

    NoHandler          template.Template
    RouteGroupMessages bool
    // contains filtered or unexported fields
}

Skit represents an instance of skit.

func New Uses

func New(token string, logger Logger) *Skit

New initializes an instance of skit with default event handlers.

func (*Skit) Listen Uses

func (sk *Skit) Listen(ctx context.Context) error

Listen connects to slack with the given configurations and starts the event loop

func (*Skit) Register Uses

func (sk *Skit) Register(name string, handler Handler)

Register a handler to handle message events. Handlers will be executed in the order they are registered in.

func (*Skit) SendText Uses

func (sk *Skit) SendText(ctx context.Context, msg string, channel string) error

SendText sends the given message to the channel.

Package skit imports 11 packages (graph). Updated 2018-12-11. Refresh now. Tools for package owners.