From f6cfec477fda5b86c6fb5e1b604510b05a7d65e9 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Tue, 3 Oct 2023 09:52:11 -0400 Subject: [PATCH] counter: fix double counter api issue --- plugins/counter/api.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/counter/api.go b/plugins/counter/api.go index fac0ce9..1f6d515 100644 --- a/plugins/counter/api.go +++ b/plugins/counter/api.go @@ -164,11 +164,9 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg) } - chs := p.cfg.GetMap("counter.channelItems", map[string]string{}) - ch, ok := chs[itemName] - if len(chs) == 0 || !ok { - return - } + genericChs := p.cfg.GetArray("counter.channels", []string{}) + specificChs := p.cfg.GetMap("counter.channelItems", map[string]string{}) + ch, ok := specificChs[itemName] req := &bot.Request{ Conn: p.b.DefaultConnector(), Kind: bot.Message, @@ -185,7 +183,12 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r } msg := fmt.Sprintf("%s changed their %s counter by %d for a total of %d via the amazing %s API. %s", userName, itemName, delta, item.Count+delta, p.cfg.Get("nick", "catbase"), personalMsg) - for _, ch := range chs { + if !ok { + for _, ch := range genericChs { + p.b.Send(p.b.DefaultConnector(), bot.Message, ch, msg) + req.Msg.Channel = ch + } + } else { p.b.Send(p.b.DefaultConnector(), bot.Message, ch, msg) req.Msg.Channel = ch }