bot

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger added in v1.6.3

func InitLogger(cfg config.Logger)

InitLogger provides logger instance for the given config

Types

type BaseCommand added in v1.6.3

type BaseCommand struct {
	client.SlackClient
}

base struct which is handy for all commands, as a direct Slack communication is possible

type Bot added in v1.6.0

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

func NewBot

func NewBot(cfg config.Config, slackClient *client.Slack, commands *Commands) *Bot

NewBot created main Bot struct which holds the slack connection and dispatch messages to commands

func (*Bot) DisconnectRTM added in v1.6.0

func (b *Bot) DisconnectRTM() error

DisconnectRTM will do a clean shutdown and kills all connections

func (*Bot) HandleMessage added in v1.6.4

func (b *Bot) HandleMessage(message *slack.MessageEvent)

entry point for incoming slack messages: - checks if the message is relevant (direct message to bot or mentioned via @bot) - is the user allowed to interact with the bot? - find the matching command and execute it

func (*Bot) Init added in v1.6.0

func (b *Bot) Init() (err error)

Init establishes the slack connection and load allowed users

func (*Bot) ListenForMessages added in v1.6.4

func (b *Bot) ListenForMessages(ctx *util.ServerContext)

ListenForMessages is blocking method to handle new incoming events

type Category added in v1.6.3

type Category struct {
	Name        string
	Description string
	HelpURL     string
}

Category of Help entries. -> Groups command in help command by "Jenkins", "Pull request" etc

type Command

type Command interface {
	GetMatcher() matcher.Matcher
}

Command is the main command struct which needs to provide the matcher and the actual executed action

type Commands

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

Commands is a wrapper of a list of commands. Only the first matched command will be executed

func (*Commands) AddCommand

func (c *Commands) AddCommand(commands ...Command)

AddCommand registers a command to the command list

func (*Commands) Count

func (c *Commands) Count() int

Count the registered/valid commands

func (*Commands) GetHelp

func (c *Commands) GetHelp() []Help

GetHelp returns the help for ALL included commands

func (*Commands) Merge

func (c *Commands) Merge(commands Commands)

Merge two list of commands

func (*Commands) Run

func (c *Commands) Run(message msg.Message) bool

Run executes the first matched command and return true in case one command matched

type Conditional

type Conditional interface {
	IsEnabled() bool
}

Conditional checks if the command should be activated. E.g. is dependencies are not present or it's disabled in the config

type Help

type Help struct {
	Command     string
	Description string
	HelpURL     string
	Category    Category
	Examples    []string
}

Help command can provide help objects which are searchable by keywords

func (*Help) GetKeywords

func (h *Help) GetKeywords() []string

GetKeywords crates a string slice of help keywords -> used by fuzzy search

type HelpProvider

type HelpProvider interface {
	// each command should provide information, like a description or examples
	GetHelp() []Help
}

HelpProvider can be provided by a command to add information within "help" command

Directories

Path Synopsis
Package tester provides functionality to test the bot against a fake slack server
Package tester provides functionality to test the bot against a fake slack server

Jump to

Keyboard shortcuts

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