diff --git a/docs/content/configuration/templating.md b/docs/content/configuration/templating.md index 97992e1..b4a1335 100644 --- a/docs/content/configuration/templating.md +++ b/docs/content/configuration/templating.md @@ -288,6 +288,19 @@ Example: < 10000 ``` +### `profileImage` + +Gets the URL of the given users profile image + +Syntax: `profileImage ` + +Example: + +``` +# {{ profileImage .username }} +< https://static-cdn.jtvnw.net/jtv_user_pictures/[...].png +``` + ### `randomString` Randomly picks a string from a list of strings diff --git a/functions_twitch.go b/functions_twitch.go index 783f563..d5c92ab 100644 --- a/functions_twitch.go +++ b/functions_twitch.go @@ -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 == "") {