quiet down the babbler

This commit is contained in:
skkiesel 2017-06-16 15:02:28 -04:00
parent 11c4f78bbd
commit 8735a2283b
3 changed files with 32 additions and 9 deletions

View File

@ -121,10 +121,15 @@ 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)
saidWhatEnd, saidSomethingEnd := p.getBabble(tokens) if !saidSomethingStart || saidWhatStart == strings.Join(tokens[2:], " ") {
saidSomething = saidSomethingStart && saidSomethingEnd saidSomething = saidSomethingStart
if saidSomething { saidWhat = saidWhatStart
saidWhat = saidWhatStart + " " + strings.Join(strings.Fields(saidWhatEnd)[len(tokens)-2:], " ") } else {
saidWhatEnd, saidSomethingEnd := p.getBabble(tokens)
saidSomething = saidSomethingStart && saidSomethingEnd
if saidSomething {
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)

View File

@ -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)

View File

@ -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 {