[templating] Add profileImage function

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-08-18 17:48:20 +02:00
parent 253379e507
commit 2f0572c256
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 23 additions and 0 deletions

View file

@ -288,6 +288,19 @@ Example:
< 10000
```
### `profileImage`
Gets the URL of the given users profile image
Syntax: `profileImage <username>`
Example:
```
# {{ profileImage .username }}
< https://static-cdn.jtvnw.net/jtv_user_pictures/[...].png
```
### `randomString`
Randomly picks a string from a list of strings

View file

@ -19,6 +19,7 @@ func init() {
tplFuncs.Register("followDate", plugins.GenericTemplateFunctionGetter(tplTwitchFollowDate))
tplFuncs.Register("doesFollowLongerThan", plugins.GenericTemplateFunctionGetter(tplTwitchDoesFollowLongerThan))
tplFuncs.Register("lastPoll", plugins.GenericTemplateFunctionGetter(tplTwitchLastPoll))
tplFuncs.Register("profileImage", plugins.GenericTemplateFunctionGetter(tplTwitchProfileImage))
tplFuncs.Register("recentGame", plugins.GenericTemplateFunctionGetter(tplTwitchRecentGame))
tplFuncs.Register("recentTitle", plugins.GenericTemplateFunctionGetter(tplTwitchRecentTitle))
tplFuncs.Register("streamUptime", plugins.GenericTemplateFunctionGetter(tplTwitchStreamUptime))
@ -110,6 +111,15 @@ func tplTwitchLastPoll(username string) (*twitch.PollInfo, error) {
return poll, errors.Wrap(err, "getting last poll")
}
func tplTwitchProfileImage(username string) (string, error) {
user, err := twitchClient.GetUserInformation(strings.TrimLeft(username, "#@"))
if err != nil {
return "", errors.Wrap(err, "getting user info")
}
return user.ProfileImageURL, nil
}
func tplTwitchRecentGame(username string, v ...string) (string, error) {
game, _, err := twitchClient.GetRecentStreamInfo(strings.TrimLeft(username, "#"))
if len(v) > 0 && (err != nil || game == "") {