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("arg", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
|
2021-04-21 20:43:33 +00:00
|
|
|
return func(arg int) (string, error) {
|
|
|
|
msgParts := strings.Split(m.Trailing(), " ")
|
|
|
|
if len(msgParts) <= arg {
|
|
|
|
return "", errors.New("argument not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgParts[arg], nil
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-19 14:40:34 +00:00
|
|
|
tplFuncs.Register("fixUsername", plugins.GenericTemplateFunctionGetter(func(username string) string { return strings.TrimLeft(username, "@#") }))
|
2021-04-21 20:43:33 +00:00
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
|
2021-04-21 20:43:33 +00:00
|
|
|
return func(idx int) (string, error) {
|
2021-08-19 13:33:56 +00:00
|
|
|
fields := r.GetMatchMessage().FindStringSubmatch(m.Trailing())
|
2021-04-21 20:43:33 +00:00
|
|
|
if len(fields) <= idx {
|
|
|
|
return "", errors.New("group not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return fields[idx], nil
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
tplFuncs.Register("tag", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} {
|
2021-04-21 20:43:33 +00:00
|
|
|
return func(tag string) string {
|
|
|
|
s, _ := m.GetTag(tag)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|