mirror of https://github.com/velour/catbase.git
This looks like += and -=
This commit is contained in:
parent
38a321f231
commit
10beb0a34f
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue