From b0d9b5782f5e0a7346ae0ce0f76b6f1432db586f Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 20 Jun 2022 21:41:53 +0200 Subject: [PATCH] [template] Add `inList` function Signed-off-by: Knut Ahlers --- internal/template/slice/slice.go | 11 +++++++++++ plugins_core.go | 2 ++ wiki/Templating.md | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 internal/template/slice/slice.go diff --git a/internal/template/slice/slice.go b/internal/template/slice/slice.go new file mode 100644 index 0000000..17eec4a --- /dev/null +++ b/internal/template/slice/slice.go @@ -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 +} diff --git a/plugins_core.go b/plugins_core.go index c4b2b6b..7b9157e 100644 --- a/plugins_core.go +++ b/plugins_core.go @@ -27,6 +27,7 @@ import ( "github.com/Luzifer/twitch-bot/internal/apimodules/overlays" "github.com/Luzifer/twitch-bot/internal/template/numeric" "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/twitch" ) @@ -52,6 +53,7 @@ var ( // Template functions numeric.Register, random.Register, + slice.Register, // API-only modules customevent.Register, diff --git a/wiki/Templating.md b/wiki/Templating.md index 1766922..68a6491 100644 --- a/wiki/Templating.md +++ b/wiki/Templating.md @@ -184,6 +184,21 @@ Example: < 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` Gets the last quote index in the quote database for the current channel