counter: fix double counter api issue

This commit is contained in:
Chris Sexton 2023-10-03 09:52:11 -04:00
parent f2153bf0b4
commit f6cfec477f
1 changed files with 9 additions and 6 deletions

View File

@ -164,11 +164,9 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r
personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg) personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg)
} }
chs := p.cfg.GetMap("counter.channelItems", map[string]string{}) genericChs := p.cfg.GetArray("counter.channels", []string{})
ch, ok := chs[itemName] specificChs := p.cfg.GetMap("counter.channelItems", map[string]string{})
if len(chs) == 0 || !ok { ch, ok := specificChs[itemName]
return
}
req := &bot.Request{ req := &bot.Request{
Conn: p.b.DefaultConnector(), Conn: p.b.DefaultConnector(),
Kind: bot.Message, 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", 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) 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) p.b.Send(p.b.DefaultConnector(), bot.Message, ch, msg)
req.Msg.Channel = ch req.Msg.Channel = ch
} }