twitch-bot/functions_twitch.go
Knut Ahlers 89de50d035
Allow plugins to register template functions
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-08-19 16:40:34 +02:00

27 lines
727 B
Go

package main
import (
"strings"
"github.com/Luzifer/twitch-bot/plugins"
)
func init() {
tplFuncs.Register("displayName", plugins.GenericTemplateFunctionGetter(func(username string, v ...string) (string, error) {
displayName, err := twitchClient.GetDisplayNameForUser(strings.TrimLeft(username, "#"))
if len(v) > 0 && (err != nil || displayName == "") {
return v[0], nil
}
return displayName, err
}))
tplFuncs.Register("recentGame", plugins.GenericTemplateFunctionGetter(func(username string, v ...string) (string, error) {
game, _, err := twitchClient.GetRecentStreamInfo(strings.TrimLeft(username, "#"))
if len(v) > 0 && (err != nil || game == "") {
return v[0], nil
}
return game, err
}))
}