2021-04-21 20:43:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-05-24 19:42:55 +00:00
|
|
|
tplFuncs.Register("displayName", genericTemplateFunctionGetter(func(username string, v ...string) (string, error) {
|
2021-08-19 13:33:56 +00:00
|
|
|
displayName, err := twitchClient.GetDisplayNameForUser(strings.TrimLeft(username, "#"))
|
2021-05-24 19:47:10 +00:00
|
|
|
if len(v) > 0 && (err != nil || displayName == "") {
|
2021-05-24 19:42:55 +00:00
|
|
|
return v[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return displayName, err
|
|
|
|
}))
|
|
|
|
|
2021-04-21 20:43:33 +00:00
|
|
|
tplFuncs.Register("recentGame", genericTemplateFunctionGetter(func(username string, v ...string) (string, error) {
|
2021-08-19 13:33:56 +00:00
|
|
|
game, _, err := twitchClient.GetRecentStreamInfo(strings.TrimLeft(username, "#"))
|
2021-05-24 19:53:17 +00:00
|
|
|
if len(v) > 0 && (err != nil || game == "") {
|
2021-04-21 20:43:33 +00:00
|
|
|
return v[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return game, err
|
|
|
|
}))
|
|
|
|
}
|