From 8d729f5d42c6a6533570c740bb363504be9961cb Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 7 Oct 2018 08:47:18 -0400 Subject: [PATCH] counter: make tea counter less strict --- plugins/counter/counter.go | 2 +- plugins/counter/counter_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index 790396b..f3ca7fe 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -240,7 +240,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool { } p.Bot.SendMessage(channel, out) return true - } else if tea, _ := regexp.MatchString("(?i)^tea\\. [^.]*\\. ((hot)|(iced))\\.?$", message.Body); tea { + } else if tea, _ := regexp.MatchString("(?i)^tea\\. [^.]*\\. ([^.]*\\.?)+$", message.Body); tea { item, err := GetItem(p.DB, nick, ":tea:") if err != nil { log.Printf("Error finding item %s.%s: %s.", nick, ":tea:", err) diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index a83b6aa..91f1ad6 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -37,6 +37,28 @@ func TestTeaEarlGreyHot(t *testing.T) { assert.Equal(t, 2, item.Count) } +func TestTeaTwoPeriods(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage("Tea. Earl Grey.")) + c.Message(makeMessage("Tea. Earl Grey.")) + item, err := GetItem(mb.DB(), "tester", ":tea:") + assert.Nil(t, err) + assert.Equal(t, 0, item.Count) +} + +func TestTeaMultiplePeriods(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage("Tea. Earl Grey. Spiked. Hot.")) + c.Message(makeMessage("Tea. Earl Grey. Spiked. Hot.")) + item, err := GetItem(mb.DB(), "tester", ":tea:") + assert.Nil(t, err) + assert.Equal(t, 2, item.Count) +} + func TestTeaGreenHot(t *testing.T) { mb := bot.NewMockBot() c := New(mb)