From 10beb0a34fa4f04e4a9f30b6f5ed72704e8040e7 Mon Sep 17 00:00:00 2001 From: Steve McCoy Date: Tue, 17 Jan 2017 17:57:39 -0500 Subject: [PATCH] This looks like += and -= --- plugins/counter/counter.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index d77e013..2ca7ff3 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -267,6 +267,49 @@ func (p *CounterPlugin) Message(message msg.Message) bool { item.Count, item.Item)) return true } + } else if len(parts) == 3 { + // Need to have at least 3 characters to ++ or -- + if len(parts[0]) < 3 { + return false + } + + subject := strings.ToLower(nick) + itemName := strings.ToLower(parts[0])[:len(parts[0])-2] + + if nameParts := strings.SplitN(itemName, ".", 2); len(nameParts) == 2 { + subject = nameParts[0] + itemName = nameParts[1] + } + + if parts[1] == "+=" { + // += those fuckers + item, err := GetItem(p.DB, subject, itemName) + if err != nil { + log.Printf("Error finding item %s.%s: %s.", subject, itemName, err) + // Item ain't there, I guess + return false + } + n := strconv.Atoi(parts[2]) + log.Printf("About to update item by %d: %#v", n, item) + item.UpdateDelta(n) + p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, + item.Count, item.Item)) + return true + } else if parts[1] == "-=" { + // -= those fuckers + item, err := GetItem(p.DB, subject, itemName) + if err != nil { + log.Printf("Error finding item %s.%s: %s.", subject, itemName, err) + // Item ain't there, I guess + return false + } + n := strconv.Atoi(parts[2]) + log.Printf("About to update item by -%d: %#v", n, item) + item.UpdateDelta(-n) + p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, + item.Count, item.Item)) + return true + } } return false