diff --git a/functions_irc.go b/functions_irc.go index 381bd2a..f34062a 100644 --- a/functions_irc.go +++ b/functions_irc.go @@ -23,12 +23,16 @@ func init() { tplFuncs.Register("fixUsername", plugins.GenericTemplateFunctionGetter(func(username string) string { return strings.TrimLeft(username, "@#") })) tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, fields map[string]interface{}) interface{} { - return func(idx int) (string, error) { + return func(idx int, fallback ...string) (string, error) { fields := r.GetMatchMessage().FindStringSubmatch(m.Trailing()) if len(fields) <= idx { return "", errors.New("group not found") } + if fields[idx] == "" && len(fallback) > 0 { + return fallback[0], nil + } + return fields[idx], nil } }) diff --git a/wiki/Home.md b/wiki/Home.md index 372647c..6b2a66b 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -160,7 +160,7 @@ Additionally there are some functions available in the templates: - `displayName [fallback]` - Returns the display name the specified user set for themselves - `fixUsername ` - Ensures the username no longer contains the `@` or `#` prefix - `followDate ` - Looks up when `from` followed `to` -- `group ` - Gets matching group specified by index from `match_message` regular expression +- `group [fallback]` - Gets matching group specified by index from `match_message` regular expression, when `fallback` is defined, it is used when group has an empty match - `recentGame [fallback]` - Returns the last played game name of the specified user (see shoutout example) or the `fallback` if the game could not be fetched. If no fallback was supplied the message will fail and not be sent. - `tag ` - Takes the message sent to the channel, returns the value of the tag specified - `toLower ` - Converts the given string to lower-case