twitch-bot/functions_twitch.go
Knut Ahlers ca55834315
Fix: Display fallback when no category is set
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-05-24 21:53:17 +02:00

25 lines
657 B
Go

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