twitch-bot/functions_counter.go
Knut Ahlers c1e84f31e8
[quotedb] Add new actor
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-10-19 00:22:05 +02:00

26 lines
646 B
Go

package main
import (
"strings"
"github.com/Luzifer/twitch-bot/plugins"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
tplFuncs.Register("channelCounter", func(m *irc.Message, r *plugins.Rule, fields plugins.FieldCollection) interface{} {
return func(name string) (string, error) {
channel, ok := fields["channel"].(string)
if !ok {
return "", errors.New("channel not available")
}
return strings.Join([]string{channel, name}, ":"), nil
}
})
tplFuncs.Register("counterValue", plugins.GenericTemplateFunctionGetter(func(name string, _ ...string) int64 {
return store.GetCounterValue(name)
}))
}