mirror of https://github.com/velour/catbase.git
"Tea. Earl Grey. Hot." generalized for any tea, hot or iced.
This commit is contained in:
parent
c82d32e460
commit
6917e091af
|
@ -6,6 +6,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
|
||||||
return false
|
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, "🍵")
|
item, err := GetItem(p.DB, nick, "🍵")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error finding item %s.%s: %s.", nick, "🍵", err)
|
log.Printf("Error finding item %s.%s: %s.", nick, "🍵", err)
|
||||||
|
|
|
@ -37,6 +37,29 @@ func TestTeaEarlGreyHot(t *testing.T) {
|
||||||
assert.Equal(t, 2, item.Count)
|
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) {
|
func TestResetMe(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
c := New(mb)
|
||||||
|
|
Loading…
Reference in New Issue