2024-01-01 16:52:18 +00:00
|
|
|
// Package slice contains slice manipulation helpers
|
2022-06-20 19:41:53 +00:00
|
|
|
package slice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Luzifer/go_helpers/v2/str"
|
2022-11-02 21:38:14 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/v3/plugins"
|
2022-06-20 19:41:53 +00:00
|
|
|
)
|
|
|
|
|
2024-01-01 16:52:18 +00:00
|
|
|
// Register provides the plugins.RegisterFunc
|
2022-06-20 19:41:53 +00:00
|
|
|
func Register(args plugins.RegistrationArguments) error {
|
2023-08-25 21:37:37 +00:00
|
|
|
args.RegisterTemplateFunction("inList", plugins.GenericTemplateFunctionGetter(func(search string, list ...string) bool {
|
|
|
|
return str.StringInSlice(search, list)
|
|
|
|
}), plugins.TemplateFuncDocumentation{
|
|
|
|
Description: "Tests whether a string is in a given list of strings (for conditional templates).",
|
|
|
|
Syntax: "inList <search> <...string>",
|
|
|
|
Example: &plugins.TemplateFuncDocumentationExample{
|
|
|
|
MatchMessage: "!command (.*)",
|
|
|
|
MessageContent: "!command foo",
|
|
|
|
Template: `{{ inList (group 1) "foo" "bar" }}`,
|
|
|
|
ExpectedOutput: "true",
|
|
|
|
},
|
|
|
|
})
|
2022-06-20 19:41:53 +00:00
|
|
|
return nil
|
|
|
|
}
|