From efde5d804d90738586aadb6c876ee1143527e02c Mon Sep 17 00:00:00 2001 From: skkiesel Date: Wed, 10 May 2017 10:11:49 -0400 Subject: [PATCH] add feedback for when a seed isn't found --- plugins/babbler/babbler.go | 9 ++++++++- plugins/babbler/babbler_test.go | 6 ++++-- plugins/babbler/commands.go | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/babbler/babbler.go b/plugins/babbler/babbler.go index b6e1598..6073d2d 100644 --- a/plugins/babbler/babbler.go +++ b/plugins/babbler/babbler.go @@ -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 } diff --git a/plugins/babbler/babbler_test.go b/plugins/babbler/babbler_test.go index da8e502..a568b8b 100644 --- a/plugins/babbler/babbler_test.go +++ b/plugins/babbler/babbler_test.go @@ -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) { diff --git a/plugins/babbler/commands.go b/plugins/babbler/commands.go index c52210a..b16f768 100644 --- a/plugins/babbler/commands.go +++ b/plugins/babbler/commands.go @@ -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