bot

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotRegistered is the default reply when rights don't match
	NotRegistered = "I'm sorry, but you are not allowed to use this command."

	// UserRightUser is the default user right for any user
	UserRightUser = "user"
	// UserRightAdmin is the user right for admins who can use some hidden features
	UserRightAdmin = "admin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Crons        map[string]*CronTask
	AllowedUsers []User
	// contains filtered or unexported fields
}

Bot is a wrapper for the authentification, slack client, all commands, running crons and users allowed to schedule crons

func NewBot

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

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

func (*Bot) AddSchedule

func (b *Bot) AddSchedule(schedule *Schedule) string

AddSchedule is used to add a new schedule via a cron

func (*Bot) DeleteSchedule

func (b *Bot) DeleteSchedule(name string)

DeleteSchedule removes a schedule from the active crons and from the schedule list

func (*Bot) GetAllowedUser

func (b *Bot) GetAllowedUser(slackUser string) User

GetAllowedUser returns all users which are allowed to handle schedules

func (*Bot) GetTasksForChannel

func (b *Bot) GetTasksForChannel(channel string) []*CronTask

GetTasksForChannel is returning all tasks which are active in the given channel

func (*Bot) GetUserFile

func (b *Bot) GetUserFile() string

GetUserFile returns the path to the user file where the allowed users are stored

func (*Bot) Init

func (b *Bot) Init(config *config.Config) (err error)

Init establishes the slack connection, loads slack and user information

func (*Bot) InitTasks

func (b *Bot) InitTasks()

InitTasks initializes all cron commands

func (*Bot) IsValidSchedule

func (b *Bot) IsValidSchedule(spec string) bool

IsValidSchedule checks if a schedule can be parsed

func (*Bot) NewSchedule

func (b *Bot) NewSchedule(project string, time string, command string, channel string, user User) *Schedule

NewSchedule holds all information for creating a new schedule

func (*Bot) ReloadSlackChannels

func (b *Bot) ReloadSlackChannels()

ReloadSlackChannels handles updating client.Channels, so new channels will be added within an hour

func (*Bot) ReloadSlackUsers

func (b *Bot) ReloadSlackUsers()

ReloadSlackUsers handles updating the client.Users map, so new slack users will be added within 24 hours

func (*Bot) ReloadUserFile

func (b *Bot) ReloadUserFile()

ReloadUserFile handles updating the user file every 10 seconds

type Command

type Command interface {
	// return true in case command did a response
	Execute(ctx context.Context, b *Bot, eventText string, event *slack.MessageEvent, user User) bool

	// return true in case command can be scheduled and passed a basic check
	IsValid(b *Bot, command string) bool

	// each command has a name
	GetName() string

	// information on how to use the command with examples
	GetHelp() []Help
}

Command is the main command struct which needs to provide the actual executed action, validation, a name and a help for the user

type Commands

type Commands struct {
	Commands []Command
}

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

func (*Commands) GetHelp

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

GetHelp returns the help for ALL included commands

type CronTask

type CronTask struct {
	Name     string
	Schedule *Schedule
	Cron     *cron.Cron
}

CronTask is a wrapper for the scheduled command

type Help

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

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

type Schedule

type Schedule struct {
	Project  string
	Creator  User
	CronTime string
	Channel  string
	Command  string
}

Schedule is a wrapper for the command to be scheduled

type User

type User struct {
	Name  string
	Right string
}

User is a wrapper with the user name and right

Jump to

Keyboard shortcuts

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