From cc8160ec678dac99f48387a7a959a41f8075a05f Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 6 Mar 2021 01:42:40 +0100 Subject: [PATCH] Fix: Allow templating to read user input Signed-off-by: Knut Ahlers --- action_counter.go | 14 +++++++++++++- config.go | 2 +- wiki/Home.md | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/action_counter.go b/action_counter.go index 442864e..18b7cb9 100644 --- a/action_counter.go +++ b/action_counter.go @@ -1,6 +1,8 @@ package main import ( + "strconv" + "github.com/go-irc/irc" "github.com/pkg/errors" ) @@ -17,8 +19,18 @@ func init() { } if r.CounterSet != nil { + parseValue, err := formatMessage(*r.CounterSet, m, ruleDef, nil) + if err != nil { + return errors.Wrap(err, "execute counter value template") + } + + counterValue, err := strconv.ParseInt(parseValue, 10, 64) + if err != nil { + return errors.Wrap(err, "parse counter value") + } + return errors.Wrap( - store.UpdateCounter(counterName, *r.CounterSet, true), + store.UpdateCounter(counterName, counterValue, true), "set counter", ) } diff --git a/config.go b/config.go index 62d6909..48fdc27 100644 --- a/config.go +++ b/config.go @@ -179,7 +179,7 @@ func (r *rule) Matches(m *irc.Message, event *string) bool { type ruleAction struct { Ban *string `json:"ban" yaml:"ban"` Command []string `json:"command" yaml:"command"` - CounterSet *int64 `json:"counter_set" yaml:"counter_set"` + CounterSet *string `json:"counter_set" yaml:"counter_set"` CounterStep *int64 `json:"counter_step" yaml:"counter_step"` Counter *string `json:"counter" yaml:"counter"` DeleteMessage *bool `json:"delete_message" yaml:"delete_message"` diff --git a/wiki/Home.md b/wiki/Home.md index 383ae50..9e21f3e 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -24,7 +24,8 @@ rules: # See below for examples # Modify an internal counter value (does NOT send a chat line) - counter: "counterid" # String to identify the counter, applies templating - counter_set: 25 # Integer, set counter to value (counter_step is ignored if set) + counter_set: 25 # String, set counter to value (counter_step is ignored if set), + # applies templating but MUST result in a parseable integer counter_step: 1 # Integer, can be negative or positive, default: +1 # Issue a delete on the message caught