2020-12-21 00:32:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-irc/irc"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-12-25 18:31:07 +00:00
|
|
|
registerAction(func(c *irc.Client, m *irc.Message, ruleDef *rule, r *ruleAction) error {
|
2020-12-21 00:32:39 +00:00
|
|
|
if r.Counter == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-25 23:31:49 +00:00
|
|
|
counterName, err := formatMessage(*r.Counter, m, ruleDef, nil)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "preparing response")
|
|
|
|
}
|
|
|
|
|
2021-03-06 00:35:20 +00:00
|
|
|
if r.CounterSet != nil {
|
|
|
|
return errors.Wrap(
|
|
|
|
store.UpdateCounter(counterName, *r.CounterSet, true),
|
|
|
|
"set counter",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-21 00:32:39 +00:00
|
|
|
var counterStep int64 = 1
|
|
|
|
if r.CounterStep != nil {
|
|
|
|
counterStep = *r.CounterStep
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.Wrap(
|
2020-12-25 23:31:49 +00:00
|
|
|
store.UpdateCounter(counterName, counterStep, false),
|
2020-12-21 00:32:39 +00:00
|
|
|
"update counter",
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|