counter: maybe really fix it finally

This commit is contained in:
Chris Sexton 2023-10-04 10:19:21 -04:00
parent 9cecccfcdd
commit f18154be5b
1 changed files with 9 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/velour/catbase/bot/user" "github.com/velour/catbase/bot/user"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@ -81,7 +81,7 @@ func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWri
return return
} }
body, _ := ioutil.ReadAll(r.Body) body, _ := io.ReadAll(r.Body)
postData := map[string]string{} postData := map[string]string{}
err = json.Unmarshal(body, &postData) err = json.Unmarshal(body, &postData)
personalMsg := "" personalMsg := ""
@ -110,7 +110,13 @@ func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWri
} }
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*direction, p.cfg.Get("nick", "catbase"), personalMsg) userName, itemName, delta, item.Count+delta*direction, p.cfg.Get("nick", "catbase"), personalMsg)
for _, ch := range chs { if !ok {
chs := p.cfg.GetArray("counter.channels", []string{})
for _, ch := range chs {
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
} }