[templating] Add followAge function

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-12-26 21:19:48 +01:00
parent 9106bcbe3f
commit 63ea08a4cd
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 19 additions and 0 deletions

View file

@ -4,6 +4,8 @@ import (
"strings"
"time"
"github.com/pkg/errors"
"github.com/Luzifer/twitch-bot/v3/plugins"
)
@ -17,6 +19,10 @@ func init() {
return displayName, err
}))
tplFuncs.Register("followAge", plugins.GenericTemplateFunctionGetter(func(from, to string) (time.Duration, error) {
since, err := twitchClient.GetFollowDate(from, to)
return time.Since(since), errors.Wrap(err, "getting follow date")
}))
tplFuncs.Register("followDate", plugins.GenericTemplateFunctionGetter(func(from, to string) (time.Time, error) { return twitchClient.GetFollowDate(from, to) }))
tplFuncs.Register("recentGame", plugins.GenericTemplateFunctionGetter(func(username string, v ...string) (string, error) {

View file

@ -134,6 +134,19 @@ Example:
< 5 hours, 33 minutes, 12 seconds - 5 hours, 33 minutes
```
#### `followAge`
Looks up when `from` followed `to` and returns the duration between then and now
Syntax: `followAge <from> <to>`
Example:
```
# {{ followAge "tezrian" "luziferus" }}
< 15004h14m59.116620989s
```
#### `followDate`
Looks up when `from` followed `to`