add feedback for when a seed isn't found

This commit is contained in:
skkiesel 2017-05-10 10:11:49 -04:00
parent 24f373d20f
commit efde5d804d
3 changed files with 14 additions and 3 deletions

View File

@ -19,6 +19,7 @@ import (
var (
NO_BABBLER = errors.New("babbler not found")
SAID_NOTHING = errors.New("hasn't said anything yet")
NEVER_SAID = errors.New("never said that")
)
@ -122,7 +123,7 @@ func (p *BabblerPlugin) makeBabbler(babbler string) (int64, error) {
func (p *BabblerPlugin) getBabbler(babbler string) (int64, error) {
id := int64(-1)
err := p.db.Get(&id, `select id from babblers where babbler = ?`, babbler)
if err != nil && err == sql.ErrNoRows {
if err == sql.ErrNoRows {
return -1, NO_BABBLER
}
return id, err
@ -164,6 +165,9 @@ func (p *BabblerPlugin) getOrCreateBabbler(babbler string) (int64, error) {
func (p *BabblerPlugin) getWordId(babblerId int64, word string) (int64, error) {
id := int64(-1)
err := p.db.Get(&id, `select id from babblerWords where babblerId = ? and word = ?`, babblerId, word)
if err == sql.ErrNoRows {
return -1, NEVER_SAID
}
return id, err
}
@ -199,6 +203,9 @@ func (p *BabblerPlugin) incrementRootWordFrequency(babblerId int64, word string)
func (p *BabblerPlugin) getWordArcHelper(fromWordId, toWordId int64) (int64, error) {
id := int64(-1)
err := p.db.Get(&id, `select id from babblerArcs where fromWordId = ? and toWordId = ?`, fromWordId, toWordId)
if err == sql.ErrNoRows {
return -1, NEVER_SAID
}
return id, err
}

View File

@ -136,7 +136,8 @@ func TestBabblerBadSeed(t *testing.T) {
seabass.Body = "This is a long message"
c.Message(seabass)
c.Message(makeMessage("!seabass says noooo this is bad"))
assert.Len(t, mb.Messages, 0)
assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'")
}
func TestBabblerBadSeed2(t *testing.T) {
@ -152,7 +153,8 @@ func TestBabblerBadSeed2(t *testing.T) {
seabass.Body = "This is a long message"
c.Message(seabass)
c.Message(makeMessage("!seabass says This is a really"))
assert.Len(t, mb.Messages, 0)
assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'")
}
func TestBabblerBatch(t *testing.T) {

View File

@ -42,6 +42,8 @@ func (p *BabblerPlugin) getBabble(tokens []string) (string, bool) {
if err != nil {
if err == SAID_NOTHING {
return fmt.Sprintf("%s hasn't said anything yet.", who), true
} else if err == NEVER_SAID {
return fmt.Sprintf("%s never said '%s'", who, strings.Join(tokens[2:], " ")), true
}
} else if saying != "" {
return saying, true