Merge pull request #164 from velour/TLDR

TL;DR Latent Dirichlet Allocation summarizer
This commit is contained in:
Scott Kiesel 2019-03-21 20:19:12 -04:00 committed by GitHub
commit 92bfc6f236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 175 additions and 0 deletions

View File

@ -38,6 +38,7 @@ import (
"github.com/velour/catbase/plugins/sisyphus" "github.com/velour/catbase/plugins/sisyphus"
"github.com/velour/catbase/plugins/talker" "github.com/velour/catbase/plugins/talker"
"github.com/velour/catbase/plugins/tell" "github.com/velour/catbase/plugins/tell"
"github.com/velour/catbase/plugins/tldr"
"github.com/velour/catbase/plugins/twitch" "github.com/velour/catbase/plugins/twitch"
"github.com/velour/catbase/plugins/your" "github.com/velour/catbase/plugins/your"
"github.com/velour/catbase/plugins/zork" "github.com/velour/catbase/plugins/zork"
@ -119,6 +120,7 @@ func main() {
b.AddPlugin(tell.New(b)) b.AddPlugin(tell.New(b))
b.AddPlugin(couldashouldawoulda.New(b)) b.AddPlugin(couldashouldawoulda.New(b))
b.AddPlugin(nerdepedia.New(b)) b.AddPlugin(nerdepedia.New(b))
b.AddPlugin(tldr.New(b))
// catches anything left, will always return true // catches anything left, will always return true
b.AddPlugin(fact.New(b)) b.AddPlugin(fact.New(b))

129
plugins/tldr/tldr.go Normal file

File diff suppressed because one or more lines are too long

44
plugins/tldr/tldr_test.go Normal file
View File

@ -0,0 +1,44 @@
package tldr
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/bot/user"
)
func makeMessageBy(payload, by string) (bot.Kind, msg.Message) {
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
return bot.Message, msg.Message{
User: &user.User{Name: by},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func makeMessage(payload string) (bot.Kind, msg.Message) {
return makeMessageBy(payload, "tester")
}
func setup(t *testing.T) (*TLDRPlugin, *bot.MockBot) {
mb := bot.NewMockBot()
r := New(mb)
return r, mb
}
func Test(t *testing.T) {
c, mb := setup(t)
res := c.message(makeMessage("The quick brown fox jumped over the lazy dog"))
res = c.message(makeMessage("The cow jumped over the moon"))
res = c.message(makeMessage("The little dog laughed to see such fun"))
res = c.message(makeMessage("tl;dr"))
assert.True(t, res)
assert.Len(t, mb.Messages, 1)
}