2021-03-24 01:28:06 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RedditConfig struct {
|
2022-11-08 04:23:53 +00:00
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
SubReddits []*SubReddit `yaml:"subs"`
|
|
|
|
Map map[string]*SubReddit `yaml:"-"`
|
2021-03-24 01:28:06 +00:00
|
|
|
|
|
|
|
// Agent file
|
2022-11-08 04:23:53 +00:00
|
|
|
AppName string `yaml:"app_name"`
|
|
|
|
Version string `yaml:"version"`
|
2021-03-24 01:28:06 +00:00
|
|
|
|
2022-11-08 04:23:53 +00:00
|
|
|
ClientID string `yaml:"client_id"`
|
|
|
|
ClientSecret string `yaml:"client_secret"`
|
2021-03-24 01:28:06 +00:00
|
|
|
|
2022-11-08 04:23:53 +00:00
|
|
|
Username string `yaml:"username"`
|
|
|
|
Password string `yaml:"password"`
|
2021-03-24 01:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SubReddit struct {
|
2022-11-08 04:23:53 +00:00
|
|
|
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"`
|
2021-03-24 01:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RedditConfig) UserAgent() string {
|
2022-03-08 21:01:28 +00:00
|
|
|
return fmt.Sprintf("go:%s:%s (by /u/%s)", r.AppName, r.Version, r.Username)
|
2021-03-24 01:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RedditConfig) SubRedditNames() []string {
|
|
|
|
names := make([]string, len(r.SubReddits))
|
|
|
|
for idx, sub := range r.SubReddits {
|
|
|
|
names[idx] = sub.Name
|
|
|
|
}
|
|
|
|
return names
|
|
|
|
}
|