Add plugin support to allow extending of functionality (#6)

This commit is contained in:
Knut Ahlers 2021-08-19 15:33:56 +02:00 committed by GitHub
parent 5404eb06fe
commit b47ffbfff7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 1316 additions and 405 deletions

View file

@ -8,7 +8,7 @@ publish:
bash golang.sh bash golang.sh
test: test:
go test -cover -v . go test -cover -v ./...
# --- Wiki Updates # --- Wiki Updates

View file

@ -1,36 +0,0 @@
package main
import (
"fmt"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
registerAction(func() Actor { return &ActorBan{} })
}
type ActorBan struct {
Ban *string `json:"ban" yaml:"ban"`
}
func (a ActorBan) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) {
if a.Ban == nil {
return false, nil
}
return false, errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/ban %s %s", m.User, *a.Ban),
},
}),
"sending timeout",
)
}
func (a ActorBan) IsAsync() bool { return false }
func (a ActorBan) Name() string { return "ban" }

41
action_core.go Normal file
View file

@ -0,0 +1,41 @@
package main
import (
"github.com/Luzifer/twitch-bot/internal/actors/ban"
"github.com/Luzifer/twitch-bot/internal/actors/delay"
deleteactor "github.com/Luzifer/twitch-bot/internal/actors/delete"
"github.com/Luzifer/twitch-bot/internal/actors/raw"
"github.com/Luzifer/twitch-bot/internal/actors/respond"
"github.com/Luzifer/twitch-bot/internal/actors/timeout"
"github.com/Luzifer/twitch-bot/internal/actors/whisper"
"github.com/Luzifer/twitch-bot/plugins"
log "github.com/sirupsen/logrus"
)
var coreActorRegistations = []plugins.RegisterFunc{
ban.Register,
delay.Register,
deleteactor.Register,
raw.Register,
respond.Register,
timeout.Register,
whisper.Register,
}
func init() {
args := getRegistrationArguments()
for _, rf := range coreActorRegistations {
if err := rf(args); err != nil {
log.WithError(err).Fatal("Unable to register core actor")
}
}
}
func getRegistrationArguments() plugins.RegistrationArguments {
return plugins.RegistrationArguments{
FormatMessage: formatMessage,
GetLogger: func(moduleName string) *log.Entry { return log.WithField("module", moduleName) },
RegisterActor: registerAction,
SendMessage: sendMessage,
}
}

View file

@ -3,12 +3,13 @@ package main
import ( import (
"strconv" "strconv"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { func init() {
registerAction(func() Actor { return &ActorCounter{} }) registerAction(func() plugins.Actor { return &ActorCounter{} })
} }
type ActorCounter struct { type ActorCounter struct {
@ -17,7 +18,7 @@ type ActorCounter struct {
Counter *string `json:"counter" yaml:"counter"` Counter *string `json:"counter" yaml:"counter"`
} }
func (a ActorCounter) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a ActorCounter) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.Counter == nil { if a.Counter == nil {
return false, nil return false, nil
} }

View file

@ -7,19 +7,21 @@ import (
"os" "os"
"os/exec" "os/exec"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/Luzifer/twitch-bot/twitch"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { func init() {
registerAction(func() Actor { return &ActorScript{} }) registerAction(func() plugins.Actor { return &ActorScript{} })
} }
type ActorScript struct { type ActorScript struct {
Command []string `json:"command" yaml:"command"` Command []string `json:"command" yaml:"command"`
} }
func (a ActorScript) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a ActorScript) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if len(a.Command) == 0 { if len(a.Command) == 0 {
return false, nil return false, nil
} }
@ -43,7 +45,7 @@ func (a ActorScript) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCoo
) )
if err := json.NewEncoder(stdin).Encode(map[string]interface{}{ if err := json.NewEncoder(stdin).Encode(map[string]interface{}{
"badges": ircHandler{}.ParseBadgeLevels(m), "badges": twitch.ParseBadgeLevels(m),
"channel": m.Params[0], "channel": m.Params[0],
"message": m.Trailing(), "message": m.Trailing(),
"tags": m.Tags, "tags": m.Tags,
@ -68,7 +70,7 @@ func (a ActorScript) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCoo
} }
var ( var (
actions []*RuleAction actions []*plugins.RuleAction
decoder = json.NewDecoder(stdout) decoder = json.NewDecoder(stdout)
) )

View file

@ -1,12 +1,13 @@
package main package main
import ( import (
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { func init() {
registerAction(func() Actor { return &ActorSetVariable{} }) registerAction(func() plugins.Actor { return &ActorSetVariable{} })
} }
type ActorSetVariable struct { type ActorSetVariable struct {
@ -15,7 +16,7 @@ type ActorSetVariable struct {
Set string `json:"set" yaml:"set"` Set string `json:"set" yaml:"set"`
} }
func (a ActorSetVariable) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a ActorSetVariable) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.Variable == "" { if a.Variable == "" {
return false, nil return false, nil
} }

View file

@ -1,37 +0,0 @@
package main
import (
"fmt"
"time"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
registerAction(func() Actor { return &ActorTimeout{} })
}
type ActorTimeout struct {
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
}
func (a ActorTimeout) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) {
if a.Timeout == nil {
return false, nil
}
return false, errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/timeout %s %d", m.User, fixDurationValue(*a.Timeout)/time.Second),
},
}),
"sending timeout",
)
}
func (a ActorTimeout) IsAsync() bool { return false }
func (a ActorTimeout) Name() string { return "timeout" }

View file

@ -3,39 +3,28 @@ package main
import ( import (
"sync" "sync"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
type (
Actor interface {
// Execute will be called after the config was read into the Actor
Execute(*irc.Client, *irc.Message, *Rule) (preventCooldown bool, err error)
// IsAsync may return true if the Execute function is to be executed
// in a Go routine as of long runtime. Normally it should return false
// except in very specific cases
IsAsync() bool
// Name must return an unique name for the actor in order to identify
// it in the logs for debugging purposes
Name() string
}
ActorCreationFunc func() Actor
)
var ( var (
availableActions []ActorCreationFunc availableActions []plugins.ActorCreationFunc
availableActionsLock = new(sync.RWMutex) availableActionsLock = new(sync.RWMutex)
) )
func registerAction(af ActorCreationFunc) { // Compile-time assertion
var _ plugins.ActorRegistrationFunc = registerAction
func registerAction(af plugins.ActorCreationFunc) {
availableActionsLock.Lock() availableActionsLock.Lock()
defer availableActionsLock.Unlock() defer availableActionsLock.Unlock()
availableActions = append(availableActions, af) availableActions = append(availableActions, af)
} }
func triggerActions(c *irc.Client, m *irc.Message, rule *Rule, ra *RuleAction) (preventCooldown bool, err error) { func triggerActions(c *irc.Client, m *irc.Message, rule *plugins.Rule, ra *plugins.RuleAction) (preventCooldown bool, err error) {
availableActionsLock.RLock() availableActionsLock.RLock()
defer availableActionsLock.RUnlock() defer availableActionsLock.RUnlock()
@ -83,7 +72,7 @@ func handleMessage(c *irc.Client, m *irc.Message, event *string) {
// Lock command // Lock command
if !preventCooldown { if !preventCooldown {
r.setCooldown(m) r.SetCooldown(timerStore, m)
} }
} }
} }

View file

@ -73,7 +73,7 @@ func (a *autoMessage) CanSend() bool {
} }
if a.OnlyOnLive { if a.OnlyOnLive {
streamLive, err := twitch.HasLiveStream(strings.TrimLeft(a.Channel, "#")) streamLive, err := twitchClient.HasLiveStream(strings.TrimLeft(a.Channel, "#"))
if err != nil { if err != nil {
log.WithError(err).Error("Unable to determine channel live status") log.WithError(err).Error("Unable to determine channel live status")
return false return false

View file

@ -1,20 +0,0 @@
package main
type badgeCollection map[string]*int
func (b badgeCollection) Add(badge string, level int) {
b[badge] = &level
}
func (b badgeCollection) Get(badge string) int {
l, ok := b[badge]
if !ok {
return 0
}
return *l
}
func (b badgeCollection) Has(badge string) bool {
return b[badge] != nil
}

View file

@ -7,6 +7,7 @@ import (
"path" "path"
"time" "time"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -19,7 +20,7 @@ type configFile struct {
PermitAllowModerator bool `yaml:"permit_allow_moderator"` PermitAllowModerator bool `yaml:"permit_allow_moderator"`
PermitTimeout time.Duration `yaml:"permit_timeout"` PermitTimeout time.Duration `yaml:"permit_timeout"`
RawLog string `yaml:"raw_log"` RawLog string `yaml:"raw_log"`
Rules []*Rule `yaml:"rules"` Rules []*plugins.Rule `yaml:"rules"`
Variables map[string]interface{} `yaml:"variables"` Variables map[string]interface{} `yaml:"variables"`
rawLogWriter io.WriteCloser rawLogWriter io.WriteCloser
@ -125,14 +126,14 @@ func (c *configFile) CloseRawMessageWriter() error {
return c.rawLogWriter.Close() return c.rawLogWriter.Close()
} }
func (c configFile) GetMatchingRules(m *irc.Message, event *string) []*Rule { func (c configFile) GetMatchingRules(m *irc.Message, event *string) []*plugins.Rule {
configLock.RLock() configLock.RLock()
defer configLock.RUnlock() defer configLock.RUnlock()
var out []*Rule var out []*plugins.Rule
for _, r := range c.Rules { for _, r := range c.Rules {
if r.matches(m, event) { if r.Matches(m, event, timerStore, formatMessage, twitchClient) {
out = append(out, r) out = append(out, r)
} }
} }

View file

@ -0,0 +1,45 @@
FROM golang:alpine as builder
COPY . /go/src/github.com/Luzifer/twitch-bot/examples/plugin
WORKDIR /go/src/github.com/Luzifer/twitch-bot/examples/plugin
RUN set -ex \
&& apk add --update \
build-base \
git \
&& go install \
-mod=readonly \
github.com/Luzifer/twitch-bot@a134d30 \
&& go build \
-buildmode=plugin \
-mod=readonly \
-o /go/bin/example-plugin.so
FROM alpine:latest
LABEL maintainer "Knut Ahlers <knut@ahlers.me>"
ENV CONFIG=/data/config.yaml \
STORAGE_FILE=/data/store.json.gz
RUN set -ex \
&& apk --no-cache add \
bash \
ca-certificates \
curl \
jq \
tzdata
RUN set -ex \
&& apk --no-cache add \
ca-certificates
COPY --from=builder /go/bin/example-plugin.so /usr/lib/twitch-bot/example-plugin.so
COPY --from=builder /go/bin/twitch-bot /usr/local/bin/twitch-bot
COPY config.yaml /data/config.yaml
ENTRYPOINT ["/usr/local/bin/twitch-bot"]
CMD ["--"]
# vim: set ft=Dockerfile:

11
examples/plugin/README.md Normal file
View file

@ -0,0 +1,11 @@
# Plugin-Example
See the `main.go` for a very simple plugin example.
To build:
- Make sure you downloaded the **same** version of `twitch-bot` you're referencing to in your `go.mod`
- Make sure every dependency in the version of the `twitch-bot` you are using too is exactly the **same** version
- Build the bot and the plugin in the **same** environment (for example the same build step in a Docker build)
If you do have different versions of **any** dependency (including the Go standard library) your plugin will not load.

View file

@ -0,0 +1,11 @@
---
channels:
- tezrian
rules:
- actions:
- example: true
match_message: '!example'
...

9
examples/plugin/go.mod Normal file
View file

@ -0,0 +1,9 @@
module github.com/Luzifer/twitch-bot/examples/plugin
go 1.16
require (
github.com/Luzifer/twitch-bot v0.15.1-0.20210818231457-a134d3080de7
github.com/go-irc/irc v2.1.0+incompatible
github.com/pkg/errors v0.9.1
)

488
examples/plugin/go.sum Normal file
View file

@ -0,0 +1,488 @@
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Luzifer/go_helpers v1.4.0 h1:Pmm058SbYewfnpP1CHda/zERoAqYoZFiBHF4l8k03Ko=
github.com/Luzifer/go_helpers v1.4.0/go.mod h1:5yUSe0FS7lIx1Uzmt0R3tdPFrSSaPfiCqaIA6u0Zn4Y=
github.com/Luzifer/go_helpers/v2 v2.11.0 h1:IEVuDEAq2st1sjQNaaTX8TxZ2LsXP0qGeqb2uzYZCIo=
github.com/Luzifer/go_helpers/v2 v2.11.0/go.mod h1:ZnWxPjyCdQ4rZP3kNiMSUW/7FigU1X9Rz8XopdJ5ZCU=
github.com/Luzifer/go_helpers/v2 v2.12.2 h1:B6ekpZ2d938tRaFXQtLZZdBSjVi2jabt2uzLGj3bYc8=
github.com/Luzifer/go_helpers/v2 v2.12.2/go.mod h1:Jp1wZqtbEFNrLlJW7noomOF7fLRW36k+ELITPDK4SHc=
github.com/Luzifer/korvike/functions v0.6.1 h1:OGDaEciVzQh0NUMUxcEK1/vmHLIn4lmneoU/iuKc8YI=
github.com/Luzifer/korvike/functions v0.6.1/go.mod h1:D7C4XN3++eXL3MH87sRPBDEDgL9ylYdEav3Wdp3HCfU=
github.com/Luzifer/rconfig v1.2.0 h1:waD1sqasGVSQSrExpLrQ9Q1JmMaltrS391VdOjWXP/I=
github.com/Luzifer/rconfig v1.2.0/go.mod h1:9pet6z2+mm/UAB0jF/rf0s62USfHNolzgR6Q4KpsJI0=
github.com/Luzifer/rconfig/v2 v2.2.1 h1:zcDdLQlnlzwcBJ8E0WFzOkQE1pCMn3EbX0dFYkeTczg=
github.com/Luzifer/rconfig/v2 v2.2.1/go.mod h1:OKIX0/JRZrPJ/ZXXWklQEFXA6tBfWaljZbW37w+sqBw=
github.com/Luzifer/rconfig/v2 v2.3.0 h1:bmOsSmi2qb4E9ABeTu8RJx/14M7yHNjI2Taski3uIRM=
github.com/Luzifer/rconfig/v2 v2.3.0/go.mod h1:CwyhBZThj0jkrgwcCSNIr/3KdNNv8yEt2aALrwebCYY=
github.com/Luzifer/twitch-bot v0.15.1-0.20210818212706-f6f98559fee2 h1:fry/AmwzeQMlRRqalRmy6vxKaWtnz27/ezctYglzkMY=
github.com/Luzifer/twitch-bot v0.15.1-0.20210818212706-f6f98559fee2/go.mod h1:IWWm6TNqaS3lymj8oKlm7FUr1QsGqQqZAnb6fgx2wAc=
github.com/Luzifer/twitch-bot v0.15.1-0.20210818230204-7459a7c6b505 h1:iLVRIi8WD0hQsjThoPL6RlDuNycQYQFVFFr8qewTEh4=
github.com/Luzifer/twitch-bot v0.15.1-0.20210818230204-7459a7c6b505/go.mod h1:IWWm6TNqaS3lymj8oKlm7FUr1QsGqQqZAnb6fgx2wAc=
github.com/Luzifer/twitch-bot v0.15.1-0.20210818231457-a134d3080de7 h1:K8PaCj3520lA+L1rNF1FJYs9M0G4H0PEmYRZCtY1gQM=
github.com/Luzifer/twitch-bot v0.15.1-0.20210818231457-a134d3080de7/go.mod h1:IWWm6TNqaS3lymj8oKlm7FUr1QsGqQqZAnb6fgx2wAc=
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
github.com/Microsoft/hcsshim v0.8.9/go.mod h1:5692vkUqntj1idxauYlpoINNKeqCiG6Sg38RRsjT5y8=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.0/go.mod h1:zXjbSimjXTd7vOpY8B0/2LpvNvDoXBuplAD+gJD3GYs=
github.com/armon/go-metrics v0.3.3/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aws/aws-sdk-go v1.25.37/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.30.27/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
github.com/cenkalti/backoff/v3 v3.2.2 h1:cfUAAO3yvKMYKPrvhDuHSwQnhZNk/RMHKdZqKTxfm6M=
github.com/cenkalti/backoff/v3 v3.2.2/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
github.com/containerd/containerd v1.3.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.3.4/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20200709052629-daa8e1ccc0bc/go.mod h1:cECdGN1O8G9bgKTlLhuPJimka6Xb/Gg7vYzCTNVxhvo=
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0=
github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o=
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.4.2-0.20200319182547-c7ad2b866182/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-irc/irc v2.1.0+incompatible h1:pg7pMVq5OYQbqTxceByD/EN8VIsba7DtKn49rsCnG8Y=
github.com/go-irc/irc v2.1.0+incompatible/go.mod h1:jJILTRy8s/qOvusiKifAEfhQMVwft1ZwQaVJnnzmyX4=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
github.com/go-ldap/ldap/v3 v3.1.3/go.mod h1:3rbOH3jRS2u6jg2rJnKAMLE/xQyCKIveG2Sa/Cohzb8=
github.com/go-ldap/ldap/v3 v3.1.10/go.mod h1:5Zun81jBTabRaI8lzN7E1JjyEl1g6zI6u9pd8luAK4Q=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.16.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g=
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.5.4 h1:1BZvpawXoJCWX6pNtow9+rpEj+3itIlutiqnntI6jOE=
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.6.2/go.mod h1:gEx6HMUGxYYhJScX7W1Il64m6cc2C1mDaW3NQ9sY1FY=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-rootcerts v1.0.1 h1:DMo4fmknnz0E0evoNYnV48RjWndOsmd6OW+09R3cEP8=
github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc=
github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/vault/api v1.0.4 h1:j08Or/wryXT4AcHj1oCbMd7IijXcKzYUGw59LGu9onU=
github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoIospckxBxk6Q=
github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE=
github.com/hashicorp/vault/api v1.1.1 h1:907ld+Z9cALyvbZK2qUX9cLwvSaEQsMVQB3x2KE8+AI=
github.com/hashicorp/vault/api v1.1.1/go.mod h1:29UXcn/1cLOPHQNMWA7bCz2By4PSd0VKPAydKXS5yN0=
github.com/hashicorp/vault/sdk v0.1.13 h1:mOEPeOhT7jl0J4AMl1E705+BcmeRs1VmKNb9F0sMLy8=
github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M=
github.com/hashicorp/vault/sdk v0.1.14-0.20200519221530-14615acda45f/go.mod h1:WX57W2PwkrOPQ6rVQk+dy5/htHIaB4aBM70EwKThu10=
github.com/hashicorp/vault/sdk v0.2.1 h1:S4O6Iv/dyKlE9AUTXGa7VOvZmsCvg36toPKgV4f2P4M=
github.com/hashicorp/vault/sdk v0.2.1/go.mod h1:WfUiO1vYzfBkz1TmoE4ZGU7HD0T0Cl/rZwaxjBkgN4U=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b/go.mod h1:thNruaSwydMhkQ8dXzapABF9Sc1Tz08ZBcDdgott9RA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.6/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/onsi/gomega v1.12.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7 h1:/bmDWM82ZX7TawqxuI8kVjKI0TXHdSY6pHJArewwHtU=
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4=
gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 h1:WB265cn5OpO+hK3pikC9hpP1zI/KTwmyMFKloW9eOVc=
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc=
gopkg.in/validator.v2 v2.0.0-20210331031555-b37d688a7fb0 h1:EFLtLCwd8tGN+r/ePz3cvRtdsfYNhDEdt/vp6qsT+0A=
gopkg.in/validator.v2 v2.0.0-20210331031555-b37d688a7fb0/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

43
examples/plugin/main.go Normal file
View file

@ -0,0 +1,43 @@
package main
import (
"fmt"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
var _ plugins.RegisterFunc = Register
func Register(args plugins.RegistrationArguments) error {
args.GetLogger("plugin-example").Warn("Example Register called")
args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
}
type actor struct {
Example bool `json:"example" yaml:"example"`
}
func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if !a.Example {
return false, nil
}
return false, errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("@%s Example plugin noticed you! KonCha", m.User),
},
}),
"sending response",
)
}
func (a actor) IsAsync() bool { return false }
func (a actor) Name() string { return "example" }

View file

@ -4,15 +4,17 @@ import (
"strings" "strings"
"sync" "sync"
"text/template" "text/template"
"time"
korvike "github.com/Luzifer/korvike/functions" korvike "github.com/Luzifer/korvike/functions"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
) )
var tplFuncs = newTemplateFuncProvider() var tplFuncs = newTemplateFuncProvider()
type ( type (
templateFuncGetter func(*irc.Message, *Rule, map[string]interface{}) interface{} templateFuncGetter func(*irc.Message, *plugins.Rule, map[string]interface{}) interface{}
templateFuncProvider struct { templateFuncProvider struct {
funcs map[string]templateFuncGetter funcs map[string]templateFuncGetter
lock *sync.RWMutex lock *sync.RWMutex
@ -28,7 +30,7 @@ func newTemplateFuncProvider() *templateFuncProvider {
return out return out
} }
func (t *templateFuncProvider) GetFuncMap(m *irc.Message, r *Rule, fields map[string]interface{}) template.FuncMap { func (t *templateFuncProvider) GetFuncMap(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) template.FuncMap {
t.lock.RLock() t.lock.RLock()
defer t.lock.RUnlock() defer t.lock.RUnlock()
@ -49,7 +51,7 @@ func (t *templateFuncProvider) Register(name string, fg templateFuncGetter) {
} }
func genericTemplateFunctionGetter(f interface{}) templateFuncGetter { func genericTemplateFunctionGetter(f interface{}) templateFuncGetter {
return func(*irc.Message, *Rule, map[string]interface{}) interface{} { return f } return func(*irc.Message, *plugins.Rule, map[string]interface{}) interface{} { return f }
} }
func init() { func init() {
@ -60,7 +62,7 @@ func init() {
tplFuncs.Register("toLower", genericTemplateFunctionGetter(strings.ToLower)) tplFuncs.Register("toLower", genericTemplateFunctionGetter(strings.ToLower))
tplFuncs.Register("toUpper", genericTemplateFunctionGetter(strings.ToUpper)) tplFuncs.Register("toUpper", genericTemplateFunctionGetter(strings.ToUpper))
tplFuncs.Register("followDate", genericTemplateFunctionGetter(twitch.GetFollowDate)) tplFuncs.Register("followDate", genericTemplateFunctionGetter(func(from, to string) (time.Time, error) { return twitchClient.GetFollowDate(from, to) }))
tplFuncs.Register("concat", genericTemplateFunctionGetter(func(delim string, parts ...string) string { return strings.Join(parts, delim) })) tplFuncs.Register("concat", genericTemplateFunctionGetter(func(delim string, parts ...string) string { return strings.Join(parts, delim) }))
tplFuncs.Register("variable", genericTemplateFunctionGetter(func(name string, defVal ...string) string { tplFuncs.Register("variable", genericTemplateFunctionGetter(func(name string, defVal ...string) string {
value := store.GetVariable(name) value := store.GetVariable(name)

View file

@ -3,12 +3,13 @@ package main
import ( import (
"strings" "strings"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { func init() {
tplFuncs.Register("channelCounter", func(m *irc.Message, r *Rule, fields map[string]interface{}) interface{} { tplFuncs.Register("channelCounter", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
return func(name string) (string, error) { return func(name string) (string, error) {
channel, ok := fields["channel"].(string) channel, ok := fields["channel"].(string)
if !ok { if !ok {

View file

@ -3,12 +3,13 @@ package main
import ( import (
"strings" "strings"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { func init() {
tplFuncs.Register("arg", func(m *irc.Message, r *Rule, fields map[string]interface{}) interface{} { tplFuncs.Register("arg", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
return func(arg int) (string, error) { return func(arg int) (string, error) {
msgParts := strings.Split(m.Trailing(), " ") msgParts := strings.Split(m.Trailing(), " ")
if len(msgParts) <= arg { if len(msgParts) <= arg {
@ -21,9 +22,9 @@ func init() {
tplFuncs.Register("fixUsername", genericTemplateFunctionGetter(func(username string) string { return strings.TrimLeft(username, "@#") })) tplFuncs.Register("fixUsername", genericTemplateFunctionGetter(func(username string) string { return strings.TrimLeft(username, "@#") }))
tplFuncs.Register("group", func(m *irc.Message, r *Rule, fields map[string]interface{}) interface{} { tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
return func(idx int) (string, error) { return func(idx int) (string, error) {
fields := r.matchMessage.FindStringSubmatch(m.Trailing()) fields := r.GetMatchMessage().FindStringSubmatch(m.Trailing())
if len(fields) <= idx { if len(fields) <= idx {
return "", errors.New("group not found") return "", errors.New("group not found")
} }
@ -32,7 +33,7 @@ func init() {
} }
}) })
tplFuncs.Register("tag", func(m *irc.Message, r *Rule, fields map[string]interface{}) interface{} { tplFuncs.Register("tag", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
return func(tag string) string { return func(tag string) string {
s, _ := m.GetTag(tag) s, _ := m.GetTag(tag)
return s return s

View file

@ -6,7 +6,7 @@ import (
func init() { func init() {
tplFuncs.Register("displayName", genericTemplateFunctionGetter(func(username string, v ...string) (string, error) { tplFuncs.Register("displayName", genericTemplateFunctionGetter(func(username string, v ...string) (string, error) {
displayName, err := twitch.GetDisplayNameForUser(strings.TrimLeft(username, "#")) displayName, err := twitchClient.GetDisplayNameForUser(strings.TrimLeft(username, "#"))
if len(v) > 0 && (err != nil || displayName == "") { if len(v) > 0 && (err != nil || displayName == "") {
return v[0], nil return v[0], nil
} }
@ -15,7 +15,7 @@ func init() {
})) }))
tplFuncs.Register("recentGame", genericTemplateFunctionGetter(func(username string, v ...string) (string, error) { tplFuncs.Register("recentGame", genericTemplateFunctionGetter(func(username string, v ...string) (string, error) {
game, _, err := twitch.GetRecentStreamInfo(strings.TrimLeft(username, "#")) game, _, err := twitchClient.GetRecentStreamInfo(strings.TrimLeft(username, "#"))
if len(v) > 0 && (err != nil || game == "") { if len(v) > 0 && (err != nil || game == "") {
return v[0], nil return v[0], nil
} }

View file

@ -1,11 +0,0 @@
package main
import "time"
func fixDurationValue(d time.Duration) time.Duration {
if d >= time.Second {
return d
}
return d * time.Second
}

View file

@ -0,0 +1,39 @@
package ban
import (
"fmt"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func Register(args plugins.RegistrationArguments) error {
args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
}
type actor struct {
Ban *string `json:"ban" yaml:"ban"`
}
func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.Ban == nil {
return false, nil
}
return false, errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/ban %s %s", m.User, *a.Ban),
},
}),
"sending timeout",
)
}
func (a actor) IsAsync() bool { return false }
func (a actor) Name() string { return "ban" }

View file

@ -1,22 +1,25 @@
package main package delay
import ( import (
"math/rand" "math/rand"
"time" "time"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
) )
func init() { func Register(args plugins.RegistrationArguments) error {
registerAction(func() Actor { return &ActorDelay{} }) args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
} }
type ActorDelay struct { type actor struct {
Delay time.Duration `json:"delay" yaml:"delay"` Delay time.Duration `json:"delay" yaml:"delay"`
DelayJitter time.Duration `json:"delay_jitter" yaml:"delay_jitter"` DelayJitter time.Duration `json:"delay_jitter" yaml:"delay_jitter"`
} }
func (a ActorDelay) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.Delay == 0 && a.DelayJitter == 0 { if a.Delay == 0 && a.DelayJitter == 0 {
return false, nil return false, nil
} }
@ -30,5 +33,5 @@ func (a ActorDelay) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCool
return false, nil return false, nil
} }
func (a ActorDelay) IsAsync() bool { return false } func (a actor) IsAsync() bool { return false }
func (a ActorDelay) Name() string { return "delay" } func (a actor) Name() string { return "delay" }

View file

@ -1,21 +1,24 @@
package main package deleteactor
import ( import (
"fmt" "fmt"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { func Register(args plugins.RegistrationArguments) error {
registerAction(func() Actor { return &ActorDelete{} }) args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
} }
type ActorDelete struct { type actor struct {
DeleteMessage *bool `json:"delete_message" yaml:"delete_message"` DeleteMessage *bool `json:"delete_message" yaml:"delete_message"`
} }
func (a ActorDelete) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.DeleteMessage == nil || !*a.DeleteMessage { if a.DeleteMessage == nil || !*a.DeleteMessage {
return false, nil return false, nil
} }
@ -37,5 +40,5 @@ func (a ActorDelete) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCoo
) )
} }
func (a ActorDelete) IsAsync() bool { return false } func (a actor) IsAsync() bool { return false }
func (a ActorDelete) Name() string { return "delete" } func (a actor) Name() string { return "delete" }

View file

@ -1,19 +1,26 @@
package main package raw
import ( import (
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { var formatMessage plugins.MsgFormatter
registerAction(func() Actor { return &ActorRaw{} })
func Register(args plugins.RegistrationArguments) error {
formatMessage = args.FormatMessage
args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
} }
type ActorRaw struct { type actor struct {
RawMessage *string `json:"raw_message" yaml:"raw_message"` RawMessage *string `json:"raw_message" yaml:"raw_message"`
} }
func (a ActorRaw) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.RawMessage == nil { if a.RawMessage == nil {
return false, nil return false, nil
} }
@ -34,5 +41,5 @@ func (a ActorRaw) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldo
) )
} }
func (a ActorRaw) IsAsync() bool { return false } func (a actor) IsAsync() bool { return false }
func (a ActorRaw) Name() string { return "raw" } func (a actor) Name() string { return "raw" }

View file

@ -1,21 +1,28 @@
package main package respond
import ( import (
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { var formatMessage plugins.MsgFormatter
registerAction(func() Actor { return &ActorRespond{} })
func Register(args plugins.RegistrationArguments) error {
formatMessage = args.FormatMessage
args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
} }
type ActorRespond struct { type actor struct {
Respond *string `json:"respond" yaml:"respond"` Respond *string `json:"respond" yaml:"respond"`
RespondAsReply *bool `json:"respond_as_reply" yaml:"respond_as_reply"` RespondAsReply *bool `json:"respond_as_reply" yaml:"respond_as_reply"`
RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"` RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"`
} }
func (a ActorRespond) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.Respond == nil { if a.Respond == nil {
return false, nil return false, nil
} }
@ -54,5 +61,5 @@ func (a ActorRespond) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCo
) )
} }
func (a ActorRespond) IsAsync() bool { return false } func (a actor) IsAsync() bool { return false }
func (a ActorRespond) Name() string { return "respond" } func (a actor) Name() string { return "respond" }

View file

@ -0,0 +1,48 @@
package timeout
import (
"fmt"
"time"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func Register(args plugins.RegistrationArguments) error {
args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
}
type actor struct {
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
}
func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.Timeout == nil {
return false, nil
}
return false, errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/timeout %s %d", m.User, fixDurationValue(*a.Timeout)/time.Second),
},
}),
"sending timeout",
)
}
func (a actor) IsAsync() bool { return false }
func (a actor) Name() string { return "timeout" }
func fixDurationValue(d time.Duration) time.Duration {
if d >= time.Second {
return d
}
return d * time.Second
}

View file

@ -1,22 +1,29 @@
package main package whisper
import ( import (
"fmt" "fmt"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() { var formatMessage plugins.MsgFormatter
registerAction(func() Actor { return &ActorWhisper{} })
func Register(args plugins.RegistrationArguments) error {
formatMessage = args.FormatMessage
args.RegisterActor(func() plugins.Actor { return &actor{} })
return nil
} }
type ActorWhisper struct { type actor struct {
WhisperMessage *string `json:"whisper_message" yaml:"whisper_message"` WhisperMessage *string `json:"whisper_message" yaml:"whisper_message"`
WhisperTo *string `json:"whisper_to" yaml:"whisper_to"` WhisperTo *string `json:"whisper_to" yaml:"whisper_to"`
} }
func (a ActorWhisper) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) { func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule) (preventCooldown bool, err error) {
if a.WhisperTo == nil || a.WhisperMessage == nil { if a.WhisperTo == nil || a.WhisperMessage == nil {
return false, nil return false, nil
} }
@ -32,9 +39,6 @@ func (a ActorWhisper) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCo
} }
channel := "#tmijs" // As a fallback, copied from tmi.js channel := "#tmijs" // As a fallback, copied from tmi.js
if len(config.Channels) > 0 {
channel = fmt.Sprintf("#%s", config.Channels[0])
}
return false, errors.Wrap( return false, errors.Wrap(
c.WriteMessage(&irc.Message{ c.WriteMessage(&irc.Message{
@ -48,5 +52,5 @@ func (a ActorWhisper) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCo
) )
} }
func (a ActorWhisper) IsAsync() bool { return false } func (a actor) IsAsync() bool { return false }
func (a ActorWhisper) Name() string { return "whisper" } func (a actor) Name() string { return "whisper" }

51
irc.go
View file

@ -3,21 +3,14 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/Luzifer/twitch-bot/twitch"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
const (
badgeBroadcaster = "broadcaster"
badgeFounder = "founder"
badgeModerator = "moderator"
badgeSubscriber = "subscriber"
)
type ircHandler struct { type ircHandler struct {
conn *tls.Conn conn *tls.Conn
c *irc.Client c *irc.Client
@ -27,7 +20,7 @@ type ircHandler struct {
func newIRCHandler() (*ircHandler, error) { func newIRCHandler() (*ircHandler, error) {
h := new(ircHandler) h := new(ircHandler)
username, err := twitch.getAuthorizedUsername() username, err := twitchClient.GetAuthorizedUsername()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching username") return nil, errors.Wrap(err, "fetching username")
} }
@ -156,8 +149,8 @@ func (i ircHandler) handlePart(m *irc.Message) {
} }
func (i ircHandler) handlePermit(m *irc.Message) { func (i ircHandler) handlePermit(m *irc.Message) {
badges := i.ParseBadgeLevels(m) badges := twitch.ParseBadgeLevels(m)
if !badges.Has(badgeBroadcaster) && (!config.PermitAllowModerator || !badges.Has(badgeModerator)) { if !badges.Has(twitch.BadgeBroadcaster) && (!config.PermitAllowModerator || !badges.Has(twitch.BadgeModerator)) {
// Neither broadcaster nor moderator or moderator not permitted // Neither broadcaster nor moderator or moderator not permitted
return return
} }
@ -256,39 +249,3 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) {
func (i ircHandler) handleTwitchWhisper(m *irc.Message) { func (i ircHandler) handleTwitchWhisper(m *irc.Message) {
go handleMessage(i.c, m, eventTypeWhisper) go handleMessage(i.c, m, eventTypeWhisper)
} }
func (ircHandler) ParseBadgeLevels(m *irc.Message) badgeCollection {
out := badgeCollection{}
badgeString, ok := m.GetTag("badges")
if !ok || len(badgeString) == 0 {
return out
}
badges := strings.Split(badgeString, ",")
for _, b := range badges {
badgeParts := strings.Split(b, "/")
if len(badgeParts) != 2 { //nolint:gomnd // This is not a magic number but just an expected count
log.WithField("badge", b).Warn("Malformed badge found")
continue
}
level, err := strconv.Atoi(badgeParts[1])
if err != nil {
log.WithField("badge", b).Warn("Unparsable level in badge")
continue
}
out.Add(badgeParts[0], level)
}
// If there is a founders badge but no subscribers badge
// add a level-0 subscribers badge to prevent the bot to
// cause trouble on founders when subscribers are allowed
// to do something
if out.Has(badgeFounder) && !out.Has(badgeSubscriber) {
out.Add(badgeSubscriber, out.Get(badgeFounder))
}
return out
}

13
main.go
View file

@ -13,6 +13,7 @@ import (
"github.com/Luzifer/go_helpers/v2/str" "github.com/Luzifer/go_helpers/v2/str"
"github.com/Luzifer/rconfig/v2" "github.com/Luzifer/rconfig/v2"
"github.com/Luzifer/twitch-bot/twitch"
) )
const ircReconnectDelay = 100 * time.Millisecond const ircReconnectDelay = 100 * time.Millisecond
@ -23,6 +24,7 @@ var (
Config string `flag:"config,c" default:"./config.yaml" description:"Location of configuration file"` Config string `flag:"config,c" default:"./config.yaml" description:"Location of configuration file"`
IRCRateLimit time.Duration `flag:"rate-limit" default:"1500ms" description:"How often to send a message (default: 20/30s=1500ms, if your bot is mod everywhere: 100/30s=300ms, different for known/verified bots)"` IRCRateLimit time.Duration `flag:"rate-limit" default:"1500ms" description:"How often to send a message (default: 20/30s=1500ms, if your bot is mod everywhere: 100/30s=300ms, different for known/verified bots)"`
LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"` LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"`
PluginDir string `flag:"plugin-dir" default:"/usr/lib/twitch-bot" description:"Where to find and load plugins"`
StorageFile string `flag:"storage-file" default:"./storage.json.gz" description:"Where to store the data"` StorageFile string `flag:"storage-file" default:"./storage.json.gz" description:"Where to store the data"`
TwitchClient string `flag:"twitch-client" default:"" description:"Client ID to act as"` TwitchClient string `flag:"twitch-client" default:"" description:"Client ID to act as"`
TwitchToken string `flag:"twitch-token" default:"" description:"OAuth token valid for client"` TwitchToken string `flag:"twitch-token" default:"" description:"OAuth token valid for client"`
@ -35,7 +37,8 @@ var (
sendMessage func(m *irc.Message) error sendMessage func(m *irc.Message) error
store = newStorageFile(false) store = newStorageFile(false)
twitchClient *twitch.Client
version = "dev" version = "dev"
) )
@ -66,10 +69,16 @@ func init() {
} }
} }
//nolint: gocognit,gocyclo // Complexity is a little too high but makes no sense to split //nolint: funlen,gocognit,gocyclo // Complexity is a little too high but makes no sense to split
func main() { func main() {
var err error var err error
if err = loadPlugins(cfg.PluginDir); err != nil {
log.WithError(err).Fatal("Unable to load plugins")
}
twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchToken)
if err = loadConfig(cfg.Config); err != nil { if err = loadConfig(cfg.Config); err != nil {
log.WithError(err).Fatal("Initial config load failed") log.WithError(err).Fatal("Initial config load failed")
} }

View file

@ -5,11 +5,15 @@ import (
"text/template" "text/template"
"time" "time"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func formatMessage(tplString string, m *irc.Message, r *Rule, fields map[string]interface{}) (string, error) { // Compile-time assertion
var _ plugins.MsgFormatter = formatMessage
func formatMessage(tplString string, m *irc.Message, r *plugins.Rule, fields map[string]interface{}) (string, error) {
compiledFields := map[string]interface{}{} compiledFields := map[string]interface{}{}
if config != nil { if config != nil {

63
plugins.go Normal file
View file

@ -0,0 +1,63 @@
//go:build cgo && (linux || darwin || freebsd)
package main
import (
"os"
"path"
"path/filepath"
"plugin"
"strings"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func loadPlugins(pluginDir string) error {
logger := log.WithField("plugin_dir", pluginDir)
d, err := os.Stat(pluginDir)
if err != nil {
if os.IsNotExist(err) {
logger.Warn("Plugin directory not found, skipping")
return nil
}
return errors.Wrap(err, "getting plugin-dir info")
}
if !d.IsDir() {
return errors.New("plugin-dir is not a directory")
}
args := getRegistrationArguments()
return errors.Wrap(filepath.Walk(pluginDir, func(currentPath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !strings.HasSuffix(currentPath, ".so") {
// Ignore that file, is not a plugin
return nil
}
logger := log.WithField("plugin", path.Base(currentPath))
p, err := plugin.Open(currentPath)
if err != nil {
logger.WithError(err).Error("Unable to open plugin")
return nil
}
f, err := p.Lookup("Register")
if err != nil {
logger.WithError(err).Error("Unable to find register function")
return nil
}
f.(func(plugins.RegistrationArguments) error)(args)
return nil
}), "loading plugins")
}

44
plugins/interface.go Normal file
View file

@ -0,0 +1,44 @@
package plugins
import (
"github.com/go-irc/irc"
log "github.com/sirupsen/logrus"
)
type (
Actor interface {
// Execute will be called after the config was read into the Actor
Execute(*irc.Client, *irc.Message, *Rule) (preventCooldown bool, err error)
// IsAsync may return true if the Execute function is to be executed
// in a Go routine as of long runtime. Normally it should return false
// except in very specific cases
IsAsync() bool
// Name must return an unique name for the actor in order to identify
// it in the logs for debugging purposes
Name() string
}
ActorCreationFunc func() Actor
ActorRegistrationFunc func(ActorCreationFunc)
LoggerCreationFunc func(moduleName string) *log.Entry
MsgFormatter func(tplString string, m *irc.Message, r *Rule, fields map[string]interface{}) (string, error)
// RegisterFunc is the type of function your plugin must expose with the name Register
RegisterFunc func(RegistrationArguments) error
RegistrationArguments struct {
// FormatMessage is a method to convert templates into strings using internally known variables / configs
FormatMessage MsgFormatter
// GetLogger returns a sirupsen log.Entry pre-configured with the module name
GetLogger LoggerCreationFunc
// RegisterActor is used to register a new IRC rule-actor implementing the Actor interface
RegisterActor ActorRegistrationFunc
// SendMessage can be used to send a message not triggered by an event
SendMessage SendMessageFunc
}
SendMessageFunc func(*irc.Message) error
)

View file

@ -1,14 +1,13 @@
package main package plugins
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"regexp" "regexp"
"strings" "strings"
"time" "time"
"github.com/Luzifer/go_helpers/v2/str" "github.com/Luzifer/go_helpers/v2/str"
"github.com/Luzifer/twitch-bot/twitch"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/mitchellh/hashstructure/v2" "github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -41,6 +40,10 @@ type Rule struct {
matchMessage *regexp.Regexp matchMessage *regexp.Regexp
disableOnMatchMessages []*regexp.Regexp disableOnMatchMessages []*regexp.Regexp
msgFormatter MsgFormatter
timerStore TimerStore
twitchClient *twitch.Client
} }
func (r Rule) MatcherID() string { func (r Rule) MatcherID() string {
@ -55,16 +58,20 @@ func (r Rule) MatcherID() string {
return fmt.Sprintf("hashstructure:%x", h) return fmt.Sprintf("hashstructure:%x", h)
} }
func (r *Rule) matches(m *irc.Message, event *string) bool { func (r *Rule) Matches(m *irc.Message, event *string, timerStore TimerStore, msgFormatter MsgFormatter, twitchClient *twitch.Client) bool {
r.msgFormatter = msgFormatter
r.timerStore = timerStore
r.twitchClient = twitchClient
var ( var (
badges = ircHandler{}.ParseBadgeLevels(m) badges = twitch.ParseBadgeLevels(m)
logger = log.WithFields(log.Fields{ logger = log.WithFields(log.Fields{
"msg": m, "msg": m,
"rule": r, "rule": r,
}) })
) )
for _, matcher := range []func(*log.Entry, *irc.Message, *string, badgeCollection) bool{ for _, matcher := range []func(*log.Entry, *irc.Message, *string, twitch.BadgeCollection) bool{
r.allowExecuteDisable, r.allowExecuteDisable,
r.allowExecuteChannelWhitelist, r.allowExecuteChannelWhitelist,
r.allowExecuteUserWhitelist, r.allowExecuteUserWhitelist,
@ -89,21 +96,34 @@ func (r *Rule) matches(m *irc.Message, event *string) bool {
return true return true
} }
func (r *Rule) setCooldown(m *irc.Message) { func (r *Rule) GetMatchMessage() *regexp.Regexp {
var err error
if r.matchMessage == nil {
if r.matchMessage, err = regexp.Compile(*r.MatchMessage); err != nil {
log.WithError(err).Error("Unable to compile expression")
return nil
}
}
return r.matchMessage
}
func (r *Rule) SetCooldown(timerStore TimerStore, m *irc.Message) {
if r.Cooldown != nil { if r.Cooldown != nil {
timerStore.AddCooldown(timerTypeCooldown, "", r.MatcherID(), time.Now().Add(*r.Cooldown)) timerStore.AddCooldown(TimerTypeCooldown, "", r.MatcherID(), time.Now().Add(*r.Cooldown))
} }
if r.ChannelCooldown != nil && len(m.Params) > 0 { if r.ChannelCooldown != nil && len(m.Params) > 0 {
timerStore.AddCooldown(timerTypeCooldown, m.Params[0], r.MatcherID(), time.Now().Add(*r.ChannelCooldown)) timerStore.AddCooldown(TimerTypeCooldown, m.Params[0], r.MatcherID(), time.Now().Add(*r.ChannelCooldown))
} }
if r.UserCooldown != nil { if r.UserCooldown != nil {
timerStore.AddCooldown(timerTypeCooldown, m.User, r.MatcherID(), time.Now().Add(*r.UserCooldown)) timerStore.AddCooldown(TimerTypeCooldown, m.User, r.MatcherID(), time.Now().Add(*r.UserCooldown))
} }
} }
func (r *Rule) allowExecuteBadgeBlacklist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteBadgeBlacklist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
for _, b := range r.DisableOn { for _, b := range r.DisableOn {
if badges.Has(b) { if badges.Has(b) {
logger.Tracef("Non-Match: Disable-Badge %s", b) logger.Tracef("Non-Match: Disable-Badge %s", b)
@ -114,7 +134,7 @@ func (r *Rule) allowExecuteBadgeBlacklist(logger *log.Entry, m *irc.Message, eve
return true return true
} }
func (r *Rule) allowExecuteBadgeWhitelist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteBadgeWhitelist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if len(r.EnableOn) == 0 { if len(r.EnableOn) == 0 {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -129,13 +149,13 @@ func (r *Rule) allowExecuteBadgeWhitelist(logger *log.Entry, m *irc.Message, eve
return false return false
} }
func (r *Rule) allowExecuteChannelCooldown(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteChannelCooldown(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.ChannelCooldown == nil || len(m.Params) < 1 { if r.ChannelCooldown == nil || len(m.Params) < 1 {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
} }
if !timerStore.InCooldown(timerTypeCooldown, m.Params[0], r.MatcherID()) { if !r.timerStore.InCooldown(TimerTypeCooldown, m.Params[0], r.MatcherID()) {
return true return true
} }
@ -148,7 +168,7 @@ func (r *Rule) allowExecuteChannelCooldown(logger *log.Entry, m *irc.Message, ev
return false return false
} }
func (r *Rule) allowExecuteChannelWhitelist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteChannelWhitelist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if len(r.MatchChannels) == 0 { if len(r.MatchChannels) == 0 {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -162,7 +182,7 @@ func (r *Rule) allowExecuteChannelWhitelist(logger *log.Entry, m *irc.Message, e
return true return true
} }
func (r *Rule) allowExecuteDisable(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteDisable(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.Disable == nil { if r.Disable == nil {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -176,13 +196,13 @@ func (r *Rule) allowExecuteDisable(logger *log.Entry, m *irc.Message, event *str
return true return true
} }
func (r *Rule) allowExecuteDisableOnOffline(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteDisableOnOffline(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.DisableOnOffline == nil || !*r.DisableOnOffline { if r.DisableOnOffline == nil || !*r.DisableOnOffline {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
} }
streamLive, err := twitch.HasLiveStream(strings.TrimLeft(m.Params[0], "#")) streamLive, err := r.twitchClient.HasLiveStream(strings.TrimLeft(m.Params[0], "#"))
if err != nil { if err != nil {
logger.WithError(err).Error("Unable to determine live status") logger.WithError(err).Error("Unable to determine live status")
return false return false
@ -195,8 +215,8 @@ func (r *Rule) allowExecuteDisableOnOffline(logger *log.Entry, m *irc.Message, e
return true return true
} }
func (r *Rule) allowExecuteDisableOnPermit(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteDisableOnPermit(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.DisableOnPermit != nil && *r.DisableOnPermit && timerStore.HasPermit(m.Params[0], m.User) { if r.DisableOnPermit != nil && *r.DisableOnPermit && r.timerStore.HasPermit(m.Params[0], m.User) {
logger.Trace("Non-Match: Permit") logger.Trace("Non-Match: Permit")
return false return false
} }
@ -204,13 +224,13 @@ func (r *Rule) allowExecuteDisableOnPermit(logger *log.Entry, m *irc.Message, ev
return true return true
} }
func (r *Rule) allowExecuteDisableOnTemplate(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteDisableOnTemplate(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.DisableOnTemplate == nil { if r.DisableOnTemplate == nil {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
} }
res, err := formatMessage(*r.DisableOnTemplate, m, r, nil) res, err := r.msgFormatter(*r.DisableOnTemplate, m, r, nil)
if err != nil { if err != nil {
logger.WithError(err).Error("Unable to check DisableOnTemplate field") logger.WithError(err).Error("Unable to check DisableOnTemplate field")
// Caused an error, forbid execution // Caused an error, forbid execution
@ -225,7 +245,7 @@ func (r *Rule) allowExecuteDisableOnTemplate(logger *log.Entry, m *irc.Message,
return true return true
} }
func (r *Rule) allowExecuteEventWhitelist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteEventWhitelist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.MatchEvent == nil { if r.MatchEvent == nil {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -239,7 +259,7 @@ func (r *Rule) allowExecuteEventWhitelist(logger *log.Entry, m *irc.Message, eve
return true return true
} }
func (r *Rule) allowExecuteMessageMatcherBlacklist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteMessageMatcherBlacklist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if len(r.DisableOnMatchMessages) == 0 { if len(r.DisableOnMatchMessages) == 0 {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -268,7 +288,7 @@ func (r *Rule) allowExecuteMessageMatcherBlacklist(logger *log.Entry, m *irc.Mes
return true return true
} }
func (r *Rule) allowExecuteMessageMatcherWhitelist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteMessageMatcherWhitelist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.MatchMessage == nil { if r.MatchMessage == nil {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -293,13 +313,13 @@ func (r *Rule) allowExecuteMessageMatcherWhitelist(logger *log.Entry, m *irc.Mes
return true return true
} }
func (r *Rule) allowExecuteRuleCooldown(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteRuleCooldown(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.Cooldown == nil { if r.Cooldown == nil {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
} }
if !timerStore.InCooldown(timerTypeCooldown, "", r.MatcherID()) { if !r.timerStore.InCooldown(TimerTypeCooldown, "", r.MatcherID()) {
return true return true
} }
@ -312,13 +332,13 @@ func (r *Rule) allowExecuteRuleCooldown(logger *log.Entry, m *irc.Message, event
return false return false
} }
func (r *Rule) allowExecuteUserCooldown(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteUserCooldown(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if r.UserCooldown == nil { if r.UserCooldown == nil {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
} }
if !timerStore.InCooldown(timerTypeCooldown, m.User, r.MatcherID()) { if !r.timerStore.InCooldown(TimerTypeCooldown, m.User, r.MatcherID()) {
return true return true
} }
@ -331,7 +351,7 @@ func (r *Rule) allowExecuteUserCooldown(logger *log.Entry, m *irc.Message, event
return false return false
} }
func (r *Rule) allowExecuteUserWhitelist(logger *log.Entry, m *irc.Message, event *string, badges badgeCollection) bool { func (r *Rule) allowExecuteUserWhitelist(logger *log.Entry, m *irc.Message, event *string, badges twitch.BadgeCollection) bool {
if len(r.MatchUsers) == 0 { if len(r.MatchUsers) == 0 {
// No match criteria set, does not speak against matching // No match criteria set, does not speak against matching
return true return true
@ -344,33 +364,3 @@ func (r *Rule) allowExecuteUserWhitelist(logger *log.Entry, m *irc.Message, even
return true return true
} }
type RuleAction struct {
yamlUnmarshal func(interface{}) error
jsonValue []byte
}
func (r *RuleAction) UnmarshalJSON(d []byte) error {
r.jsonValue = d
return nil
}
func (r *RuleAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
r.yamlUnmarshal = unmarshal
return nil
}
func (r *RuleAction) Unmarshal(v interface{}) error {
switch {
case r.yamlUnmarshal != nil:
return r.yamlUnmarshal(v)
case r.jsonValue != nil:
jd := json.NewDecoder(bytes.NewReader(r.jsonValue))
jd.DisallowUnknownFields()
return jd.Decode(v)
default:
return errors.New("unmarshal on unprimed object")
}
}

38
plugins/ruleAction.go Normal file
View file

@ -0,0 +1,38 @@
package plugins
import (
"bytes"
"encoding/json"
"github.com/pkg/errors"
)
type RuleAction struct {
yamlUnmarshal func(interface{}) error
jsonValue []byte
}
func (r *RuleAction) UnmarshalJSON(d []byte) error {
r.jsonValue = d
return nil
}
func (r *RuleAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
r.yamlUnmarshal = unmarshal
return nil
}
func (r *RuleAction) Unmarshal(v interface{}) error {
switch {
case r.yamlUnmarshal != nil:
return r.yamlUnmarshal(v)
case r.jsonValue != nil:
jd := json.NewDecoder(bytes.NewReader(r.jsonValue))
jd.DisallowUnknownFields()
return jd.Decode(v)
default:
return errors.New("unmarshal on unprimed object")
}
}

View file

@ -1,10 +1,11 @@
package main package plugins
import ( import (
"fmt" "fmt"
"testing" "testing"
"time" "time"
"github.com/Luzifer/twitch-bot/twitch"
"github.com/go-irc/irc" "github.com/go-irc/irc"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -16,25 +17,25 @@ var (
) )
func TestAllowExecuteBadgeBlacklist(t *testing.T) { func TestAllowExecuteBadgeBlacklist(t *testing.T) {
r := &Rule{DisableOn: []string{badgeBroadcaster}} r := &Rule{DisableOn: []string{twitch.BadgeBroadcaster}}
if r.allowExecuteBadgeBlacklist(testLogger, nil, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if r.allowExecuteBadgeBlacklist(testLogger, nil, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Execution allowed on blacklisted badge") t.Error("Execution allowed on blacklisted badge")
} }
if !r.allowExecuteBadgeBlacklist(testLogger, nil, nil, badgeCollection{badgeModerator: testBadgeLevel0}) { if !r.allowExecuteBadgeBlacklist(testLogger, nil, nil, twitch.BadgeCollection{twitch.BadgeModerator: testBadgeLevel0}) {
t.Error("Execution denied without blacklisted badge") t.Error("Execution denied without blacklisted badge")
} }
} }
func TestAllowExecuteBadgeWhitelist(t *testing.T) { func TestAllowExecuteBadgeWhitelist(t *testing.T) {
r := &Rule{EnableOn: []string{badgeBroadcaster}} r := &Rule{EnableOn: []string{twitch.BadgeBroadcaster}}
if r.allowExecuteBadgeWhitelist(testLogger, nil, nil, badgeCollection{badgeModerator: testBadgeLevel0}) { if r.allowExecuteBadgeWhitelist(testLogger, nil, nil, twitch.BadgeCollection{twitch.BadgeModerator: testBadgeLevel0}) {
t.Error("Execution allowed without whitelisted badge") t.Error("Execution allowed without whitelisted badge")
} }
if !r.allowExecuteBadgeWhitelist(testLogger, nil, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if !r.allowExecuteBadgeWhitelist(testLogger, nil, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Execution denied with whitelisted badge") t.Error("Execution denied with whitelisted badge")
} }
} }
@ -52,7 +53,7 @@ func TestAllowExecuteChannelWhitelist(t *testing.T) {
":tmi.twitch.tv CLEARCHAT #dallas": false, ":tmi.twitch.tv CLEARCHAT #dallas": false,
"@msg-id=slow_off :tmi.twitch.tv NOTICE #mychannel :This room is no longer in slow mode.": true, "@msg-id=slow_off :tmi.twitch.tv NOTICE #mychannel :This room is no longer in slow mode.": true,
} { } {
if res := r.allowExecuteChannelWhitelist(testLogger, irc.MustParseMessage(m), nil, badgeCollection{}); res != exp { if res := r.allowExecuteChannelWhitelist(testLogger, irc.MustParseMessage(m), nil, twitch.BadgeCollection{}); res != exp {
t.Errorf("Message %q yield unxpected result: exp=%v res=%v", m, exp, res) t.Errorf("Message %q yield unxpected result: exp=%v res=%v", m, exp, res)
} }
} }
@ -63,7 +64,7 @@ func TestAllowExecuteDisable(t *testing.T) {
true: {Disable: testPtrBool(false)}, true: {Disable: testPtrBool(false)},
false: {Disable: testPtrBool(true)}, false: {Disable: testPtrBool(true)},
} { } {
if res := r.allowExecuteDisable(testLogger, nil, nil, badgeCollection{}); res != exp { if res := r.allowExecuteDisable(testLogger, nil, nil, twitch.BadgeCollection{}); res != exp {
t.Errorf("Disable status %v yield unexpected result: exp=%v res=%v", *r.Disable, exp, res) t.Errorf("Disable status %v yield unexpected result: exp=%v res=%v", *r.Disable, exp, res)
} }
} }
@ -73,58 +74,58 @@ func TestAllowExecuteDisableOnOffline(t *testing.T) {
r := &Rule{DisableOnOffline: testPtrBool(true)} r := &Rule{DisableOnOffline: testPtrBool(true)}
// Fake cache entries to prevent calling the real Twitch API // Fake cache entries to prevent calling the real Twitch API
twitch.apiCache.Set([]string{"hasLiveStream", "channel1"}, time.Minute, true) r.twitchClient = twitch.New("", "")
twitch.apiCache.Set([]string{"hasLiveStream", "channel2"}, time.Minute, false) r.twitchClient.APICache().Set([]string{"hasLiveStream", "channel1"}, time.Minute, true)
r.twitchClient.APICache().Set([]string{"hasLiveStream", "channel2"}, time.Minute, false)
for ch, exp := range map[string]bool{ for ch, exp := range map[string]bool{
"channel1": true, "channel1": true,
"channel2": false, "channel2": false,
} { } {
if res := r.allowExecuteDisableOnOffline(testLogger, irc.MustParseMessage(fmt.Sprintf("PRIVMSG #%s :test", ch)), nil, badgeCollection{}); res != exp { if res := r.allowExecuteDisableOnOffline(testLogger, irc.MustParseMessage(fmt.Sprintf("PRIVMSG #%s :test", ch)), nil, twitch.BadgeCollection{}); res != exp {
t.Errorf("Channel %q yield an unexpected result: exp=%v res=%v", ch, exp, res) t.Errorf("Channel %q yield an unexpected result: exp=%v res=%v", ch, exp, res)
} }
} }
} }
func TestAllowExecuteChannelCooldown(t *testing.T) { func TestAllowExecuteChannelCooldown(t *testing.T) {
r := &Rule{ChannelCooldown: func(i time.Duration) *time.Duration { return &i }(time.Minute), SkipCooldownFor: []string{badgeBroadcaster}} r := &Rule{ChannelCooldown: func(i time.Duration) *time.Duration { return &i }(time.Minute), SkipCooldownFor: []string{twitch.BadgeBroadcaster}}
c1 := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #mychannel :Testing") c1 := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #mychannel :Testing")
c2 := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #otherchannel :Testing") c2 := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #otherchannel :Testing")
if !r.allowExecuteChannelCooldown(testLogger, c1, nil, badgeCollection{}) { r.timerStore = newTestTimerStore()
if !r.allowExecuteChannelCooldown(testLogger, c1, nil, twitch.BadgeCollection{}) {
t.Error("Initial call was not allowed") t.Error("Initial call was not allowed")
} }
// Add cooldown // Add cooldown
timerStore.AddCooldown(timerTypeCooldown, c1.Params[0], r.MatcherID(), time.Now().Add(*r.ChannelCooldown)) r.timerStore.AddCooldown(TimerTypeCooldown, c1.Params[0], r.MatcherID(), time.Now().Add(*r.ChannelCooldown))
if r.allowExecuteChannelCooldown(testLogger, c1, nil, badgeCollection{}) { if r.allowExecuteChannelCooldown(testLogger, c1, nil, twitch.BadgeCollection{}) {
t.Error("Call after cooldown added was allowed") t.Error("Call after cooldown added was allowed")
} }
if !r.allowExecuteChannelCooldown(testLogger, c1, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if !r.allowExecuteChannelCooldown(testLogger, c1, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Call in cooldown with skip badge was not allowed") t.Error("Call in cooldown with skip badge was not allowed")
} }
if !r.allowExecuteChannelCooldown(testLogger, c2, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if !r.allowExecuteChannelCooldown(testLogger, c2, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Call in cooldown with different channel was not allowed") t.Error("Call in cooldown with different channel was not allowed")
} }
} }
func TestAllowExecuteDisableOnPermit(t *testing.T) { func TestAllowExecuteDisableOnPermit(t *testing.T) {
r := &Rule{DisableOnPermit: testPtrBool(true)} r := &Rule{DisableOnPermit: testPtrBool(true)}
r.timerStore = newTestTimerStore()
// Permit is using global configuration, so we must fake that one
config = &configFile{PermitTimeout: time.Minute}
defer func() { config = nil }()
m := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #mychannel :Testing") m := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #mychannel :Testing")
if !r.allowExecuteDisableOnPermit(testLogger, m, nil, badgeCollection{}) { if !r.allowExecuteDisableOnPermit(testLogger, m, nil, twitch.BadgeCollection{}) {
t.Error("Execution was not allowed without permit") t.Error("Execution was not allowed without permit")
} }
timerStore.AddPermit(m.Params[0], m.User) r.timerStore.AddPermit(m.Params[0], m.User)
if r.allowExecuteDisableOnPermit(testLogger, m, nil, badgeCollection{}) { if r.allowExecuteDisableOnPermit(testLogger, m, nil, twitch.BadgeCollection{}) {
t.Error("Execution was allowed with permit") t.Error("Execution was allowed with permit")
} }
} }
@ -133,10 +134,16 @@ func TestAllowExecuteDisableOnTemplate(t *testing.T) {
r := &Rule{DisableOnTemplate: func(s string) *string { return &s }(`{{ ne .username "amy" }}`)} r := &Rule{DisableOnTemplate: func(s string) *string { return &s }(`{{ ne .username "amy" }}`)}
for msg, exp := range map[string]bool{ for msg, exp := range map[string]bool{
":amy!amy@foo.example.com PRIVMSG #mychannel :Testing": true, "false": true,
":bob!bob@foo.example.com PRIVMSG #mychannel :Testing": false, "true": false,
} { } {
if res := r.allowExecuteDisableOnTemplate(testLogger, irc.MustParseMessage(msg), nil, badgeCollection{}); exp != res { // We don't test the message formatter here but only the disable functionality
// so we fake the result of the evaluation
r.msgFormatter = func(tplString string, m *irc.Message, r *Rule, fields map[string]interface{}) (string, error) {
return msg, nil
}
if res := r.allowExecuteDisableOnTemplate(testLogger, irc.MustParseMessage(msg), nil, twitch.BadgeCollection{}); exp != res {
t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res) t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res)
} }
} }
@ -149,7 +156,7 @@ func TestAllowExecuteEventWhitelist(t *testing.T) {
"foobar": false, "foobar": false,
"test": true, "test": true,
} { } {
if res := r.allowExecuteEventWhitelist(testLogger, nil, &evt, badgeCollection{}); exp != res { if res := r.allowExecuteEventWhitelist(testLogger, nil, &evt, twitch.BadgeCollection{}); exp != res {
t.Errorf("Event %q yield unexpected result: exp=%v res=%v", evt, exp, res) t.Errorf("Event %q yield unexpected result: exp=%v res=%v", evt, exp, res)
} }
} }
@ -162,7 +169,7 @@ func TestAllowExecuteMessageMatcherBlacklist(t *testing.T) {
"PRIVMSG #test :Random message": true, "PRIVMSG #test :Random message": true,
"PRIVMSG #test :!disable this one": false, "PRIVMSG #test :!disable this one": false,
} { } {
if res := r.allowExecuteMessageMatcherBlacklist(testLogger, irc.MustParseMessage(msg), nil, badgeCollection{}); exp != res { if res := r.allowExecuteMessageMatcherBlacklist(testLogger, irc.MustParseMessage(msg), nil, twitch.BadgeCollection{}); exp != res {
t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res) t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res)
} }
} }
@ -175,52 +182,55 @@ func TestAllowExecuteMessageMatcherWhitelist(t *testing.T) {
"PRIVMSG #test :Random message": false, "PRIVMSG #test :Random message": false,
"PRIVMSG #test :!test this one": true, "PRIVMSG #test :!test this one": true,
} { } {
if res := r.allowExecuteMessageMatcherWhitelist(testLogger, irc.MustParseMessage(msg), nil, badgeCollection{}); exp != res { if res := r.allowExecuteMessageMatcherWhitelist(testLogger, irc.MustParseMessage(msg), nil, twitch.BadgeCollection{}); exp != res {
t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res) t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res)
} }
} }
} }
func TestAllowExecuteRuleCooldown(t *testing.T) { func TestAllowExecuteRuleCooldown(t *testing.T) {
r := &Rule{Cooldown: func(i time.Duration) *time.Duration { return &i }(time.Minute), SkipCooldownFor: []string{badgeBroadcaster}} r := &Rule{Cooldown: func(i time.Duration) *time.Duration { return &i }(time.Minute), SkipCooldownFor: []string{twitch.BadgeBroadcaster}}
r.timerStore = newTestTimerStore()
if !r.allowExecuteRuleCooldown(testLogger, nil, nil, badgeCollection{}) { if !r.allowExecuteRuleCooldown(testLogger, nil, nil, twitch.BadgeCollection{}) {
t.Error("Initial call was not allowed") t.Error("Initial call was not allowed")
} }
// Add cooldown // Add cooldown
timerStore.AddCooldown(timerTypeCooldown, "", r.MatcherID(), time.Now().Add(*r.Cooldown)) r.timerStore.AddCooldown(TimerTypeCooldown, "", r.MatcherID(), time.Now().Add(*r.Cooldown))
if r.allowExecuteRuleCooldown(testLogger, nil, nil, badgeCollection{}) { if r.allowExecuteRuleCooldown(testLogger, nil, nil, twitch.BadgeCollection{}) {
t.Error("Call after cooldown added was allowed") t.Error("Call after cooldown added was allowed")
} }
if !r.allowExecuteRuleCooldown(testLogger, nil, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if !r.allowExecuteRuleCooldown(testLogger, nil, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Call in cooldown with skip badge was not allowed") t.Error("Call in cooldown with skip badge was not allowed")
} }
} }
func TestAllowExecuteUserCooldown(t *testing.T) { func TestAllowExecuteUserCooldown(t *testing.T) {
r := &Rule{UserCooldown: func(i time.Duration) *time.Duration { return &i }(time.Minute), SkipCooldownFor: []string{badgeBroadcaster}} r := &Rule{UserCooldown: func(i time.Duration) *time.Duration { return &i }(time.Minute), SkipCooldownFor: []string{twitch.BadgeBroadcaster}}
c1 := irc.MustParseMessage(":ben!ben@foo.example.com PRIVMSG #mychannel :Testing") c1 := irc.MustParseMessage(":ben!ben@foo.example.com PRIVMSG #mychannel :Testing")
c2 := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #mychannel :Testing") c2 := irc.MustParseMessage(":amy!amy@foo.example.com PRIVMSG #mychannel :Testing")
if !r.allowExecuteUserCooldown(testLogger, c1, nil, badgeCollection{}) { r.timerStore = newTestTimerStore()
if !r.allowExecuteUserCooldown(testLogger, c1, nil, twitch.BadgeCollection{}) {
t.Error("Initial call was not allowed") t.Error("Initial call was not allowed")
} }
// Add cooldown // Add cooldown
timerStore.AddCooldown(timerTypeCooldown, c1.User, r.MatcherID(), time.Now().Add(*r.UserCooldown)) r.timerStore.AddCooldown(TimerTypeCooldown, c1.User, r.MatcherID(), time.Now().Add(*r.UserCooldown))
if r.allowExecuteUserCooldown(testLogger, c1, nil, badgeCollection{}) { if r.allowExecuteUserCooldown(testLogger, c1, nil, twitch.BadgeCollection{}) {
t.Error("Call after cooldown added was allowed") t.Error("Call after cooldown added was allowed")
} }
if !r.allowExecuteUserCooldown(testLogger, c1, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if !r.allowExecuteUserCooldown(testLogger, c1, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Call in cooldown with skip badge was not allowed") t.Error("Call in cooldown with skip badge was not allowed")
} }
if !r.allowExecuteUserCooldown(testLogger, c2, nil, badgeCollection{badgeBroadcaster: testBadgeLevel0}) { if !r.allowExecuteUserCooldown(testLogger, c2, nil, twitch.BadgeCollection{twitch.BadgeBroadcaster: testBadgeLevel0}) {
t.Error("Call in cooldown with different user was not allowed") t.Error("Call in cooldown with different user was not allowed")
} }
} }
@ -232,7 +242,7 @@ func TestAllowExecuteUserWhitelist(t *testing.T) {
":amy!amy@foo.example.com PRIVMSG #mychannel :Testing": true, ":amy!amy@foo.example.com PRIVMSG #mychannel :Testing": true,
":bob!bob@foo.example.com PRIVMSG #mychannel :Testing": false, ":bob!bob@foo.example.com PRIVMSG #mychannel :Testing": false,
} { } {
if res := r.allowExecuteUserWhitelist(testLogger, irc.MustParseMessage(msg), nil, badgeCollection{}); exp != res { if res := r.allowExecuteUserWhitelist(testLogger, irc.MustParseMessage(msg), nil, twitch.BadgeCollection{}); exp != res {
t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res) t.Errorf("Message %q yield unexpected result: exp=%v res=%v", msg, exp, res)
} }
} }

67
plugins/timerstore.go Normal file
View file

@ -0,0 +1,67 @@
package plugins
import (
"crypto/sha256"
"fmt"
"strings"
"time"
)
type TimerType uint8
const (
TimerTypePermit TimerType = iota
TimerTypeCooldown
)
type (
TimerEntry struct {
Kind TimerType `json:"kind"`
Time time.Time `json:"time"`
}
TimerStore interface {
AddCooldown(tt TimerType, limiter, ruleID string, expiry time.Time)
InCooldown(tt TimerType, limiter, ruleID string) bool
AddPermit(channel, username string)
HasPermit(channel, username string) bool
}
testTimerStore struct {
timers map[string]time.Time
}
)
func newTestTimerStore() *testTimerStore { return &testTimerStore{timers: map[string]time.Time{}} }
// Cooldown timer
func (t *testTimerStore) AddCooldown(tt TimerType, limiter, ruleID string, expiry time.Time) {
t.timers[t.getCooldownTimerKey(tt, limiter, ruleID)] = expiry
}
func (t *testTimerStore) InCooldown(tt TimerType, limiter, ruleID string) bool {
return t.timers[t.getCooldownTimerKey(tt, limiter, ruleID)].After(time.Now())
}
func (testTimerStore) getCooldownTimerKey(tt TimerType, limiter, ruleID string) string {
h := sha256.New()
fmt.Fprintf(h, "%d:%s:%s", tt, limiter, ruleID)
return fmt.Sprintf("sha256:%x", h.Sum(nil))
}
// Permit timer
func (t *testTimerStore) AddPermit(channel, username string) {
t.timers[t.getPermitTimerKey(channel, username)] = time.Now().Add(time.Minute)
}
func (t *testTimerStore) HasPermit(channel, username string) bool {
return t.timers[t.getPermitTimerKey(channel, username)].After(time.Now())
}
func (testTimerStore) getPermitTimerKey(channel, username string) string {
h := sha256.New()
fmt.Fprintf(h, "%d:%s:%s", TimerTypePermit, channel, strings.ToLower(strings.TrimLeft(username, "@")))
return fmt.Sprintf("sha256:%x", h.Sum(nil))
}

10
plugins_unsupported.go Normal file
View file

@ -0,0 +1,10 @@
//go:build !cgo || !(linux || darwin || freebsd)
package main
import log "github.com/sirupsen/logrus"
func loadPlugins(string) error {
log.Warn("Plugin support is disabled in this version")
return nil
}

View file

@ -7,13 +7,14 @@ import (
"sync" "sync"
"time" "time"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
type storageFile struct { type storageFile struct {
Counters map[string]int64 `json:"counters"` Counters map[string]int64 `json:"counters"`
Timers map[string]timerEntry `json:"timers"` Timers map[string]plugins.TimerEntry `json:"timers"`
Variables map[string]string `json:"variables"` Variables map[string]string `json:"variables"`
inMem bool inMem bool
lock *sync.RWMutex lock *sync.RWMutex
@ -22,7 +23,7 @@ type storageFile struct {
func newStorageFile(inMemStore bool) *storageFile { func newStorageFile(inMemStore bool) *storageFile {
return &storageFile{ return &storageFile{
Counters: map[string]int64{}, Counters: map[string]int64{},
Timers: map[string]timerEntry{}, Timers: map[string]plugins.TimerEntry{},
Variables: map[string]string{}, Variables: map[string]string{},
inMem: inMemStore, inMem: inMemStore,
@ -121,11 +122,11 @@ func (s *storageFile) Save() error {
) )
} }
func (s *storageFile) SetTimer(kind timerType, id string, expiry time.Time) error { func (s *storageFile) SetTimer(kind plugins.TimerType, id string, expiry time.Time) error {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
s.Timers[id] = timerEntry{Kind: kind, Time: expiry} s.Timers[id] = plugins.TimerEntry{Kind: kind, Time: expiry}
return errors.Wrap(s.Save(), "saving store") return errors.Wrap(s.Save(), "saving store")
} }

View file

@ -5,21 +5,11 @@ import (
"fmt" "fmt"
"strings" "strings"
"time" "time"
"github.com/Luzifer/twitch-bot/plugins"
) )
type timerType uint8 var timerStore plugins.TimerStore = newTimer()
const (
timerTypePermit timerType = iota
timerTypeCooldown
)
var timerStore = newTimer()
type timerEntry struct {
Kind timerType `json:"kind"`
Time time.Time `json:"time"`
}
type timer struct{} type timer struct{}
@ -29,15 +19,15 @@ func newTimer() *timer {
// Cooldown timer // Cooldown timer
func (t *timer) AddCooldown(tt timerType, limiter, ruleID string, expiry time.Time) { func (t *timer) AddCooldown(tt plugins.TimerType, limiter, ruleID string, expiry time.Time) {
store.SetTimer(timerTypeCooldown, t.getCooldownTimerKey(tt, limiter, ruleID), expiry) store.SetTimer(plugins.TimerTypeCooldown, t.getCooldownTimerKey(tt, limiter, ruleID), expiry)
} }
func (t *timer) InCooldown(tt timerType, limiter, ruleID string) bool { func (t *timer) InCooldown(tt plugins.TimerType, limiter, ruleID string) bool {
return store.HasTimer(t.getCooldownTimerKey(tt, limiter, ruleID)) return store.HasTimer(t.getCooldownTimerKey(tt, limiter, ruleID))
} }
func (timer) getCooldownTimerKey(tt timerType, limiter, ruleID string) string { func (timer) getCooldownTimerKey(tt plugins.TimerType, limiter, ruleID string) string {
h := sha256.New() h := sha256.New()
fmt.Fprintf(h, "%d:%s:%s", tt, limiter, ruleID) fmt.Fprintf(h, "%d:%s:%s", tt, limiter, ruleID)
return fmt.Sprintf("sha256:%x", h.Sum(nil)) return fmt.Sprintf("sha256:%x", h.Sum(nil))
@ -46,7 +36,7 @@ func (timer) getCooldownTimerKey(tt timerType, limiter, ruleID string) string {
// Permit timer // Permit timer
func (t *timer) AddPermit(channel, username string) { func (t *timer) AddPermit(channel, username string) {
store.SetTimer(timerTypePermit, t.getPermitTimerKey(channel, username), time.Now().Add(config.PermitTimeout)) store.SetTimer(plugins.TimerTypePermit, t.getPermitTimerKey(channel, username), time.Now().Add(config.PermitTimeout))
} }
func (t *timer) HasPermit(channel, username string) bool { func (t *timer) HasPermit(channel, username string) bool {
@ -55,6 +45,6 @@ func (t *timer) HasPermit(channel, username string) bool {
func (timer) getPermitTimerKey(channel, username string) string { func (timer) getPermitTimerKey(channel, username string) string {
h := sha256.New() h := sha256.New()
fmt.Fprintf(h, "%d:%s:%s", timerTypePermit, channel, strings.ToLower(strings.TrimLeft(username, "@"))) fmt.Fprintf(h, "%d:%s:%s", plugins.TimerTypePermit, channel, strings.ToLower(strings.TrimLeft(username, "@")))
return fmt.Sprintf("sha256:%x", h.Sum(nil)) return fmt.Sprintf("sha256:%x", h.Sum(nil))
} }

68
twitch/badges.go Normal file
View file

@ -0,0 +1,68 @@
package twitch
import (
"strconv"
"strings"
"github.com/go-irc/irc"
)
const (
BadgeBroadcaster = "broadcaster"
BadgeFounder = "founder"
BadgeModerator = "moderator"
BadgeSubscriber = "subscriber"
)
type BadgeCollection map[string]*int
func ParseBadgeLevels(m *irc.Message) BadgeCollection {
out := BadgeCollection{}
badgeString, ok := m.GetTag("badges")
if !ok || len(badgeString) == 0 {
return out
}
badges := strings.Split(badgeString, ",")
for _, b := range badges {
badgeParts := strings.Split(b, "/")
if len(badgeParts) != 2 { //nolint:gomnd // This is not a magic number but just an expected count
continue
}
level, err := strconv.Atoi(badgeParts[1])
if err != nil {
continue
}
out.Add(badgeParts[0], level)
}
// If there is a founders badge but no subscribers badge
// add a level-0 subscribers badge to prevent the bot to
// cause trouble on founders when subscribers are allowed
// to do something
if out.Has(BadgeFounder) && !out.Has(BadgeSubscriber) {
out.Add(BadgeSubscriber, out.Get(BadgeFounder))
}
return out
}
func (b BadgeCollection) Add(badge string, level int) {
b[badge] = &level
}
func (b BadgeCollection) Get(badge string) int {
l, ok := b[badge]
if !ok {
return 0
}
return *l
}
func (b BadgeCollection) Has(badge string) bool {
return b[badge] != nil
}

View file

@ -1,4 +1,4 @@
package main package twitch
import ( import (
"context" "context"
@ -20,19 +20,25 @@ const (
twitchRequestTimeout = 2 * time.Second twitchRequestTimeout = 2 * time.Second
) )
var twitch = newTwitchClient() type Client struct {
clientID string
token string
type twitchClient struct { apiCache *APICache
apiCache *twitchAPICache
} }
func newTwitchClient() *twitchClient { func New(clientID, token string) *Client {
return &twitchClient{ return &Client{
clientID: clientID,
token: token,
apiCache: newTwitchAPICache(), apiCache: newTwitchAPICache(),
} }
} }
func (t twitchClient) getAuthorizedUsername() (string, error) { func (c Client) APICache() *APICache { return c.apiCache }
func (c Client) GetAuthorizedUsername() (string, error) {
var payload struct { var payload struct {
Data []struct { Data []struct {
ID string `json:"id"` ID string `json:"id"`
@ -40,7 +46,7 @@ func (t twitchClient) getAuthorizedUsername() (string, error) {
} `json:"data"` } `json:"data"`
} }
if err := t.request( if err := c.request(
context.Background(), context.Background(),
http.MethodGet, http.MethodGet,
"https://api.twitch.tv/helix/users", "https://api.twitch.tv/helix/users",
@ -57,9 +63,9 @@ func (t twitchClient) getAuthorizedUsername() (string, error) {
return payload.Data[0].Login, nil return payload.Data[0].Login, nil
} }
func (t twitchClient) GetDisplayNameForUser(username string) (string, error) { func (c Client) GetDisplayNameForUser(username string) (string, error) {
cacheKey := []string{"displayNameForUsername", username} cacheKey := []string{"displayNameForUsername", username}
if d := t.apiCache.Get(cacheKey); d != nil { if d := c.apiCache.Get(cacheKey); d != nil {
return d.(string), nil return d.(string), nil
} }
@ -71,7 +77,7 @@ func (t twitchClient) GetDisplayNameForUser(username string) (string, error) {
} `json:"data"` } `json:"data"`
} }
if err := t.request( if err := c.request(
context.Background(), context.Background(),
http.MethodGet, http.MethodGet,
fmt.Sprintf("https://api.twitch.tv/helix/users?login=%s", username), fmt.Sprintf("https://api.twitch.tv/helix/users?login=%s", username),
@ -86,22 +92,22 @@ func (t twitchClient) GetDisplayNameForUser(username string) (string, error) {
} }
// The DisplayName for an username will not change (often), cache for a decent time // The DisplayName for an username will not change (often), cache for a decent time
t.apiCache.Set(cacheKey, time.Hour, payload.Data[0].DisplayName) c.apiCache.Set(cacheKey, time.Hour, payload.Data[0].DisplayName)
return payload.Data[0].DisplayName, nil return payload.Data[0].DisplayName, nil
} }
func (t twitchClient) GetFollowDate(from, to string) (time.Time, error) { func (c Client) GetFollowDate(from, to string) (time.Time, error) {
cacheKey := []string{"followDate", from, to} cacheKey := []string{"followDate", from, to}
if d := t.apiCache.Get(cacheKey); d != nil { if d := c.apiCache.Get(cacheKey); d != nil {
return d.(time.Time), nil return d.(time.Time), nil
} }
fromID, err := t.getIDForUsername(from) fromID, err := c.getIDForUsername(from)
if err != nil { if err != nil {
return time.Time{}, errors.Wrap(err, "getting id for 'from' user") return time.Time{}, errors.Wrap(err, "getting id for 'from' user")
} }
toID, err := t.getIDForUsername(to) toID, err := c.getIDForUsername(to)
if err != nil { if err != nil {
return time.Time{}, errors.Wrap(err, "getting id for 'to' user") return time.Time{}, errors.Wrap(err, "getting id for 'to' user")
} }
@ -112,7 +118,7 @@ func (t twitchClient) GetFollowDate(from, to string) (time.Time, error) {
} `json:"data"` } `json:"data"`
} }
if err := t.request( if err := c.request(
context.Background(), context.Background(),
http.MethodGet, http.MethodGet,
fmt.Sprintf("https://api.twitch.tv/helix/users/follows?to_id=%s&from_id=%s", toID, fromID), fmt.Sprintf("https://api.twitch.tv/helix/users/follows?to_id=%s&from_id=%s", toID, fromID),
@ -127,14 +133,14 @@ func (t twitchClient) GetFollowDate(from, to string) (time.Time, error) {
} }
// Follow date will not change that often, cache for a long time // Follow date will not change that often, cache for a long time
t.apiCache.Set(cacheKey, timeDay, payload.Data[0].FollowedAt) c.apiCache.Set(cacheKey, timeDay, payload.Data[0].FollowedAt)
return payload.Data[0].FollowedAt, nil return payload.Data[0].FollowedAt, nil
} }
func (t twitchClient) HasLiveStream(username string) (bool, error) { func (c Client) HasLiveStream(username string) (bool, error) {
cacheKey := []string{"hasLiveStream", username} cacheKey := []string{"hasLiveStream", username}
if d := t.apiCache.Get(cacheKey); d != nil { if d := c.apiCache.Get(cacheKey); d != nil {
return d.(bool), nil return d.(bool), nil
} }
@ -146,7 +152,7 @@ func (t twitchClient) HasLiveStream(username string) (bool, error) {
} `json:"data"` } `json:"data"`
} }
if err := t.request( if err := c.request(
context.Background(), context.Background(),
http.MethodGet, http.MethodGet,
fmt.Sprintf("https://api.twitch.tv/helix/streams?user_login=%s", username), fmt.Sprintf("https://api.twitch.tv/helix/streams?user_login=%s", username),
@ -157,14 +163,14 @@ func (t twitchClient) HasLiveStream(username string) (bool, error) {
} }
// Live status might change recently, cache for one minute // Live status might change recently, cache for one minute
t.apiCache.Set(cacheKey, time.Minute, len(payload.Data) == 1 && payload.Data[0].Type == "live") c.apiCache.Set(cacheKey, time.Minute, len(payload.Data) == 1 && payload.Data[0].Type == "live")
return len(payload.Data) == 1 && payload.Data[0].Type == "live", nil return len(payload.Data) == 1 && payload.Data[0].Type == "live", nil
} }
func (t twitchClient) getIDForUsername(username string) (string, error) { func (c Client) getIDForUsername(username string) (string, error) {
cacheKey := []string{"idForUsername", username} cacheKey := []string{"idForUsername", username}
if d := t.apiCache.Get(cacheKey); d != nil { if d := c.apiCache.Get(cacheKey); d != nil {
return d.(string), nil return d.(string), nil
} }
@ -175,7 +181,7 @@ func (t twitchClient) getIDForUsername(username string) (string, error) {
} `json:"data"` } `json:"data"`
} }
if err := t.request( if err := c.request(
context.Background(), context.Background(),
http.MethodGet, http.MethodGet,
fmt.Sprintf("https://api.twitch.tv/helix/users?login=%s", username), fmt.Sprintf("https://api.twitch.tv/helix/users?login=%s", username),
@ -190,18 +196,18 @@ func (t twitchClient) getIDForUsername(username string) (string, error) {
} }
// The ID for an username will not change (often), cache for a long time // The ID for an username will not change (often), cache for a long time
t.apiCache.Set(cacheKey, timeDay, payload.Data[0].ID) c.apiCache.Set(cacheKey, timeDay, payload.Data[0].ID)
return payload.Data[0].ID, nil return payload.Data[0].ID, nil
} }
func (t twitchClient) GetRecentStreamInfo(username string) (string, string, error) { func (c Client) GetRecentStreamInfo(username string) (string, string, error) {
cacheKey := []string{"recentStreamInfo", username} cacheKey := []string{"recentStreamInfo", username}
if d := t.apiCache.Get(cacheKey); d != nil { if d := c.apiCache.Get(cacheKey); d != nil {
return d.([2]string)[0], d.([2]string)[1], nil return d.([2]string)[0], d.([2]string)[1], nil
} }
id, err := t.getIDForUsername(username) id, err := c.getIDForUsername(username)
if err != nil { if err != nil {
return "", "", errors.Wrap(err, "getting ID for username") return "", "", errors.Wrap(err, "getting ID for username")
} }
@ -215,7 +221,7 @@ func (t twitchClient) GetRecentStreamInfo(username string) (string, string, erro
} `json:"data"` } `json:"data"`
} }
if err := t.request( if err := c.request(
context.Background(), context.Background(),
http.MethodGet, http.MethodGet,
fmt.Sprintf("https://api.twitch.tv/helix/channels?broadcaster_id=%s", id), fmt.Sprintf("https://api.twitch.tv/helix/channels?broadcaster_id=%s", id),
@ -230,12 +236,12 @@ func (t twitchClient) GetRecentStreamInfo(username string) (string, string, erro
} }
// Stream-info can be changed at any moment, cache for a short period of time // Stream-info can be changed at any moment, cache for a short period of time
t.apiCache.Set(cacheKey, time.Minute, [2]string{payload.Data[0].GameName, payload.Data[0].Title}) c.apiCache.Set(cacheKey, time.Minute, [2]string{payload.Data[0].GameName, payload.Data[0].Title})
return payload.Data[0].GameName, payload.Data[0].Title, nil return payload.Data[0].GameName, payload.Data[0].Title, nil
} }
func (twitchClient) request(ctx context.Context, method, url string, body io.Reader, out interface{}) error { func (c Client) request(ctx context.Context, method, url string, body io.Reader, out interface{}) error {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"method": method, "method": method,
"url": url, "url": url,
@ -250,8 +256,8 @@ func (twitchClient) request(ctx context.Context, method, url string, body io.Rea
return errors.Wrap(err, "assemble request") return errors.Wrap(err, "assemble request")
} }
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("Client-Id", cfg.TwitchClient) req.Header.Set("Client-Id", c.clientID)
req.Header.Set("Authorization", "Bearer "+cfg.TwitchToken) req.Header.Set("Authorization", "Bearer "+c.token)
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {

View file

@ -1,4 +1,4 @@
package main package twitch
import ( import (
"crypto/sha256" "crypto/sha256"
@ -9,23 +9,24 @@ import (
) )
type ( type (
twitchAPICache struct { APICache struct {
data map[string]twitchAPICacheEntry data map[string]twitchAPICacheEntry
lock sync.RWMutex lock sync.RWMutex
} }
twitchAPICacheEntry struct { twitchAPICacheEntry struct {
Data interface{} Data interface{}
ValidUntil time.Time ValidUntil time.Time
} }
) )
func newTwitchAPICache() *twitchAPICache { func newTwitchAPICache() *APICache {
return &twitchAPICache{ return &APICache{
data: make(map[string]twitchAPICacheEntry), data: make(map[string]twitchAPICacheEntry),
} }
} }
func (t *twitchAPICache) Get(key []string) interface{} { func (t *APICache) Get(key []string) interface{} {
t.lock.RLock() t.lock.RLock()
defer t.lock.RUnlock() defer t.lock.RUnlock()
@ -37,7 +38,7 @@ func (t *twitchAPICache) Get(key []string) interface{} {
return e.Data return e.Data
} }
func (t *twitchAPICache) Set(key []string, valid time.Duration, data interface{}) { func (t *APICache) Set(key []string, valid time.Duration, data interface{}) {
t.lock.Lock() t.lock.Lock()
defer t.lock.Unlock() defer t.lock.Unlock()
@ -47,7 +48,7 @@ func (t *twitchAPICache) Set(key []string, valid time.Duration, data interface{}
} }
} }
func (*twitchAPICache) deriveKey(key []string) string { func (*APICache) deriveKey(key []string) string {
sha := sha256.New() sha := sha256.New()
fmt.Fprintf(sha, "%s", strings.Join(key, ":")) fmt.Fprintf(sha, "%s", strings.Join(key, ":"))