From 3be9150f8c6d30c517a0b573fb2fd7fbf9b06d3c Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 8 Nov 2022 04:23:53 +0000 Subject: [PATCH] Updates 2022 (#7) closes #6 Co-authored-by: jolheiser Reviewed-on: https://git.jojodev.com/jolheiser/lurk/pulls/7 --- .goreleaser.yaml | 25 ++++++++++++++++ .woodpecker.yml | 59 -------------------------------------- .woodpecker/goreleaser.yml | 39 +++++++++++++++++++++++++ config.yaml | 55 +++++++++++++++++++++++++++++++++++ config/config.go | 22 +++++++------- config/config.yaml | 55 +++++++++++++++++++++++++++++++++++ config/lurk.toml | 51 -------------------------------- config/reddit.go | 51 ++++++++++++++++---------------- config/twitter.go | 21 +++++++------- go.mod | 4 +-- go.sum | 9 ++---- handler/reddit.go | 37 +++++++++++------------- handler/twitter.go | 22 ++++++++++++-- main.go | 16 ++++++++--- tools.go | 8 ------ 15 files changed, 275 insertions(+), 199 deletions(-) create mode 100644 .goreleaser.yaml delete mode 100644 .woodpecker.yml create mode 100644 .woodpecker/goreleaser.yml create mode 100644 config.yaml create mode 100644 config/config.yaml delete mode 100644 config/lurk.toml delete mode 100644 tools.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..17297b3 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,25 @@ +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ldflags: + - "-s -w -X main.Version={{.Version}}" +archives: + - replacements: + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +release: + gitea: + owner: jolheiser + name: lurk +gitea_urls: + api: https://git.jojodev.com/api/v1/ + download: https://git.jojodev.com diff --git a/.woodpecker.yml b/.woodpecker.yml deleted file mode 100644 index 7414948..0000000 --- a/.woodpecker.yml +++ /dev/null @@ -1,59 +0,0 @@ -clone: - git: - image: woodpeckerci/plugin-git:next - -pipeline: - compliance: - image: golang:1.17 - commands: - - go test -race ./... - - go vet ./... - - go run github.com/rs/zerolog/cmd/lint go.jolheiser.com/lurk - - go build - when: - event: pull_request - - build: - image: golang:1.17 - commands: - - GOOS="windows" go build - - GOOS="linux" go build - when: - event: [ push, tag ] - branch: main - - release-main: - image: jolheiser/drone-gitea-main:latest - secrets: - - source: gitea_token - target: plugin_token - base: https://git.jojodev.com - files: - - "lurk" - - "lurk.exe" - when: - event: push - branch: main - - release-tag: - image: plugins/gitea-release:1 - secrets: - - source: gitea_token - target: plugin_api_key - base_url: https://git.jojodev.com - files: - - "lurk" - - "lurk.exe" - when: - event: tag - tag: v* - - prune: - image: jolheiser/drone-gitea-prune - secrets: - - source: gitea_token - target: plugin_token - base: https://git.jojodev.com - when: - event: tag - tag: v* diff --git a/.woodpecker/goreleaser.yml b/.woodpecker/goreleaser.yml new file mode 100644 index 0000000..29a760b --- /dev/null +++ b/.woodpecker/goreleaser.yml @@ -0,0 +1,39 @@ +clone: + git: + image: woodpeckerci/plugin-git + settings: + tags: true + +pipeline: + compliance: + image: golang:1.18 + commands: + - go test -race ./... + - go vet ./... + - go run github.com/rs/zerolog/cmd/lint@latest go.jolheiser.com/lurk + when: + event: pull_request + + build: + image: goreleaser/goreleaser + commands: + - goreleaser build --snapshot + when: + event: pull_request + + release: + image: goreleaser/goreleaser + commands: + - goreleaser release + secrets: [ gitea_token ] + when: + event: tag + + prune: + image: jolheiser/drone-gitea-prune + settings: + base: https://git.jojodev.com + token: + from_secret: gitea_token + when: + event: tag diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..a8add13 --- /dev/null +++ b/config.yaml @@ -0,0 +1,55 @@ +# Backoff before lurkers restart after dying +backoff: "5m" + +# Reddit information +reddit: + enabled: false + + # Reddit Agent Info + app_name: "Lurk" + version: "0.1" + + # https://www.reddit.com/prefs/apps + client_id: "" + client_secret: "" + + # Reddit credentials + username: "" + password: "" + + # A list of subreddites to monitor + # allow/blocklist can be omitted in real config if empty + subs: + - name: "" + icon_url: "" + flair_allowlist: [] + flair_blocklist: [] + title_allowlist: [] + title_blocklist: [] + title_limit: 0 + body_allowlist: [] + body_blocklist: [] + body_limit: 0 + webhook: "" + +# Twitter information +twitter: + enabled: false + + # Auth + consumer_key: "" + consumer_secret: "" + access_token: "" + access_secret: "" + + # A list of filters to watch for + # Empty fields can be omitted in a real config + filters: + # follows must use a Twitter user's ID + # https://tweeterid.com/ + - follows: [] + # strict mode means only original tweets will be ingested + follow_strict: false + locations: [] + tracks: [] + webhook: "" diff --git a/config/config.go b/config/config.go index d875af9..bd87fcb 100644 --- a/config/config.go +++ b/config/config.go @@ -8,11 +8,11 @@ import ( "strings" "time" - "github.com/pelletier/go-toml" "github.com/rs/zerolog/log" + "gopkg.in/yaml.v3" ) -//go:embed lurk.toml +//go:embed config.yaml var defaultConfig []byte func Init(configPath string) error { @@ -31,12 +31,12 @@ func Init(configPath string) error { } type Config struct { - Backoff time.Duration `toml:"backoff"` - Reddit RedditConfig `toml:"reddit"` - Twitter TwitterConfig `toml:"twitter"` + Backoff time.Duration `yaml:"backoff"` + Reddit RedditConfig `yaml:"reddit"` + Twitter TwitterConfig `yaml:"twitter"` } -func (c *Config) loadReddit() { +func (c *Config) initReddit() { for _, sub := range c.Reddit.SubReddits { c.Reddit.Map[strings.ToLower(sub.Name)] = sub if sub.TitleLimit == 0 || sub.TitleLimit > 253 { @@ -79,16 +79,16 @@ func Load(configPath string) (*Config, error) { }, } - tree, err := toml.LoadFile(configPath) + fi, err := os.Open(configPath) if err != nil { - return nil, err + return nil, fmt.Errorf("could not open config: %v", err) } - if err := tree.Unmarshal(&cfg); err != nil { - return nil, err + if err := yaml.NewDecoder(fi).Decode(&cfg); err != nil { + return nil, fmt.Errorf("could not decode config: %v", err) } - cfg.loadReddit() + cfg.initReddit() log.Debug().Msgf("%#v", cfg) return &cfg, nil } diff --git a/config/config.yaml b/config/config.yaml new file mode 100644 index 0000000..a8add13 --- /dev/null +++ b/config/config.yaml @@ -0,0 +1,55 @@ +# Backoff before lurkers restart after dying +backoff: "5m" + +# Reddit information +reddit: + enabled: false + + # Reddit Agent Info + app_name: "Lurk" + version: "0.1" + + # https://www.reddit.com/prefs/apps + client_id: "" + client_secret: "" + + # Reddit credentials + username: "" + password: "" + + # A list of subreddites to monitor + # allow/blocklist can be omitted in real config if empty + subs: + - name: "" + icon_url: "" + flair_allowlist: [] + flair_blocklist: [] + title_allowlist: [] + title_blocklist: [] + title_limit: 0 + body_allowlist: [] + body_blocklist: [] + body_limit: 0 + webhook: "" + +# Twitter information +twitter: + enabled: false + + # Auth + consumer_key: "" + consumer_secret: "" + access_token: "" + access_secret: "" + + # A list of filters to watch for + # Empty fields can be omitted in a real config + filters: + # follows must use a Twitter user's ID + # https://tweeterid.com/ + - follows: [] + # strict mode means only original tweets will be ingested + follow_strict: false + locations: [] + tracks: [] + webhook: "" diff --git a/config/lurk.toml b/config/lurk.toml deleted file mode 100644 index 0494fe0..0000000 --- a/config/lurk.toml +++ /dev/null @@ -1,51 +0,0 @@ -# Backoff before lurkers restart after dying -backoff = "5m" - -# Reddit information -[reddit] - # Reddit Agent Info - app_name = "Lurk" - version = "0.1" - - # https://www.reddit.com/prefs/apps - client_id = "" - client_secret = "" - - # Reddit credentials - username = "" - password = "" - - # A list of subreddites to monitor - # allow/blocklist can be omitted in real config if empty - [[reddit.sub]] - name = "" - icon_url = "" - flair_allowlist = [] - flair_blocklist = [] - title_allowlist = [] - title_blocklist = [] - title_limit = 0 - body_allowlist = [] - body_blocklist = [] - body_limit = 0 - webhook = "" - -# Twitter information -[twitter] - # Auth - consumer_key = "" - consumer_secret = "" - access_token = "" - access_secret = "" - - # A list of filters to watch for - # Empty fields can be omitted in a real config - [[twitter.filter]] - # follows must use a Twitter user's ID - # https://tweeterid.com/ - follows = [] - # strict mode means only original tweets will be ingested - follow_strict = false - locations = [] - tracks = [] - webhook = "" diff --git a/config/reddit.go b/config/reddit.go index e335eb1..5e1502b 100644 --- a/config/reddit.go +++ b/config/reddit.go @@ -6,38 +6,39 @@ import ( ) type RedditConfig struct { - SubReddits []*SubReddit `toml:"sub"` - Map map[string]*SubReddit `toml:"-"` + Enabled bool `yaml:"enabled"` + SubReddits []*SubReddit `yaml:"subs"` + Map map[string]*SubReddit `yaml:"-"` // Agent file - AppName string `toml:"app_name"` - Version string `toml:"version"` + AppName string `yaml:"app_name"` + Version string `yaml:"version"` - ClientID string `toml:"client_id"` - ClientSecret string `toml:"client_secret"` + ClientID string `yaml:"client_id"` + ClientSecret string `yaml:"client_secret"` - Username string `toml:"username"` - Password string `toml:"password"` + Username string `yaml:"username"` + Password string `yaml:"password"` } type SubReddit struct { - Name string `toml:"name"` - IconURL string `toml:"icon_url"` - FlairAllowlist []string `toml:"flair_allowlist"` - FlairAllowlistRe []*regexp.Regexp `toml:"-"` - FlairBlocklist []string `toml:"flair_blocklist"` - FlairBlocklistRe []*regexp.Regexp `toml:"-"` - TitleAllowlist []string `toml:"title_allowlist"` - TitleAllowlistRe []*regexp.Regexp `toml:"-"` - TitleBlocklist []string `toml:"title_blocklist"` - TitleBlocklistRe []*regexp.Regexp `toml:"-"` - TitleLimit int `toml:"title_limit"` - BodyAllowlist []string `toml:"body_allowlist"` - BodyAllowlistRe []*regexp.Regexp `toml:"-"` - BodyBlocklist []string `toml:"body_blocklist"` - BodyBlocklistRe []*regexp.Regexp `toml:"-"` - BodyLimit int `toml:"body_limit"` - Webhook string `toml:"webhook"` + 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 { diff --git a/config/twitter.go b/config/twitter.go index 782cc72..004cabd 100644 --- a/config/twitter.go +++ b/config/twitter.go @@ -1,18 +1,19 @@ package config type TwitterConfig struct { - ConsumerKey string `toml:"consumer_key"` - ConsumerSecret string `toml:"consumer_secret"` - AccessToken string `toml:"access_token"` - AccessSecret string `toml:"access_secret"` + Enabled bool `yaml:"enabled"` + ConsumerKey string `yaml:"consumer_key"` + ConsumerSecret string `yaml:"consumer_secret"` + AccessToken string `yaml:"access_token"` + AccessSecret string `yaml:"access_secret"` - Filters []Filter `toml:"filter"` + Filters []Filter `yaml:"filters"` } type Filter struct { - Follows []string `toml:"follows"` - FollowStrict bool `toml:"follow_strict"` - Locations []string `toml:"locations"` - Tracks []string `toml:"tracks"` - Webhook string `toml:"webhook"` + Follows []string `yaml:"follows"` + FollowStrict bool `yaml:"follow_strict"` + Locations []string `yaml:"locations"` + Tracks []string `yaml:"tracks"` + Webhooks []string `yaml:"webhooks"` } diff --git a/go.mod b/go.mod index 6876545..58df694 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.16 require ( github.com/dghubble/go-twitter v0.0.0-20200725221434-4bc8ad7ad1b4 github.com/dghubble/oauth1 v0.6.0 - github.com/pelletier/go-toml v1.8.1 - github.com/peterbourgon/ff/v3 v3.1.2 // indirect + github.com/peterbourgon/ff/v3 v3.1.2 github.com/rs/zerolog v1.26.0 github.com/turnage/graw v0.0.0-20200404033202-65715eea1cd0 go.jolheiser.com/disco v0.0.3 + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 09db1ae..dc03858 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,6 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys= -github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= -github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/peterbourgon/ff/v3 v3.1.2 h1:0GNhbRhO9yHA4CC27ymskOsuRpmX0YQxwxM9UPiP6JM= github.com/peterbourgon/ff/v3 v3.1.2/go.mod h1:XNJLY8EIl6MjMVjBS4F0+G0LYoAqs0DTa4rmHHukKDE= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -45,7 +43,6 @@ go.jolheiser.com/disco v0.0.3 h1:Itt+RazbK2OpREDArE5IN2TA+h4wgTh9HVtKa4N/U+Q= go.jolheiser.com/disco v0.0.3/go.mod h1:J1U0AyytqMRkcuoQCbfWTH7tM7Dfnmtn453lVERJTXI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -63,20 +60,20 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/handler/reddit.go b/handler/reddit.go index 2371905..80de9c7 100644 --- a/handler/reddit.go +++ b/handler/reddit.go @@ -3,8 +3,6 @@ package handler import ( "context" "fmt" - "github.com/rs/zerolog/log" - "github.com/turnage/graw" "net/http" "regexp" "strings" @@ -12,6 +10,8 @@ import ( "go.jolheiser.com/lurk/config" + "github.com/rs/zerolog/log" + "github.com/turnage/graw" "github.com/turnage/graw/reddit" "go.jolheiser.com/disco" ) @@ -68,26 +68,23 @@ func (r *Reddit) Post(p *reddit.Post) error { }, } - if sub.Webhook == "" { - log.Error().Msgf("no webhook for %s", p.Subreddit) - return nil - } + for _, webhook := range sub.Webhooks { + req, err := e.Request(context.Background(), webhook) + if err != nil { + log.Err(err).Msg("") + continue + } - req, err := e.Request(context.Background(), sub.Webhook) - if err != nil { - log.Err(err).Msg("") - return nil - } + resp, err := httpClient.Do(req) + if err != nil { + log.Err(err).Msg("") + continue + } - resp, err := httpClient.Do(req) - if err != nil { - log.Err(err).Msg("") - return nil - } - - if resp.StatusCode != http.StatusNoContent { - log.Error().Msgf(resp.Status) - return nil + if resp.StatusCode != http.StatusNoContent { + log.Error().Msgf(resp.Status) + continue + } } return nil diff --git a/handler/twitter.go b/handler/twitter.go index 6c320c6..26b1d72 100644 --- a/handler/twitter.go +++ b/handler/twitter.go @@ -3,11 +3,12 @@ package handler import ( "context" "fmt" - "github.com/rs/zerolog/log" + "net/http" "go.jolheiser.com/lurk/config" "github.com/dghubble/go-twitter/twitter" + "github.com/rs/zerolog/log" "go.jolheiser.com/disco" ) @@ -56,7 +57,22 @@ func (t *Twitter) Tweet(tweet *twitter.Tweet) { AvatarURL: tweet.User.ProfileImageURLHttps, Content: fmt.Sprintf("https://twitter.com/%d/status/%d", tweet.User.ID, tweet.ID), } - if _, err := w.Send(context.Background(), t.Filter.Webhook); err != nil { - log.Err(err).Msg("") + for _, webhook := range t.Filter.Webhooks { + req, err := w.Request(context.Background(), webhook) + if err != nil { + log.Err(err).Msg("") + continue + } + + resp, err := httpClient.Do(req) + if err != nil { + log.Err(err).Msg("") + continue + } + + if resp.StatusCode != http.StatusNoContent { + log.Error().Msgf(resp.Status) + continue + } } } diff --git a/main.go b/main.go index 482427f..17ae44e 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,6 @@ package main import ( "flag" - "github.com/peterbourgon/ff/v3" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" "os" "os/signal" "strings" @@ -16,6 +13,9 @@ import ( "github.com/dghubble/go-twitter/twitter" "github.com/dghubble/oauth1" + "github.com/peterbourgon/ff/v3" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "github.com/turnage/graw/reddit" ) @@ -24,7 +24,7 @@ func main() { zerolog.SetGlobalLevel(zerolog.InfoLevel) fs := flag.NewFlagSet("lurk", flag.ExitOnError) - configFlag := fs.String("config", "lurk.toml", "path to config file") + configFlag := fs.String("config", "config.yaml", "path to config file") debugFlag := fs.Bool("debug", false, "turn on debug mode") if err := ff.Parse(fs, os.Args[1:], ff.WithEnvVarPrefix("LURK")); err != nil { log.Fatal().Err(err).Msg("") @@ -61,6 +61,10 @@ func main() { } func lurkReddit(cfg *config.Config) { + if !cfg.Reddit.Enabled { + log.Info().Msg("reddit is disabled") + return + } bot, err := reddit.NewBot(reddit.BotConfig{ Agent: cfg.Reddit.UserAgent(), App: reddit.App{ @@ -89,6 +93,10 @@ func lurkReddit(cfg *config.Config) { } func lurkTwitter(cfg *config.Config) { + if !cfg.Twitter.Enabled { + log.Info().Msg("twitter is disabled") + return + } twitterConfig := oauth1.NewConfig(cfg.Twitter.ConsumerKey, cfg.Twitter.ConsumerSecret) token := oauth1.NewToken(cfg.Twitter.AccessToken, cfg.Twitter.AccessSecret) diff --git a/tools.go b/tools.go deleted file mode 100644 index 048b2fa..0000000 --- a/tools.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build tools -// +build tools - -package main - -import ( - _ "github.com/rs/zerolog/cmd/lint" -)