[template] Add inList function

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-06-20 21:41:53 +02:00
parent beb491f015
commit b0d9b5782f
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
3 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1,11 @@
package slice
import (
"github.com/Luzifer/go_helpers/v2/str"
"github.com/Luzifer/twitch-bot/plugins"
)
func Register(args plugins.RegistrationArguments) error {
args.RegisterTemplateFunction("inList", plugins.GenericTemplateFunctionGetter(str.StringInSlice))
return nil
}

View file

@ -27,6 +27,7 @@ import (
"github.com/Luzifer/twitch-bot/internal/apimodules/overlays" "github.com/Luzifer/twitch-bot/internal/apimodules/overlays"
"github.com/Luzifer/twitch-bot/internal/template/numeric" "github.com/Luzifer/twitch-bot/internal/template/numeric"
"github.com/Luzifer/twitch-bot/internal/template/random" "github.com/Luzifer/twitch-bot/internal/template/random"
"github.com/Luzifer/twitch-bot/internal/template/slice"
"github.com/Luzifer/twitch-bot/plugins" "github.com/Luzifer/twitch-bot/plugins"
"github.com/Luzifer/twitch-bot/twitch" "github.com/Luzifer/twitch-bot/twitch"
) )
@ -52,6 +53,7 @@ var (
// Template functions // Template functions
numeric.Register, numeric.Register,
random.Register, random.Register,
slice.Register,
// API-only modules // API-only modules
customevent.Register, customevent.Register,

View file

@ -184,6 +184,21 @@ Example:
< test - oops < test - oops
``` ```
#### `inList`
Tests whether a string is in a given list of strings (for conditional templates).
Syntax: `inList "search" "item1" "item2" [...]`
Example:
```
! !command (.*)
> !command foo
# {{ inList (group 1) "foo" "bar" }}
< true
```
#### `lastQuoteIndex` #### `lastQuoteIndex`
Gets the last quote index in the quote database for the current channel Gets the last quote index in the quote database for the current channel