mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-09-07 20:39:07 +00:00
[templating] Add streamIsLive
function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
0a37873241
commit
8e8895d32e
@ -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 <username>`
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# {{ streamIsLive "luziferus" }}
|
||||
* true
|
||||
```
|
||||
|
||||
### `streamUptime`
|
||||
|
||||
Returns the duration the stream is online (causes an error if no current stream is found)
|
||||
|
@ -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 <username>",
|
||||
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, "#"))
|
||||
|
Loading…
Reference in New Issue
Block a user