bot

package
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(cfg config.Logger)

InitLogger provides logger instance for the given config

Types

type BaseCommand

type BaseCommand struct {
	client.SlackClient
}

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

type Bot

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

Bot is the main object which is holding the connection to Slack and all possible commands it also registers the listener and handles topics like authentication and logging

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) HandleMessage

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

HandleMessage is the 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

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

Init establishes the slack connection and load allowed users

func (*Bot) ProcessMessage added in v2.2.4

func (b *Bot) ProcessMessage(message msg.Message, fromUserContext bool)

ProcessMessage process the incoming message and respond appropriately

func (*Bot) Run added in v2.2.3

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

Run is blocking method to handle new incoming events...from different sources

type Category

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) GetCommandNames added in v2.3.1

func (c *Commands) GetCommandNames() []string

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

func (*Commands) RunWithName added in v2.3.1

func (c *Commands) RunWithName(message msg.Message) (bool, string)

RunWithName executes the first matched command and return the command name if there was a match

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 {
	// GetHelp 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

type Runnable added in v2.3.0

type Runnable interface {
	RunAsync(ctx *util.ServerContext)
}

Runnable indicates that the command executes a go function

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