add middle out compression, I mean babbles

This commit is contained in:
skkiesel 2017-06-07 20:02:42 -04:00
parent 8edba10b5d
commit bd7cf6be7c
2 changed files with 23 additions and 1 deletions

View File

@ -119,7 +119,14 @@ func (p *BabblerPlugin) Message(message msg.Message) bool {
saidWhat, saidSomething = p.getBabble(tokens)
} else if numTokens > 2 && tokens[1] == "says-tail" {
saidWhat, saidSomething = p.getBabbleWithSuffix(tokens)
}else if len(tokens) == 4 && strings.Index(lowercase, "initialize babbler for ") == 0 {
} else if numTokens >= 2 && tokens[1] == "says-middle-out" {
saidWhatStart, saidSomethingStart := p.getBabbleWithSuffix(tokens)
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 {
saidWhat, saidSomething = p.initializeBabbler(tokens)
} else if strings.Index(lowercase, "batch learn for ") == 0 {
saidWhat, saidSomething = p.batchLearn(tokens)
@ -142,6 +149,7 @@ func (p *BabblerPlugin) Help(channel string, parts []string) {
"merge babbler drseabass into seabass",
"seabass says ...",
"seabass says-tail ...",
"seabass says-middle-out ...",
"seabass says-bridge ... | ...",
}
p.Bot.SendMessage(channel, strings.Join(commands, "\n\n"))

View File

@ -237,6 +237,20 @@ func TestBabblerBadBookendSeed(t *testing.T) {
assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'")
}
func TestBabblerMiddleOutSeed(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 test with"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
}
func TestBabblerBatch(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)