feat: start moving to YAML
ci/woodpecker/push/goreleaser Pipeline was successful
Details
ci/woodpecker/push/goreleaser Pipeline was successful
Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>pull/7/head
parent
499bb25f8f
commit
84e3f0840a
|
@ -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
|
|
@ -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*
|
|
@ -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
|
|
@ -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: ""
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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: ""
|
|
@ -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 = ""
|
|
@ -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"`
|
||||
Webhook string `yaml:"webhook"`
|
||||
}
|
||||
|
||||
func (r *RedditConfig) UserAgent() string {
|
||||
|
|
|
@ -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"`
|
||||
Webhook string `yaml:"webhook"`
|
||||
}
|
||||
|
|
4
go.mod
4
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
|
||||
)
|
||||
|
|
5
go.sum
5
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=
|
||||
|
@ -78,5 +76,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1N
|
|||
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=
|
||||
|
|
|
@ -3,13 +3,14 @@ package handler
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/turnage/graw"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/turnage/graw"
|
||||
|
||||
"go.jolheiser.com/lurk/config"
|
||||
|
||||
"github.com/turnage/graw/reddit"
|
||||
|
|
|
@ -3,6 +3,7 @@ package handler
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"go.jolheiser.com/lurk/config"
|
||||
|
|
17
main.go
17
main.go
|
@ -2,15 +2,16 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/peterbourgon/ff/v3"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"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"
|
||||
|
||||
|
@ -24,7 +25,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 +62,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 +94,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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue