diff --git a/config/reddit.go b/config/reddit.go index c0296d0..5e1502b 100644 --- a/config/reddit.go +++ b/config/reddit.go @@ -38,7 +38,7 @@ type SubReddit struct { BodyBlocklist []string `yaml:"body_blocklist"` BodyBlocklistRe []*regexp.Regexp `yaml:"-"` BodyLimit int `yaml:"body_limit"` - Webhook string `yaml:"webhook"` + Webhooks []string `yaml:"webhooks"` } func (r *RedditConfig) UserAgent() string { diff --git a/config/twitter.go b/config/twitter.go index cd42497..004cabd 100644 --- a/config/twitter.go +++ b/config/twitter.go @@ -15,5 +15,5 @@ type Filter struct { FollowStrict bool `yaml:"follow_strict"` Locations []string `yaml:"locations"` Tracks []string `yaml:"tracks"` - Webhook string `yaml:"webhook"` + Webhooks []string `yaml:"webhooks"` } diff --git a/handler/reddit.go b/handler/reddit.go index 1e45c92..80de9c7 100644 --- a/handler/reddit.go +++ b/handler/reddit.go @@ -8,11 +8,10 @@ import ( "strings" "time" - "github.com/rs/zerolog/log" - "github.com/turnage/graw" - "go.jolheiser.com/lurk/config" + "github.com/rs/zerolog/log" + "github.com/turnage/graw" "github.com/turnage/graw/reddit" "go.jolheiser.com/disco" ) @@ -69,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 abf5645..26b1d72 100644 --- a/handler/twitter.go +++ b/handler/twitter.go @@ -3,12 +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" ) @@ -57,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 fb3e8ee..17ae44e 100644 --- a/main.go +++ b/main.go @@ -8,15 +8,14 @@ import ( "syscall" "time" - "github.com/peterbourgon/ff/v3" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" - "go.jolheiser.com/lurk/config" "go.jolheiser.com/lurk/handler" "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" )