[counter] Add counterValueAdd template function

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-06-12 23:48:22 +02:00
parent 5d0f1acbf2
commit 996cc2877d
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 25 additions and 0 deletions

View file

@ -137,6 +137,19 @@ func Register(args plugins.RegistrationArguments) error {
return GetCounterValue(db, name)
}))
args.RegisterTemplateFunction("counterValueAdd", plugins.GenericTemplateFunctionGetter(func(name string, val ...int64) (int64, error) {
var mod int64 = 1
if len(val) > 0 {
mod = val[0]
}
if err := UpdateCounter(db, name, mod, false); err != nil {
return 0, errors.Wrap(err, "updating counter")
}
return GetCounterValue(db, name)
}))
return nil
}

View file

@ -82,6 +82,18 @@ Example:
< 5
```
#### `counterValueAdd`
Adds the given value (or 1 if no value) to the counter and returns its new value
Syntax: `counterValueAdd <counter name> [increase=1]`
Example:
```
# {{ counterValueAdd "myCounter" }} {{ counterValueAdd "myCounter" 5 }}
< 1 6
```
#### `displayName`
Returns the display name the specified user set for themselves