package config import ( "fmt" "regexp" ) type RedditConfig struct { SubReddits []*SubReddit `toml:"sub"` Map map[string]*SubReddit `toml:"-"` // Agent file AppName string `toml:"app_name"` Version string `toml:"version"` ClientID string `toml:"client_id"` ClientSecret string `toml:"client_secret"` Username string `toml:"username"` Password string `toml:"password"` } type SubReddit struct { Name string `toml:"name"` IconURL string `toml:"icon_url"` FlairWhitelist []string `toml:"flair_whitelist"` FlairWhitelistRe []*regexp.Regexp `toml:"-"` FlairBlacklist []string `toml:"flair_blacklist"` FlairBlacklistRe []*regexp.Regexp `toml:"-"` TitleWhitelist []string `toml:"title_whitelist"` TitleWhitelistRe []*regexp.Regexp `toml:"-"` TitleBlacklist []string `toml:"title_blacklist"` TitleBlacklistRe []*regexp.Regexp `toml:"-"` TitleLimit int `toml:"title_limit"` BodyWhitelist []string `toml:"body_whitelist"` BodyWhitelistRe []*regexp.Regexp `toml:"-"` BodyBlacklist []string `toml:"body_blacklist"` BodyBlacklistRe []*regexp.Regexp `toml:"-"` BodyLimit int `toml:"body_limit"` Webhook string `toml:"webhook"` } func (r *RedditConfig) UserAgent() string { return fmt.Sprintf("%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 }