mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
Compare commits
34 commits
aa7fd0118a
...
06b3ff2f2f
Author | SHA1 | Date | |
---|---|---|---|
06b3ff2f2f | |||
9656010ff3 | |||
1a5b3f6bbd | |||
7df78cf1ff | |||
e16c623ec4 | |||
32df28f1d8 | |||
1a425416b8 | |||
dc21293e35 | |||
70e268f1b5 | |||
721a16ad9f | |||
5f5fcf6824 | |||
c52d66cea7 | |||
debd41af50 | |||
098a0b120d | |||
a12dbc0ed3 | |||
8194d1b80f | |||
770b9d316c | |||
4f00beefd0 | |||
f9198367a5 | |||
960e205ba3 | |||
3f1525b0f2 | |||
7e783b2d00 | |||
8ca3642919 | |||
338284b89b | |||
e81ffd5acf | |||
529f08db18 | |||
ba01c3c2f0 | |||
0075da1eba | |||
bb46ba5d0e | |||
0e9027fa3f | |||
f1f3e70d0d | |||
5f07a66405 | |||
945fb155b4 | |||
0d76c58ede |
2 changed files with 62 additions and 1 deletions
|
@ -392,6 +392,32 @@ Example:
|
|||
< @user @user @user
|
||||
```
|
||||
|
||||
### `parseDuration`
|
||||
|
||||
Parses a duration (i.e. 1h25m10s) into a time.Duration
|
||||
|
||||
Syntax: `parseDuration <duration>`
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# {{ parseDuration "1h30s" }}
|
||||
< 1h0m30s
|
||||
```
|
||||
|
||||
### `parseDurationToSeconds`
|
||||
|
||||
Parses a duration (i.e. 1h25m10s) into a number of seconds
|
||||
|
||||
Syntax: `parseDurationToSeconds <duration>`
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# {{ parseDurationToSeconds "1h25m10s" }}
|
||||
< 5110
|
||||
```
|
||||
|
||||
### `pow`
|
||||
|
||||
Returns float from calculation: `float1 ** float2`
|
||||
|
@ -480,7 +506,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: 23%
|
||||
< Your int this hour: 24%
|
||||
```
|
||||
|
||||
### `spotifyCurrentPlaying`
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
package date
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Luzifer/twitch-bot/v3/plugins"
|
||||
)
|
||||
|
||||
|
@ -27,5 +30,37 @@ func Register(args plugins.RegistrationArguments) error {
|
|||
},
|
||||
})
|
||||
|
||||
args.RegisterTemplateFunction("parseDuration", plugins.GenericTemplateFunctionGetter(func(duration string) (time.Duration, error) {
|
||||
d, err := time.ParseDuration(duration)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("parsing duration: %w", err)
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}), plugins.TemplateFuncDocumentation{
|
||||
Description: `Parses a duration (i.e. 1h25m10s) into a time.Duration`,
|
||||
Syntax: "parseDuration <duration>",
|
||||
Example: &plugins.TemplateFuncDocumentationExample{
|
||||
Template: `{{ parseDuration "1h30s" }}`,
|
||||
ExpectedOutput: "1h0m30s",
|
||||
},
|
||||
})
|
||||
|
||||
args.RegisterTemplateFunction("parseDurationToSeconds", plugins.GenericTemplateFunctionGetter(func(duration string) (int64, error) {
|
||||
d, err := time.ParseDuration(duration)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("parsing duration: %w", err)
|
||||
}
|
||||
|
||||
return int64(d / time.Second), nil
|
||||
}), plugins.TemplateFuncDocumentation{
|
||||
Description: `Parses a duration (i.e. 1h25m10s) into a number of seconds`,
|
||||
Syntax: "parseDurationToSeconds <duration>",
|
||||
Example: &plugins.TemplateFuncDocumentationExample{
|
||||
Template: `{{ parseDurationToSeconds "1h25m10s" }}`,
|
||||
ExpectedOutput: "5110",
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue