counter: make tea counter less strict

This commit is contained in:
Chris Sexton 2018-10-07 08:47:18 -04:00 committed by Chris Sexton
parent b1a4fd2050
commit 8d729f5d42
2 changed files with 23 additions and 1 deletions

View File

@ -240,7 +240,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
} }
p.Bot.SendMessage(channel, out) p.Bot.SendMessage(channel, out)
return true 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:") item, err := GetItem(p.DB, nick, ":tea:")
if err != nil { if err != nil {
log.Printf("Error finding item %s.%s: %s.", nick, ":tea:", err) log.Printf("Error finding item %s.%s: %s.", nick, ":tea:", err)

View File

@ -37,6 +37,28 @@ func TestTeaEarlGreyHot(t *testing.T) {
assert.Equal(t, 2, item.Count) 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) { func TestTeaGreenHot(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) c := New(mb)