bot

package
v0.0.0-...-62de630 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfigFromBytes

func LoadConfigFromBytes(data []byte, conf *Config) error

LoadConfigFromBytes loads config from a raw []byte TOML file

func LoadConfigFromEnvVars

func LoadConfigFromEnvVars(ctx context.Context, prefix string, conf *Config) error

LoadConfigFromEnvVars reads config from env vars and maps that into the given Config struct.

func LoadConfigFromFile

func LoadConfigFromFile(filepath string, conf *Config) error

LoadConfigFromFile reads a TOML file and unmarshals that config into the given Config struct.

func LoadConfigFromFileAndEnvVars

func LoadConfigFromFileAndEnvVars(ctx context.Context, envVarsPrefix, filepath string, conf *Config) error

LoadConfigFromFileAndEnvVars reads config and maps that into the given Config in the following order: 1. Loads from Toml file. 2. Loads from env vars. Note: env var values will overwrite TOML file values.

func WakeUp

func WakeUp(_ context.Context, conf Config, bus EventBus.Bus) error

WakeUp wakes up the bot.

Types

type Config

type Config struct {
	Bot                 ConfigBot      `env:",prefix=BOT_"`
	Staff               ConfigStaff    `env:",prefix=STAFF_"`
	Channels            ConfigChannels `env:",prefix=CHANNELS_"`
	Links               ConfigLinks    `env:",prefix=LINKS_"`
	Twitter             ConfigTwitter  `env:",prefix=TWITTER_"`
	TwitterContestToken string         `env:"TWITTER_CONTEST_TOKEN"`
	TwitterContestURL   string         `env:"TWITTER_CONTEST_URL"`
	NewRelicLicenseKey  string         `env:"NEW_RELIC_LICENSE_KEY"`
	Debug               bool           `env:"DEBUG"`
	Version             string         `env:"VERSION"`
}

type ConfigBot

type ConfigBot struct {
	ID         string          `env:"ID,required"`
	UserID     string          `env:"USER_ID,required"`
	Name       string          `env:"NAME,required"`
	UserToken  string          `env:"USER_TOKEN,required"`
	AdminToken string          `env:"ADMIN_TOKEN,required"`
	Server     ConfigBotServer `env:",prefix=SERVER_"`
}

type ConfigBotServer

type ConfigBotServer struct {
	Port          int    `env:"PORT,default=8080"`
	SigningSecret string `env:"SIGNING_SECRET,required"`
}

type ConfigChannels

type ConfigChannels struct {
	Reports    string `env:"REPORTS"`
	Playground string `env:"PLAYGROUND"`
	Jobs       string `env:"JOBS"`
	Staff      string `env:"STAFF"`
}
type ConfigLinks struct {
	COC        string `env:"COC"`
	Netiquette string `env:"NETIQUETTE"`
}

type ConfigStaff

type ConfigStaff struct {
	Members []string `env:"MEMBERS"`
}

type ConfigTwitter

type ConfigTwitter struct {
	twitter.Credentials
	APIKey       string `env:"API_KEY"`
	APIKeySecret string `env:"API_KEY_SECRET"`
}

type Context

type Context struct {
	Client              *slack.Client
	AdminClient         *slack.Client
	Config              Config
	SigningSecret       string
	Version             string
	TwitterContestToken string
	Harvester           *telemetry.Harvester

	Bus EventBus.Bus

	CLI bool // true if runs from CLI
	// contains filtered or unexported fields
}

func (*Context) IsStaff

func (c *Context) IsStaff(userID string) bool

func (*Context) VerifyRequest

func (c *Context) VerifyRequest(r *http.Request, body []byte) error

type EventHandler

type EventHandler func(Context, slackevents.EventsAPIInnerEvent) error

EventHandler handles a Slack event.

func CreateEventHandler

func CreateEventHandler(t slackevents.EventsAPIType, f EventHandler) EventHandler

CreateEventHandler creates a handler aware of errors (they are logged)

type SlackContext

type SlackContext struct {
	User            string
	Channel         string
	Text            string
	Timestamp       string
	ThreadTimestamp string
}

Jump to

Keyboard shortcuts

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