feat: finish YAML
Signed-off-by: jolheiser <john.olheiser@gmail.com>pull/7/head
parent
84e3f0840a
commit
0b8f4b85bd
|
@ -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 {
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
main.go
7
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"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue