lurk/config/reddit.go

55 lines
1.6 KiB
Go

package config
import (
"fmt"
"regexp"
)
type RedditConfig struct {
Enabled bool `yaml:"enabled"`
SubReddits []*SubReddit `yaml:"subs"`
Map map[string]*SubReddit `yaml:"-"`
// Agent file
AppName string `yaml:"app_name"`
Version string `yaml:"version"`
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
type SubReddit struct {
Name string `yaml:"name"`
IconURL string `yaml:"icon_url"`
FlairAllowlist []string `yaml:"flair_allowlist"`
FlairAllowlistRe []*regexp.Regexp `yaml:"-"`
FlairBlocklist []string `yaml:"flair_blocklist"`
FlairBlocklistRe []*regexp.Regexp `yaml:"-"`
TitleAllowlist []string `yaml:"title_allowlist"`
TitleAllowlistRe []*regexp.Regexp `yaml:"-"`
TitleBlocklist []string `yaml:"title_blocklist"`
TitleBlocklistRe []*regexp.Regexp `yaml:"-"`
TitleLimit int `yaml:"title_limit"`
BodyAllowlist []string `yaml:"body_allowlist"`
BodyAllowlistRe []*regexp.Regexp `yaml:"-"`
BodyBlocklist []string `yaml:"body_blocklist"`
BodyBlocklistRe []*regexp.Regexp `yaml:"-"`
BodyLimit int `yaml:"body_limit"`
Webhooks []string `yaml:"webhooks"`
}
func (r *RedditConfig) UserAgent() string {
return fmt.Sprintf("go:%s:%s (by /u/%s)", r.AppName, r.Version, r.Username)
}
func (r *RedditConfig) SubRedditNames() []string {
names := make([]string, len(r.SubReddits))
for idx, sub := range r.SubReddits {
names[idx] = sub.Name
}
return names
}