From 6d358b307f6dd15f4c8f4427577e4b0afc911819 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 17 Jun 2021 18:08:52 +0200 Subject: [PATCH] Apply time-fix, json is not able to decode `2s` but `2` which is ns instead of s Signed-off-by: Knut Ahlers --- action_timeout.go | 2 +- helpers.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 helpers.go diff --git a/action_timeout.go b/action_timeout.go index 6a11cddc..05c61c54 100644 --- a/action_timeout.go +++ b/action_timeout.go @@ -26,7 +26,7 @@ func (a ActorTimeout) Execute(c *irc.Client, m *irc.Message, r *Rule) error { Command: "PRIVMSG", Params: []string{ m.Params[0], - fmt.Sprintf("/timeout %s %d", m.User, *a.Timeout/time.Second), + fmt.Sprintf("/timeout %s %d", m.User, fixDurationValue(*a.Timeout)/time.Second), }, }), "sending timeout", diff --git a/helpers.go b/helpers.go new file mode 100644 index 00000000..5807ebd0 --- /dev/null +++ b/helpers.go @@ -0,0 +1,11 @@ +package main + +import "time" + +func fixDurationValue(d time.Duration) time.Duration { + if d >= time.Second { + return d + } + + return d * time.Second +}