counter: reorder goal and count

This commit is contained in:
Chris Sexton 2021-12-04 16:01:11 -05:00 committed by Chris Sexton
parent 6d004d8d1f
commit 9670e0e657
2 changed files with 11 additions and 12 deletions

View File

@ -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))
}

View File

@ -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
}