diff --git a/docs/content/configuration/templating.md b/docs/content/configuration/templating.md index 5988789..bab742a 100644 --- a/docs/content/configuration/templating.md +++ b/docs/content/configuration/templating.md @@ -467,7 +467,7 @@ Example: ``` # Your int this hour: {{ printf "%.0f" (mulf (seededRandom (list "int" .username (now | date "2006-01-02 15") | join ":")) 100) }}% -< Your int this hour: 82% +< Your int this hour: 41% ``` ### `spotifyCurrentPlaying` @@ -500,6 +500,19 @@ Example: * https://open.spotify.com/track/3HCzXf0lNpekSqsGBcGrCd ``` +### `streamIsLive` + +Check whether a given channel is currently live + +Syntax: `streamIsLive ` + +Example: + +``` +# {{ streamIsLive "luziferus" }} +* true +``` + ### `streamUptime` Returns the duration the stream is online (causes an error if no current stream is found) diff --git a/internal/template/twitch/stream.go b/internal/template/twitch/stream.go index 0b20b4c..95de83a 100644 --- a/internal/template/twitch/stream.go +++ b/internal/template/twitch/stream.go @@ -15,6 +15,7 @@ func init() { regFn, tplTwitchRecentGame, tplTwitchRecentTitle, + tplTwitchStreamIsLive, tplTwitchStreamUptime, ) } @@ -55,6 +56,20 @@ func tplTwitchRecentTitle(args plugins.RegistrationArguments) { }) } +func tplTwitchStreamIsLive(args plugins.RegistrationArguments) { + args.RegisterTemplateFunction("streamIsLive", plugins.GenericTemplateFunctionGetter(func(username string) bool { + _, err := args.GetTwitchClient().GetCurrentStreamInfo(context.Background(), strings.TrimLeft(username, "#")) + return err == nil + }), plugins.TemplateFuncDocumentation{ + Description: "Check whether a given channel is currently live", + Syntax: "streamIsLive ", + Example: &plugins.TemplateFuncDocumentationExample{ + Template: `{{ streamIsLive "luziferus" }}`, + FakedOutput: "true", + }, + }) +} + func tplTwitchStreamUptime(args plugins.RegistrationArguments) { args.RegisterTemplateFunction("streamUptime", plugins.GenericTemplateFunctionGetter(func(username string) (time.Duration, error) { si, err := args.GetTwitchClient().GetCurrentStreamInfo(context.Background(), strings.TrimLeft(username, "#"))