From bd7cf6be7c4cb3e17be7e4d42ac910425fece531 Mon Sep 17 00:00:00 2001 From: skkiesel Date: Wed, 7 Jun 2017 20:02:42 -0400 Subject: [PATCH] add middle out compression, I mean babbles --- plugins/babbler/babbler.go | 10 +++++++++- plugins/babbler/babbler_test.go | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/babbler/babbler.go b/plugins/babbler/babbler.go index a146f1c..cc6e408 100644 --- a/plugins/babbler/babbler.go +++ b/plugins/babbler/babbler.go @@ -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")) diff --git a/plugins/babbler/babbler_test.go b/plugins/babbler/babbler_test.go index a530602..380c8d8 100644 --- a/plugins/babbler/babbler_test.go +++ b/plugins/babbler/babbler_test.go @@ -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)