mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-30 00:21:16 +00:00
[counter] Add counterValueAdd
template function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
5d0f1acbf2
commit
996cc2877d
2 changed files with 25 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue