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"`
|
BodyBlocklist []string `yaml:"body_blocklist"`
|
||||||
BodyBlocklistRe []*regexp.Regexp `yaml:"-"`
|
BodyBlocklistRe []*regexp.Regexp `yaml:"-"`
|
||||||
BodyLimit int `yaml:"body_limit"`
|
BodyLimit int `yaml:"body_limit"`
|
||||||
Webhook string `yaml:"webhook"`
|
Webhooks []string `yaml:"webhooks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedditConfig) UserAgent() string {
|
func (r *RedditConfig) UserAgent() string {
|
||||||
|
|
|
@ -15,5 +15,5 @@ type Filter struct {
|
||||||
FollowStrict bool `yaml:"follow_strict"`
|
FollowStrict bool `yaml:"follow_strict"`
|
||||||
Locations []string `yaml:"locations"`
|
Locations []string `yaml:"locations"`
|
||||||
Tracks []string `yaml:"tracks"`
|
Tracks []string `yaml:"tracks"`
|
||||||
Webhook string `yaml:"webhook"`
|
Webhooks []string `yaml:"webhooks"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/turnage/graw"
|
|
||||||
|
|
||||||
"go.jolheiser.com/lurk/config"
|
"go.jolheiser.com/lurk/config"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/turnage/graw"
|
||||||
"github.com/turnage/graw/reddit"
|
"github.com/turnage/graw/reddit"
|
||||||
"go.jolheiser.com/disco"
|
"go.jolheiser.com/disco"
|
||||||
)
|
)
|
||||||
|
@ -69,26 +68,23 @@ func (r *Reddit) Post(p *reddit.Post) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if sub.Webhook == "" {
|
for _, webhook := range sub.Webhooks {
|
||||||
log.Error().Msgf("no webhook for %s", p.Subreddit)
|
req, err := e.Request(context.Background(), webhook)
|
||||||
return nil
|
if err != nil {
|
||||||
}
|
log.Err(err).Msg("")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
req, err := e.Request(context.Background(), sub.Webhook)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("")
|
log.Err(err).Msg("")
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
if resp.StatusCode != http.StatusNoContent {
|
||||||
if err != nil {
|
log.Error().Msgf(resp.Status)
|
||||||
log.Err(err).Msg("")
|
continue
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusNoContent {
|
|
||||||
log.Error().Msgf(resp.Status)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -3,12 +3,12 @@ package handler
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
|
||||||
"go.jolheiser.com/lurk/config"
|
"go.jolheiser.com/lurk/config"
|
||||||
|
|
||||||
"github.com/dghubble/go-twitter/twitter"
|
"github.com/dghubble/go-twitter/twitter"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"go.jolheiser.com/disco"
|
"go.jolheiser.com/disco"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,7 +57,22 @@ func (t *Twitter) Tweet(tweet *twitter.Tweet) {
|
||||||
AvatarURL: tweet.User.ProfileImageURLHttps,
|
AvatarURL: tweet.User.ProfileImageURLHttps,
|
||||||
Content: fmt.Sprintf("https://twitter.com/%d/status/%d", tweet.User.ID, tweet.ID),
|
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 {
|
for _, webhook := range t.Filter.Webhooks {
|
||||||
log.Err(err).Msg("")
|
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"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/peterbourgon/ff/v3"
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
|
||||||
"go.jolheiser.com/lurk/config"
|
"go.jolheiser.com/lurk/config"
|
||||||
"go.jolheiser.com/lurk/handler"
|
"go.jolheiser.com/lurk/handler"
|
||||||
|
|
||||||
"github.com/dghubble/go-twitter/twitter"
|
"github.com/dghubble/go-twitter/twitter"
|
||||||
"github.com/dghubble/oauth1"
|
"github.com/dghubble/oauth1"
|
||||||
|
"github.com/peterbourgon/ff/v3"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/turnage/graw/reddit"
|
"github.com/turnage/graw/reddit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue