mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
[counter] Add template support for counter step
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f001b79635
commit
287a38aa02
3 changed files with 26 additions and 5 deletions
|
@ -36,8 +36,8 @@ func init() {
|
|||
Key: "counter_step",
|
||||
Name: "Counter Step",
|
||||
Optional: true,
|
||||
SupportTemplate: false,
|
||||
Type: plugins.ActionDocumentationFieldTypeInt64,
|
||||
SupportTemplate: true,
|
||||
Type: plugins.ActionDocumentationFieldTypeString,
|
||||
},
|
||||
{
|
||||
Default: "",
|
||||
|
@ -132,8 +132,16 @@ func (a ActorCounter) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule, ev
|
|||
}
|
||||
|
||||
var counterStep int64 = 1
|
||||
if s := attrs.MustInt64("counter_step", ptrIntZero); s != 0 {
|
||||
counterStep = s
|
||||
if s := attrs.MustString("counter_step", ptrStringEmpty); s != "" {
|
||||
parseStep, err := formatMessage(s, m, r, eventData)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "execute counter step template")
|
||||
}
|
||||
|
||||
counterStep, err = strconv.ParseInt(parseStep, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "parse counter step")
|
||||
}
|
||||
}
|
||||
|
||||
return false, errors.Wrap(
|
||||
|
|
|
@ -289,7 +289,7 @@ func (f *FieldCollection) String(name string) (string, error) {
|
|||
return iv.String(), nil
|
||||
}
|
||||
|
||||
return "", ErrValueMismatch
|
||||
return fmt.Sprintf("%v", v), nil
|
||||
}
|
||||
|
||||
// StringSlice tries to read key name as []string
|
||||
|
|
|
@ -78,3 +78,16 @@ func TestFieldCollectionNilDataGet(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFieldCollectionIntToString(t *testing.T) {
|
||||
var val int = 123
|
||||
fc := FieldCollectionFromData(map[string]interface{}{"test": val})
|
||||
|
||||
if !fc.CanString("test") {
|
||||
t.Fatalf("cannot convert %T to string", val)
|
||||
}
|
||||
|
||||
if v := fc.MustString("test", nil); v != "123" {
|
||||
t.Errorf("unexpected value: 123 != %s", v)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue