mirror of https://github.com/velour/catbase.git
add feedback for when a seed isn't found
This commit is contained in:
parent
24f373d20f
commit
efde5d804d
|
@ -19,6 +19,7 @@ import (
|
||||||
var (
|
var (
|
||||||
NO_BABBLER = errors.New("babbler not found")
|
NO_BABBLER = errors.New("babbler not found")
|
||||||
SAID_NOTHING = errors.New("hasn't said anything yet")
|
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) {
|
func (p *BabblerPlugin) getBabbler(babbler string) (int64, error) {
|
||||||
id := int64(-1)
|
id := int64(-1)
|
||||||
err := p.db.Get(&id, `select id from babblers where babbler = ?`, babbler)
|
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 -1, NO_BABBLER
|
||||||
}
|
}
|
||||||
return id, err
|
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) {
|
func (p *BabblerPlugin) getWordId(babblerId int64, word string) (int64, error) {
|
||||||
id := int64(-1)
|
id := int64(-1)
|
||||||
err := p.db.Get(&id, `select id from babblerWords where babblerId = ? and word = ?`, babblerId, word)
|
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
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +203,9 @@ func (p *BabblerPlugin) incrementRootWordFrequency(babblerId int64, word string)
|
||||||
func (p *BabblerPlugin) getWordArcHelper(fromWordId, toWordId int64) (int64, error) {
|
func (p *BabblerPlugin) getWordArcHelper(fromWordId, toWordId int64) (int64, error) {
|
||||||
id := int64(-1)
|
id := int64(-1)
|
||||||
err := p.db.Get(&id, `select id from babblerArcs where fromWordId = ? and toWordId = ?`, fromWordId, toWordId)
|
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
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,8 @@ func TestBabblerBadSeed(t *testing.T) {
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
c.Message(seabass)
|
c.Message(seabass)
|
||||||
c.Message(makeMessage("!seabass says noooo this is bad"))
|
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) {
|
func TestBabblerBadSeed2(t *testing.T) {
|
||||||
|
@ -152,7 +153,8 @@ func TestBabblerBadSeed2(t *testing.T) {
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
c.Message(seabass)
|
c.Message(seabass)
|
||||||
c.Message(makeMessage("!seabass says This is a really"))
|
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) {
|
func TestBabblerBatch(t *testing.T) {
|
||||||
|
|
|
@ -42,6 +42,8 @@ func (p *BabblerPlugin) getBabble(tokens []string) (string, bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == SAID_NOTHING {
|
if err == SAID_NOTHING {
|
||||||
return fmt.Sprintf("%s hasn't said anything yet.", who), true
|
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 != "" {
|
} else if saying != "" {
|
||||||
return saying, true
|
return saying, true
|
||||||
|
|
Loading…
Reference in New Issue