parent
4b94186a88
commit
27733f40f9
26
.drone.yml
26
.drone.yml
|
@ -15,4 +15,28 @@ steps:
|
|||
pull: always
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- make vet
|
||||
- make vet
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: release
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
branch:
|
||||
- master
|
||||
steps:
|
||||
- name: build
|
||||
pull: always
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- make build
|
||||
- name: gitea-release
|
||||
pull: always
|
||||
image: jolheiser/drone-gitea-main:latest
|
||||
settings:
|
||||
token:
|
||||
from_secret: gitea_token
|
||||
base: https://git.etztech.xyz
|
||||
files:
|
||||
- "lurk"
|
|
@ -4,7 +4,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/pelletier/go-toml"
|
||||
"go.jolheiser.com/beaver"
|
||||
)
|
||||
|
||||
|
@ -50,17 +50,22 @@ func (c *Config) loadReddit() {
|
|||
}
|
||||
|
||||
func Load(configPath string) (*Config, error) {
|
||||
cfg := &Config{
|
||||
cfg := Config{
|
||||
Reddit: RedditConfig{
|
||||
Map: make(map[string]*SubReddit),
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := toml.DecodeFile(configPath, &cfg); err != nil {
|
||||
tree, err := toml.LoadFile(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := tree.Unmarshal(&cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.loadReddit()
|
||||
beaver.Debug(cfg)
|
||||
return cfg, nil
|
||||
return &cfg, nil
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ type TwitterConfig struct {
|
|||
}
|
||||
|
||||
type Filter struct {
|
||||
Follows []string `toml:"follows"`
|
||||
Locations []string `toml:"locations"`
|
||||
Tracks []string `toml:"tracks"`
|
||||
Webhook string `toml:"webhook"`
|
||||
Follows []string `toml:"follows"`
|
||||
FollowStrict bool `toml:"follow_strict"`
|
||||
Locations []string `toml:"locations"`
|
||||
Tracks []string `toml:"tracks"`
|
||||
Webhook string `toml:"webhook"`
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,9 +3,9 @@ module go.etztech.xyz/lurk
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
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/turnage/graw v0.0.0-20200404033202-65715eea1cd0
|
||||
go.jolheiser.com/beaver v1.0.2
|
||||
)
|
||||
|
|
8
go.sum
8
go.sum
|
@ -1,9 +1,9 @@
|
|||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
|
||||
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dghubble/go-twitter v0.0.0-20200725221434-4bc8ad7ad1b4 h1:I60CX3+rWlBGPXR13jwxxBWB2GhlhZkEEh5o1eDLzJg=
|
||||
github.com/dghubble/go-twitter v0.0.0-20200725221434-4bc8ad7ad1b4/go.mod h1:xfg4uS5LEzOj8PgZV7SQYRHbG7jPUnelEiaAVJxmhJE=
|
||||
github.com/dghubble/oauth1 v0.6.0 h1:m1yC01Ohc/eF38jwZ8JUjL1a+XHHXtGQgK+MxQbmSx0=
|
||||
|
@ -19,8 +19,12 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
|
|||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
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.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM=
|
||||
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/turnage/graw v0.0.0-20200404033202-65715eea1cd0 h1:ss0FREpyYvw5V9t5XWWWIvUJnRgWFzdftvCXd8WQNhU=
|
||||
github.com/turnage/graw v0.0.0-20200404033202-65715eea1cd0/go.mod h1:aAkq4I/q1izZSSwHvzhDn9NA+eGxgTSuibwP3MZRlQY=
|
||||
|
|
|
@ -22,6 +22,19 @@ func (t *Twitter) Run() {
|
|||
demux := twitter.NewSwitchDemux()
|
||||
demux.Tweet = func(tweet *twitter.Tweet) {
|
||||
beaver.Debugf("new tweet for %v", t.Filter)
|
||||
if t.Filter.FollowStrict {
|
||||
var match bool
|
||||
for _, id := range t.Filter.Follows {
|
||||
if id == tweet.User.IDStr {
|
||||
match = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
beaver.Debug("tweet did not match any follow IDs")
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := t.Discord(tweet); err != nil {
|
||||
beaver.Error(err)
|
||||
}
|
||||
|
@ -29,7 +42,7 @@ func (t *Twitter) Run() {
|
|||
|
||||
beaver.Debugf("streaming %v", t.Filter)
|
||||
demux.HandleChan(t.Stream.Messages)
|
||||
beaver.Debugf("diconnected from stream: %v", t.Filter)
|
||||
beaver.Debugf("disconnected from stream: %v", t.Filter)
|
||||
}
|
||||
|
||||
func (t *Twitter) Discord(tweet *twitter.Tweet) error {
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
# 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 = ""
|
||||
|
|
Loading…
Reference in New Issue