Merge branch 'tea'

* tea:
  Tea. Earl Grey. Hot.
This commit is contained in:
cws 2017-01-31 15:38:54 -05:00
commit c82d32e460
2 changed files with 24 additions and 1 deletions

View File

@ -135,7 +135,19 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
return false return false
} }
if message.Command && message.Body == "reset me" { if strings.ToLower(message.Body) == "tea. earl grey. hot." {
item, err := GetItem(p.DB, nick, "🍵")
if err != nil {
log.Printf("Error finding item %s.%s: %s.", nick, "🍵", err)
// Item ain't there, I guess
return false
}
log.Printf("About to update item: %#v", item)
item.UpdateDelta(1)
p.Bot.SendMessage(channel, fmt.Sprintf("bleep-bloop-blop... %s has %d 🍵",
nick, item.Count))
return true
} else if message.Command && message.Body == "reset me" {
items, err := GetItems(p.DB, strings.ToLower(nick)) items, err := GetItems(p.DB, strings.ToLower(nick))
if err != nil { if err != nil {
log.Printf("Error getting items to reset %s: %s", nick, err) log.Printf("Error getting items to reset %s: %s", nick, err)

View File

@ -26,6 +26,17 @@ func makeMessage(payload string) msg.Message {
} }
} }
func TestTeaEarlGreyHot(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
c.Message(makeMessage("Tea. Earl Grey. Hot."))
c.Message(makeMessage("Tea. Earl Grey. Hot."))
item, err := GetItem(mb.DB(), "tester", "🍵")
assert.Nil(t, err)
assert.Equal(t, 2, item.Count)
}
func TestResetMe(t *testing.T) { func TestResetMe(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) c := New(mb)