diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index 1845d16..64b78a3 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -6,6 +6,7 @@ import ( "database/sql" "fmt" "log" + "regexp" "strconv" "strings" @@ -135,7 +136,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool { return false } - if strings.ToLower(message.Body) == "tea. earl grey. hot." { + if tea, _ := regexp.MatchString("(?i)^tea\\. [0-9A-Za-z_ ]*\\. (hot)|(iced)\\.?$", message.Body); tea { item, err := GetItem(p.DB, nick, "🍵") if err != nil { log.Printf("Error finding item %s.%s: %s.", nick, "🍵", err) diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index 6e928a8..1ac2bb3 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -37,6 +37,29 @@ func TestTeaEarlGreyHot(t *testing.T) { assert.Equal(t, 2, item.Count) } +func TestTeaGreenHot(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage("Tea. Green. Hot.")) + c.Message(makeMessage("Tea. Green. Hot")) + c.Message(makeMessage("Tea. Green. Iced.")) + item, err := GetItem(mb.DB(), "tester", "🍵") + assert.Nil(t, err) + assert.Equal(t, 3, item.Count) +} + +func TestTeaUnrelated(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage("Tea.")) + c.Message(makeMessage("Tea. It's great.")) + item, err := GetItem(mb.DB(), "tester", "🍵") + assert.Nil(t, err) + assert.Equal(t, 0, item.Count) +} + func TestResetMe(t *testing.T) { mb := bot.NewMockBot() c := New(mb)