2021-04-21 20:43:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/plugins"
|
2021-04-21 20:43:33 +00:00
|
|
|
"github.com/go-irc/irc"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-08-19 13:33:56 +00:00
|
|
|
tplFuncs.Register("channelCounter", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
|
2021-04-21 20:43:33 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-19 14:40:34 +00:00
|
|
|
tplFuncs.Register("counterValue", plugins.GenericTemplateFunctionGetter(func(name string, _ ...string) int64 {
|
2021-04-21 20:43:33 +00:00
|
|
|
return store.GetCounterValue(name)
|
|
|
|
}))
|
|
|
|
}
|