mirror of https://github.com/velour/catbase.git
Merge pull request #61 from velour/more_babbler_stuff
quiet down the babbler
This commit is contained in:
commit
4664ffec58
|
@ -121,11 +121,16 @@ func (p *BabblerPlugin) Message(message msg.Message) bool {
|
||||||
saidWhat, saidSomething = p.getBabbleWithSuffix(tokens)
|
saidWhat, saidSomething = p.getBabbleWithSuffix(tokens)
|
||||||
} else if numTokens >= 2 && tokens[1] == "says-middle-out" {
|
} else if numTokens >= 2 && tokens[1] == "says-middle-out" {
|
||||||
saidWhatStart, saidSomethingStart := p.getBabbleWithSuffix(tokens)
|
saidWhatStart, saidSomethingStart := p.getBabbleWithSuffix(tokens)
|
||||||
|
if !saidSomethingStart || saidWhatStart == strings.Join(tokens[2:], " ") {
|
||||||
|
saidSomething = saidSomethingStart
|
||||||
|
saidWhat = saidWhatStart
|
||||||
|
} else {
|
||||||
saidWhatEnd, saidSomethingEnd := p.getBabble(tokens)
|
saidWhatEnd, saidSomethingEnd := p.getBabble(tokens)
|
||||||
saidSomething = saidSomethingStart && saidSomethingEnd
|
saidSomething = saidSomethingStart && saidSomethingEnd
|
||||||
if saidSomething {
|
if saidSomething {
|
||||||
saidWhat = saidWhatStart + " " + strings.Join(strings.Fields(saidWhatEnd)[len(tokens)-2:], " ")
|
saidWhat = saidWhatStart + " " + strings.Join(strings.Fields(saidWhatEnd)[len(tokens)-2:], " ")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if len(tokens) == 4 && strings.Index(lowercase, "initialize babbler for ") == 0 {
|
} else if len(tokens) == 4 && strings.Index(lowercase, "initialize babbler for ") == 0 {
|
||||||
saidWhat, saidSomething = p.initializeBabbler(tokens)
|
saidWhat, saidSomething = p.initializeBabbler(tokens)
|
||||||
} else if strings.Index(lowercase, "batch learn for ") == 0 {
|
} else if strings.Index(lowercase, "batch learn for ") == 0 {
|
||||||
|
|
|
@ -31,9 +31,9 @@ func TestBabblerNoBabbler(t *testing.T) {
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, c)
|
||||||
c.Message(makeMessage("!seabass2 says"))
|
c.Message(makeMessage("!seabass2 says"))
|
||||||
res := assert.Len(t, mb.Messages, 1)
|
res := assert.Len(t, mb.Messages, 0)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "seabass2 babbler not found")
|
// assert.Contains(t, mb.Messages[0], "seabass2 babbler not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBabblerNothingSaid(t *testing.T) {
|
func TestBabblerNothingSaid(t *testing.T) {
|
||||||
|
@ -251,6 +251,21 @@ func TestBabblerMiddleOutSeed(t *testing.T) {
|
||||||
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
|
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBabblerBadMiddleOutSeed(t *testing.T) {
|
||||||
|
mb := bot.NewMockBot()
|
||||||
|
c := New(mb)
|
||||||
|
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
|
assert.NotNil(t, c)
|
||||||
|
seabass := makeMessage("It's easier to test with unique messages")
|
||||||
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
|
res := c.Message(seabass)
|
||||||
|
res = c.Message(makeMessage("!seabass says-middle-out anything true"))
|
||||||
|
assert.Len(t, mb.Messages, 1)
|
||||||
|
assert.True(t, res)
|
||||||
|
assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestBabblerBatch(t *testing.T) {
|
func TestBabblerBatch(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
c := New(mb)
|
||||||
|
|
|
@ -28,7 +28,8 @@ func (p *BabblerPlugin) getBabble(tokens []string) (string, bool) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == NO_BABBLER {
|
if err == NO_BABBLER {
|
||||||
return fmt.Sprintf("%s babbler not found.", who), true
|
// return fmt.Sprintf("%s babbler not found.", who), true
|
||||||
|
return "", false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -58,7 +59,8 @@ func (p *BabblerPlugin) getBabbleWithSuffix(tokens []string) (string, bool) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == NO_BABBLER {
|
if err == NO_BABBLER {
|
||||||
return fmt.Sprintf("%s babbler not found.", who), true
|
// return fmt.Sprintf("%s babbler not found.", who), true
|
||||||
|
return "", false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -83,7 +85,8 @@ func (p *BabblerPlugin) getBabbleWithBookends(start, end []string) (string, bool
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == NO_BABBLER {
|
if err == NO_BABBLER {
|
||||||
return fmt.Sprintf("%s babbler not found.", who), true
|
// return fmt.Sprintf("%s babbler not found.", who), true
|
||||||
|
return "", false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue