mirror of https://github.com/velour/catbase.git
Fixed babbler tests by not running go routines during testing. (go fmt on nerdepedia because of course this should all happen in one commit)
This commit is contained in:
parent
265fe441b4
commit
91a334b32b
|
@ -26,6 +26,7 @@ type BabblerPlugin struct {
|
||||||
Bot bot.Bot
|
Bot bot.Bot
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
config *config.Config
|
config *config.Config
|
||||||
|
WithGoRoutines bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Babbler struct {
|
type Babbler struct {
|
||||||
|
@ -93,6 +94,7 @@ func New(bot bot.Bot) *BabblerPlugin {
|
||||||
Bot: bot,
|
Bot: bot,
|
||||||
db: bot.DB(),
|
db: bot.DB(),
|
||||||
config: bot.Config(),
|
config: bot.Config(),
|
||||||
|
WithGoRoutines: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.createNewWord("")
|
plugin.createNewWord("")
|
||||||
|
|
|
@ -25,12 +25,18 @@ func makeMessage(payload string) msg.Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newBabblerPlugin(mb *bot.MockBot) *BabblerPlugin {
|
||||||
|
bp := New(mb)
|
||||||
|
bp.WithGoRoutines = false
|
||||||
|
return bp
|
||||||
|
}
|
||||||
|
|
||||||
func TestBabblerNoBabbler(t *testing.T) {
|
func TestBabblerNoBabbler(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
c.Message(makeMessage("!seabass2 says"))
|
bp.Message(makeMessage("!seabass2 says"))
|
||||||
res := assert.Len(t, mb.Messages, 0)
|
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")
|
||||||
|
@ -38,12 +44,12 @@ func TestBabblerNoBabbler(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerNothingSaid(t *testing.T) {
|
func TestBabblerNothingSaid(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
res := c.Message(makeMessage("initialize babbler for seabass"))
|
res := bp.Message(makeMessage("initialize babbler for seabass"))
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
res = c.Message(makeMessage("!seabass says"))
|
res = bp.Message(makeMessage("!seabass says"))
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Len(t, mb.Messages, 2)
|
assert.Len(t, mb.Messages, 2)
|
||||||
assert.Contains(t, mb.Messages[0], "okay.")
|
assert.Contains(t, mb.Messages[0], "okay.")
|
||||||
|
@ -52,17 +58,17 @@ func TestBabblerNothingSaid(t *testing.T) {
|
||||||
|
|
||||||
func TestBabbler(t *testing.T) {
|
func TestBabbler(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is a message")
|
seabass := makeMessage("This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
seabass.Body = "This is another message"
|
seabass.Body = "This is another message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says"))
|
res = bp.Message(makeMessage("!seabass says"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "this is")
|
assert.Contains(t, mb.Messages[0], "this is")
|
||||||
|
@ -71,17 +77,17 @@ func TestBabbler(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerSeed(t *testing.T) {
|
func TestBabblerSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is a message")
|
seabass := makeMessage("This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
seabass.Body = "This is another message"
|
seabass.Body = "This is another message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says long"))
|
res = bp.Message(makeMessage("!seabass says long"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "long message")
|
assert.Contains(t, mb.Messages[0], "long message")
|
||||||
|
@ -89,17 +95,17 @@ func TestBabblerSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerMultiSeed(t *testing.T) {
|
func TestBabblerMultiSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is a message")
|
seabass := makeMessage("This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
seabass.Body = "This is another message"
|
seabass.Body = "This is another message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says This is a long"))
|
res = bp.Message(makeMessage("!seabass says This is a long"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "this is a long message")
|
assert.Contains(t, mb.Messages[0], "this is a long message")
|
||||||
|
@ -107,17 +113,17 @@ func TestBabblerMultiSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerMultiSeed2(t *testing.T) {
|
func TestBabblerMultiSeed2(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is a message")
|
seabass := makeMessage("This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
seabass.Body = "This is another message"
|
seabass.Body = "This is another message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says is a long"))
|
res = bp.Message(makeMessage("!seabass says is a long"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "is a long message")
|
assert.Contains(t, mb.Messages[0], "is a long message")
|
||||||
|
@ -125,52 +131,52 @@ func TestBabblerMultiSeed2(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBadSeed(t *testing.T) {
|
func TestBabblerBadSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is a message")
|
seabass := makeMessage("This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
c.Message(seabass)
|
bp.Message(seabass)
|
||||||
seabass.Body = "This is another message"
|
seabass.Body = "This is another message"
|
||||||
c.Message(seabass)
|
bp.Message(seabass)
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
c.Message(seabass)
|
bp.Message(seabass)
|
||||||
c.Message(makeMessage("!seabass says noooo this is bad"))
|
bp.Message(makeMessage("!seabass says noooo this is bad"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'")
|
assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBabblerBadSeed2(t *testing.T) {
|
func TestBabblerBadSeed2(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is a message")
|
seabass := makeMessage("This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
c.Message(seabass)
|
bp.Message(seabass)
|
||||||
seabass.Body = "This is another message"
|
seabass.Body = "This is another message"
|
||||||
c.Message(seabass)
|
bp.Message(seabass)
|
||||||
seabass.Body = "This is a long message"
|
seabass.Body = "This is a long message"
|
||||||
c.Message(seabass)
|
bp.Message(seabass)
|
||||||
c.Message(makeMessage("!seabass says This is a really"))
|
bp.Message(makeMessage("!seabass says This is a really"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'")
|
assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBabblerSuffixSeed(t *testing.T) {
|
func TestBabblerSuffixSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is message one")
|
seabass := makeMessage("This is message one")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
seabass.Body = "It's easier to test with unique messages"
|
seabass.Body = "It's easier to test with unique messages"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
seabass.Body = "hi there"
|
seabass.Body = "hi there"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-tail message one"))
|
res = bp.Message(makeMessage("!seabass says-tail message one"))
|
||||||
res = c.Message(makeMessage("!seabass says-tail with unique"))
|
res = bp.Message(makeMessage("!seabass says-tail with unique"))
|
||||||
assert.Len(t, mb.Messages, 2)
|
assert.Len(t, mb.Messages, 2)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "this is message one")
|
assert.Contains(t, mb.Messages[0], "this is message one")
|
||||||
|
@ -179,17 +185,17 @@ func TestBabblerSuffixSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBadSuffixSeed(t *testing.T) {
|
func TestBabblerBadSuffixSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("This is message one")
|
seabass := makeMessage("This is message one")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
seabass.Body = "It's easier to test with unique messages"
|
seabass.Body = "It's easier to test with unique messages"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
seabass.Body = "hi there"
|
seabass.Body = "hi there"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-tail anything true"))
|
res = bp.Message(makeMessage("!seabass says-tail anything true"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'")
|
assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'")
|
||||||
|
@ -197,13 +203,13 @@ func TestBabblerBadSuffixSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBookendSeed(t *testing.T) {
|
func TestBabblerBookendSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("It's easier to test with unique messages")
|
seabass := makeMessage("It's easier to test with unique messages")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-bridge It's easier | unique messages"))
|
res = bp.Message(makeMessage("!seabass says-bridge It's easier | unique messages"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
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")
|
||||||
|
@ -211,13 +217,13 @@ func TestBabblerBookendSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBookendSeedShort(t *testing.T) {
|
func TestBabblerBookendSeedShort(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("It's easier to test with unique messages")
|
seabass := makeMessage("It's easier to test with unique messages")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages"))
|
res = bp.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
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")
|
||||||
|
@ -225,13 +231,13 @@ func TestBabblerBookendSeedShort(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBadBookendSeed(t *testing.T) {
|
func TestBabblerBadBookendSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("It's easier to test with unique messages")
|
seabass := makeMessage("It's easier to test with unique messages")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-bridge It's easier | not unique messages"))
|
res = bp.Message(makeMessage("!seabass says-bridge It's easier | not unique messages"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'")
|
assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'")
|
||||||
|
@ -239,13 +245,13 @@ func TestBabblerBadBookendSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerMiddleOutSeed(t *testing.T) {
|
func TestBabblerMiddleOutSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("It's easier to test with unique messages")
|
seabass := makeMessage("It's easier to test with unique messages")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-middle-out test with"))
|
res = bp.Message(makeMessage("!seabass says-middle-out test with"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
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")
|
||||||
|
@ -253,13 +259,13 @@ func TestBabblerMiddleOutSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBadMiddleOutSeed(t *testing.T) {
|
func TestBabblerBadMiddleOutSeed(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("It's easier to test with unique messages")
|
seabass := makeMessage("It's easier to test with unique messages")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
res = c.Message(makeMessage("!seabass says-middle-out anything true"))
|
res = bp.Message(makeMessage("!seabass says-middle-out anything true"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Equal(t, mb.Messages[0], "seabass never said 'anything true'")
|
assert.Equal(t, mb.Messages[0], "seabass never said 'anything true'")
|
||||||
|
@ -267,13 +273,13 @@ func TestBabblerBadMiddleOutSeed(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerBatch(t *testing.T) {
|
func TestBabblerBatch(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
seabass := makeMessage("batch learn for seabass This is a message! This is another message. This is not a long message? This is not a message! This is not another message. This is a long message?")
|
seabass := makeMessage("batch learn for seabass This is a message! This is another message. This is not a long message? This is not a message! This is not another message. This is a long message?")
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
res = c.Message(makeMessage("!seabass says"))
|
res = bp.Message(makeMessage("!seabass says"))
|
||||||
assert.Len(t, mb.Messages, 2)
|
assert.Len(t, mb.Messages, 2)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Contains(t, mb.Messages[1], "this is")
|
assert.Contains(t, mb.Messages[1], "this is")
|
||||||
|
@ -282,27 +288,27 @@ func TestBabblerBatch(t *testing.T) {
|
||||||
|
|
||||||
func TestBabblerMerge(t *testing.T) {
|
func TestBabblerMerge(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
c.config.Babbler.DefaultUsers = []string{"seabass"}
|
bp.config.Babbler.DefaultUsers = []string{"seabass"}
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
|
|
||||||
seabass := makeMessage("<seabass> This is a message")
|
seabass := makeMessage("<seabass> This is a message")
|
||||||
seabass.User = &user.User{Name: "seabass"}
|
seabass.User = &user.User{Name: "seabass"}
|
||||||
res := c.Message(seabass)
|
res := bp.Message(seabass)
|
||||||
assert.Len(t, mb.Messages, 0)
|
assert.Len(t, mb.Messages, 0)
|
||||||
|
|
||||||
seabass.Body = "<seabass> This is another message"
|
seabass.Body = "<seabass> This is another message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
|
|
||||||
seabass.Body = "<seabass> This is a long message"
|
seabass.Body = "<seabass> This is a long message"
|
||||||
res = c.Message(seabass)
|
res = bp.Message(seabass)
|
||||||
|
|
||||||
res = c.Message(makeMessage("!merge babbler seabass into seabass2"))
|
res = bp.Message(makeMessage("!merge babbler seabass into seabass2"))
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.Contains(t, mb.Messages[0], "mooooiggged")
|
assert.Contains(t, mb.Messages[0], "mooooiggged")
|
||||||
|
|
||||||
res = c.Message(makeMessage("!seabass2 says"))
|
res = bp.Message(makeMessage("!seabass2 says"))
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
assert.Len(t, mb.Messages, 2)
|
assert.Len(t, mb.Messages, 2)
|
||||||
|
|
||||||
|
@ -312,29 +318,29 @@ func TestBabblerMerge(t *testing.T) {
|
||||||
|
|
||||||
func TestHelp(t *testing.T) {
|
func TestHelp(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
c.Help("channel", []string{})
|
bp.Help("channel", []string{})
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBotMessage(t *testing.T) {
|
func TestBotMessage(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
assert.False(t, c.BotMessage(makeMessage("test")))
|
assert.False(t, bp.BotMessage(makeMessage("test")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvent(t *testing.T) {
|
func TestEvent(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
assert.False(t, c.Event("dummy", makeMessage("test")))
|
assert.False(t, bp.Event("dummy", makeMessage("test")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegisterWeb(t *testing.T) {
|
func TestRegisterWeb(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
bp := newBabblerPlugin(mb)
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, bp)
|
||||||
assert.Nil(t, c.RegisterWeb())
|
assert.Nil(t, bp.RegisterWeb())
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,11 @@ func (p *BabblerPlugin) initializeBabbler(tokens []string) (string, bool) {
|
||||||
func (p *BabblerPlugin) addToBabbler(babblerName, whatWasSaid string) (string, bool) {
|
func (p *BabblerPlugin) addToBabbler(babblerName, whatWasSaid string) (string, bool) {
|
||||||
babblerId, err := p.getOrCreateBabbler(babblerName)
|
babblerId, err := p.getOrCreateBabbler(babblerName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if p.WithGoRoutines {
|
||||||
go p.addToMarkovChain(babblerId, whatWasSaid)
|
go p.addToMarkovChain(babblerId, whatWasSaid)
|
||||||
|
} else {
|
||||||
|
p.addToMarkovChain(babblerId, whatWasSaid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
package nerdepedia
|
package nerdepedia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"html"
|
"html"
|
||||||
"net/http"
|
"net/http"
|
||||||
"bufio"
|
"strings"
|
||||||
|
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
"github.com/velour/catbase/bot/msg"
|
"github.com/velour/catbase/bot/msg"
|
||||||
|
|
Loading…
Reference in New Issue