Documentation
¶
Index ¶
- func LoadConfigFromBytes(data []byte, conf *Config) error
- func LoadConfigFromEnvVars(ctx context.Context, prefix string, conf *Config) error
- func LoadConfigFromFile(filepath string, conf *Config) error
- func LoadConfigFromFileAndEnvVars(ctx context.Context, envVarsPrefix, filepath string, conf *Config) error
- func WakeUp(_ context.Context, conf Config, bus EventBus.Bus) error
- type ChannelLimit
- type Config
- type ConfigBot
- type ConfigBotServer
- type ConfigChannels
- type ConfigLinks
- type ConfigStaff
- type ConfigTwitter
- type Context
- type EventHandler
- type RateLimitConfig
- type RateLimiter
- type SlackContext
- type TrackingDetectionConfig
- type UserRateState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadConfigFromBytes ¶
LoadConfigFromBytes loads config from a raw []byte TOML file
func LoadConfigFromEnvVars ¶
LoadConfigFromEnvVars reads config from env vars and maps that into the given Config struct.
func LoadConfigFromFile ¶
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.
Types ¶
type ChannelLimit ¶
ChannelLimit defines the rate limiting configuration for a specific channel.
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_"`
RateLimits []RateLimitConfig `toml:"rate_limits"`
TrackingDetection []TrackingDetectionConfig `toml:"tracking_detection"`
TwitterContestToken string `env:"TWITTER_CONTEST_TOKEN"`
TwitterContestURL string `env:"TWITTER_CONTEST_URL"`
NewRelicLicenseKey string `env:"NEW_RELIC_LICENSE_KEY"`
APIKey string `env:"API_KEY"`
Debug bool `env:"DEBUG"`
Version string `env:"VERSION"`
}
type ConfigBotServer ¶
type ConfigChannels ¶
type ConfigLinks ¶
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
RateLimiter *RateLimiter
ChannelResolver *slackx.ChannelResolver
TrackingDetector *privacy.TrackingDetector
Bus EventBus.Bus
CLI bool // true if runs from CLI
// contains filtered or unexported fields
}
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 RateLimitConfig ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter enforces per-user, per-channel message rate limits using a sliding window algorithm. It is safe for concurrent use.
func NewRateLimiter ¶
func NewRateLimiter(config []RateLimitConfig, getChannelID func(string) (string, error)) (*RateLimiter, error)
NewRateLimiter creates a new rate limiter with the given configuration. The getChannelID function resolves channel names to IDs. Returns an error if any channel name cannot be resolved.
func (*RateLimiter) CheckLimit ¶
func (rl *RateLimiter) CheckLimit(channelID, userID string) (allowed bool, nextAllowedTime time.Time)
CheckLimit checks if a user is allowed to post a message in a channel. Returns (true, zero time) if allowed, or (false, nextAllowedTime) if rate limited.
func (*RateLimiter) ShouldCheckStaff ¶
func (rl *RateLimiter) ShouldCheckStaff(channelID string) bool
ShouldCheckStaff returns true if rate limits should apply to staff members in the given channel.
type SlackContext ¶
type TrackingDetectionConfig ¶
type TrackingDetectionConfig struct {
ChannelName string `toml:"channel_name"`
}