From 9670e0e6572b354941e2cf55d929f9a96f11dbad Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 4 Dec 2021 16:01:11 -0500 Subject: [PATCH] counter: reorder goal and count --- plugins/counter/api.go | 4 ++-- plugins/counter/counter.go | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/plugins/counter/api.go b/plugins/counter/api.go index d3c9445..4c78c1d 100644 --- a/plugins/counter/api.go +++ b/plugins/counter/api.go @@ -94,13 +94,13 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r Values: nil, Args: nil, } - item.UpdateDelta(req, delta) 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, p.cfg.Get("nick", "catbase"), personalMsg) + userName, itemName, delta, item.Count+delta, p.cfg.Get("nick", "catbase"), personalMsg) for _, ch := range chs { p.b.Send(p.b.DefaultConnector(), bot.Message, ch, msg) req.Msg.Channel = ch } + item.UpdateDelta(req, delta) j, _ := json.Marshal(struct{ Status bool }{true}) fmt.Fprint(w, string(j)) } diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index cc16a80..1cf4e55 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -593,9 +593,8 @@ func (p *CounterPlugin) incrementCmd(r bot.Request) bool { return false } log.Debug().Msgf("About to update item: %#v", item) + p.b.Send(r.Conn, bot.Message, channel, fmt.Sprintf("%s has %d %s.", nick, item.Count+1, item.Item)) item.UpdateDelta(&r, 1) - p.b.Send(r.Conn, bot.Message, channel, fmt.Sprintf("%s has %d %s.", nick, - item.Count, item.Item)) return true } @@ -618,9 +617,9 @@ func (p *CounterPlugin) decrementCmd(r bot.Request) bool { // Item ain't there, I guess return false } - item.UpdateDelta(&r, -1) p.b.Send(r.Conn, bot.Message, channel, fmt.Sprintf("%s has %d %s.", nick, - item.Count, item.Item)) + item.Count-1, item.Item)) + item.UpdateDelta(&r, -1) return true } @@ -642,9 +641,9 @@ func (p *CounterPlugin) addToCmd(r bot.Request) bool { } n, _ := strconv.Atoi(r.Values["amount"]) log.Debug().Msgf("About to update item by %d: %#v", n, item) - item.UpdateDelta(&r, n) p.b.Send(r.Conn, bot.Message, channel, fmt.Sprintf("%s has %d %s.", nick, - item.Count, item.Item)) + item.Count+n, item.Item)) + item.UpdateDelta(&r, n) return true } @@ -666,9 +665,9 @@ func (p *CounterPlugin) removeFromCmd(r bot.Request) bool { } n, _ := strconv.Atoi(r.Values["amount"]) log.Debug().Msgf("About to update item by -%d: %#v", n, item) - item.UpdateDelta(&r, -n) p.b.Send(r.Conn, bot.Message, channel, fmt.Sprintf("%s has %d %s.", nick, - item.Count, item.Item)) + item.Count-n, item.Item)) + item.UpdateDelta(&r, -n) return true } @@ -708,9 +707,9 @@ func (p *CounterPlugin) teaMatchCmd(r bot.Request) bool { if item.Count < 0 { delta = -1 } - item.UpdateDelta(&r, delta) p.b.Send(r.Conn, bot.Message, channel, fmt.Sprintf("%s... %s has %d %s", - strings.Join(everyDayImShuffling([]string{"bleep", "bloop", "blop"}), "-"), nick, item.Count, itemName)) + strings.Join(everyDayImShuffling([]string{"bleep", "bloop", "blop"}), "-"), nick, item.Count+delta, itemName)) + item.UpdateDelta(&r, delta) return true }