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