From 5dd7df164e8ab391ead32ebe9686ccba9b04b576 Mon Sep 17 00:00:00 2001 From: skkiesel Date: Sat, 19 Jan 2019 08:38:19 -0500 Subject: [PATCH 1/8] This is my public shaming --- plugins/nerdepedia/nerdepedia.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/nerdepedia/nerdepedia.go b/plugins/nerdepedia/nerdepedia.go index cb7140e..ecf5bf9 100644 --- a/plugins/nerdepedia/nerdepedia.go +++ b/plugins/nerdepedia/nerdepedia.go @@ -59,15 +59,15 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool { for scanner.Scan() { line := scanner.Text() if description == "" { - index := strings.Index(line, linkPrefix) + index := strings.Index(line, descriptionPrefix) if index >= 0 { - description = html.UnescapeString(strings.TrimSuffix(strings.TrimPrefix(line, linkPrefix), closingTagSuffix)) + description = html.UnescapeString(strings.TrimSuffix(strings.TrimPrefix(line, descriptionPrefix), closingTagSuffix)) } } if link == "" { - index := strings.Index(line, descriptionPrefix) + index := strings.Index(line, linkPrefix) if index >= 0 { - link = strings.TrimSuffix(strings.TrimPrefix(line, descriptionPrefix), closingTagSuffix) + link = strings.TrimSuffix(strings.TrimPrefix(line, linkPrefix), closingTagSuffix) } } From 75dcb47d112294c69977692f615854f3410b5a83 Mon Sep 17 00:00:00 2001 From: skkiesel Date: Sat, 19 Jan 2019 08:45:14 -0500 Subject: [PATCH 2/8] Kids gonna like dune --- plugins/nerdepedia/nerdepedia.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/nerdepedia/nerdepedia.go b/plugins/nerdepedia/nerdepedia.go index ecf5bf9..229569a 100644 --- a/plugins/nerdepedia/nerdepedia.go +++ b/plugins/nerdepedia/nerdepedia.go @@ -44,6 +44,8 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool { query = "http://starwars.wikia.com/wiki/Special:Random" } else if lowerCase == "beam me up scotty" || lowerCase == "live long and prosper" { query = "http://memory-alpha.wikia.com/wiki/Special:Random" + } else if lowerCase == "bless the maker" || lowerCase == "i must not fear" { + query = "http://dune.wikia.com/wiki/Special:Random" } if query != "" { @@ -82,7 +84,7 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool { // Help responds to help requests. Every plugin must implement a help function. func (p *NerdepediaPlugin) Help(channel string, parts []string) { - p.bot.SendMessage(channel, "star wars/trek stuff") + p.bot.SendMessage(channel, "nerd stuff") } // Empty event handler because this plugin does not do anything on event recv From 3aaed538dda94a86a2d75446db8133abd829cb35 Mon Sep 17 00:00:00 2001 From: skkiesel Date: Sat, 19 Jan 2019 08:55:47 -0500 Subject: [PATCH 3/8] LOTR --- plugins/nerdepedia/nerdepedia.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/nerdepedia/nerdepedia.go b/plugins/nerdepedia/nerdepedia.go index 229569a..473c56e 100644 --- a/plugins/nerdepedia/nerdepedia.go +++ b/plugins/nerdepedia/nerdepedia.go @@ -46,6 +46,8 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool { query = "http://memory-alpha.wikia.com/wiki/Special:Random" } else if lowerCase == "bless the maker" || lowerCase == "i must not fear" { query = "http://dune.wikia.com/wiki/Special:Random" + } else if lowerCase == "my precious" || lowerCase == "one ring to rule them all" || lowerCase == "one does not simply walk into mordor" { + query = "http://lotr.wikia.com/wiki/Special:Random" } if query != "" { From 265fe441b42b959ff9734773b6ec01a195fb1e3e Mon Sep 17 00:00:00 2001 From: skkiesel Date: Sat, 19 Jan 2019 09:02:50 -0500 Subject: [PATCH 4/8] I'll see your double escaping, and raise you triple unescaping. But seriously, double unescaping. --- plugins/nerdepedia/nerdepedia.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/nerdepedia/nerdepedia.go b/plugins/nerdepedia/nerdepedia.go index 473c56e..5c2373f 100644 --- a/plugins/nerdepedia/nerdepedia.go +++ b/plugins/nerdepedia/nerdepedia.go @@ -65,7 +65,7 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool { if description == "" { index := strings.Index(line, descriptionPrefix) if index >= 0 { - description = html.UnescapeString(strings.TrimSuffix(strings.TrimPrefix(line, descriptionPrefix), closingTagSuffix)) + description = html.UnescapeString(html.UnescapeString(strings.TrimSuffix(strings.TrimPrefix(line, descriptionPrefix), closingTagSuffix))) } } if link == "" { From 91a334b32bd656afd5dee0e14119beca86ac677e Mon Sep 17 00:00:00 2001 From: skkiesel Date: Sat, 19 Jan 2019 09:43:33 -0500 Subject: [PATCH 5/8] Fixed babbler tests by not running go routines during testing. (go fmt on nerdepedia because of course this should all happen in one commit) --- plugins/babbler/babbler.go | 14 +- plugins/babbler/babbler_test.go | 238 ++++++++++++++++--------------- plugins/babbler/commands.go | 6 +- plugins/nerdepedia/nerdepedia.go | 6 +- 4 files changed, 138 insertions(+), 126 deletions(-) diff --git a/plugins/babbler/babbler.go b/plugins/babbler/babbler.go index 0ae0b58..36f1521 100644 --- a/plugins/babbler/babbler.go +++ b/plugins/babbler/babbler.go @@ -23,9 +23,10 @@ var ( ) type BabblerPlugin struct { - Bot bot.Bot - db *sqlx.DB - config *config.Config + Bot bot.Bot + db *sqlx.DB + config *config.Config + WithGoRoutines bool } type Babbler struct { @@ -90,9 +91,10 @@ func New(bot bot.Bot) *BabblerPlugin { } plugin := &BabblerPlugin{ - Bot: bot, - db: bot.DB(), - config: bot.Config(), + Bot: bot, + db: bot.DB(), + config: bot.Config(), + WithGoRoutines: true, } plugin.createNewWord("") diff --git a/plugins/babbler/babbler_test.go b/plugins/babbler/babbler_test.go index 5031a19..d598359 100644 --- a/plugins/babbler/babbler_test.go +++ b/plugins/babbler/babbler_test.go @@ -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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) - c.Message(makeMessage("!seabass2 says")) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) + bp.Message(makeMessage("!seabass2 says")) res := assert.Len(t, mb.Messages, 0) assert.True(t, res) // assert.Contains(t, mb.Messages[0], "seabass2 babbler not found") @@ -38,12 +44,12 @@ func TestBabblerNoBabbler(t *testing.T) { func TestBabblerNothingSaid(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) - res := c.Message(makeMessage("initialize babbler for seabass")) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) + res := bp.Message(makeMessage("initialize babbler for seabass")) assert.True(t, res) - res = c.Message(makeMessage("!seabass says")) + res = bp.Message(makeMessage("!seabass says")) assert.True(t, res) assert.Len(t, mb.Messages, 2) assert.Contains(t, mb.Messages[0], "okay.") @@ -52,17 +58,17 @@ func TestBabblerNothingSaid(t *testing.T) { func TestBabbler(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) seabass.Body = "This is another message" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = "This is a long message" - res = c.Message(seabass) - res = c.Message(makeMessage("!seabass says")) + res = bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "this is") @@ -71,17 +77,17 @@ func TestBabbler(t *testing.T) { func TestBabblerSeed(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) seabass.Body = "This is another message" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = "This is a long message" - res = c.Message(seabass) - res = c.Message(makeMessage("!seabass says long")) + res = bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says long")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "long message") @@ -89,17 +95,17 @@ func TestBabblerSeed(t *testing.T) { func TestBabblerMultiSeed(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) seabass.Body = "This is another message" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = "This is a long message" - res = c.Message(seabass) - res = c.Message(makeMessage("!seabass says This is a long")) + res = bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says This is a long")) assert.Len(t, mb.Messages, 1) assert.True(t, res) 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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) seabass.Body = "This is another message" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = "This is a long message" - res = c.Message(seabass) - res = c.Message(makeMessage("!seabass says is a long")) + res = bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says is a long")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "is a long message") @@ -125,52 +131,52 @@ func TestBabblerMultiSeed2(t *testing.T) { func TestBabblerBadSeed(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - c.Message(seabass) + bp.Message(seabass) seabass.Body = "This is another message" - c.Message(seabass) + bp.Message(seabass) seabass.Body = "This is a long message" - c.Message(seabass) - c.Message(makeMessage("!seabass says noooo this is bad")) + bp.Message(seabass) + bp.Message(makeMessage("!seabass says noooo this is bad")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'") } func TestBabblerBadSeed2(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - c.Message(seabass) + bp.Message(seabass) seabass.Body = "This is another message" - c.Message(seabass) + bp.Message(seabass) seabass.Body = "This is a long message" - c.Message(seabass) - c.Message(makeMessage("!seabass says This is a really")) + bp.Message(seabass) + bp.Message(makeMessage("!seabass says This is a really")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'") } func TestBabblerSuffixSeed(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is message one") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) seabass.Body = "It's easier to test with unique messages" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = "hi there" - res = c.Message(seabass) - res = c.Message(makeMessage("!seabass says-tail message one")) - res = c.Message(makeMessage("!seabass says-tail with unique")) + res = bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says-tail message one")) + res = bp.Message(makeMessage("!seabass says-tail with unique")) assert.Len(t, mb.Messages, 2) assert.True(t, res) assert.Contains(t, mb.Messages[0], "this is message one") @@ -179,17 +185,17 @@ func TestBabblerSuffixSeed(t *testing.T) { func TestBabblerBadSuffixSeed(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage("This is message one") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) seabass.Body = "It's easier to test with unique messages" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = "hi there" - res = c.Message(seabass) - res = c.Message(makeMessage("!seabass says-tail anything true")) + res = bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says-tail anything true")) assert.Len(t, mb.Messages, 1) assert.True(t, res) 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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) 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-bridge It's easier | unique messages")) + res := bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says-bridge It's easier | unique messages")) assert.Len(t, mb.Messages, 1) assert.True(t, res) 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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) 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-bridge It's easier to test with | unique messages")) + res := bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages")) assert.Len(t, mb.Messages, 1) assert.True(t, res) 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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) 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-bridge It's easier | not unique messages")) + res := bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says-bridge It's easier | not unique messages")) assert.Len(t, mb.Messages, 1) assert.True(t, res) 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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) 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")) + res := bp.Message(seabass) + res = bp.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") @@ -253,13 +259,13 @@ func TestBabblerMiddleOutSeed(t *testing.T) { func TestBabblerBadMiddleOutSeed(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) 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")) + res := bp.Message(seabass) + res = bp.Message(makeMessage("!seabass says-middle-out anything true")) assert.Len(t, mb.Messages, 1) assert.True(t, res) 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) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + 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?") - res := c.Message(seabass) + res := bp.Message(seabass) 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.True(t, res) assert.Contains(t, mb.Messages[1], "this is") @@ -282,27 +288,27 @@ func TestBabblerBatch(t *testing.T) { func TestBabblerMerge(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - c.config.Babbler.DefaultUsers = []string{"seabass"} - assert.NotNil(t, c) + bp := newBabblerPlugin(mb) + bp.config.Babbler.DefaultUsers = []string{"seabass"} + assert.NotNil(t, bp) seabass := makeMessage(" This is a message") seabass.User = &user.User{Name: "seabass"} - res := c.Message(seabass) + res := bp.Message(seabass) assert.Len(t, mb.Messages, 0) seabass.Body = " This is another message" - res = c.Message(seabass) + res = bp.Message(seabass) seabass.Body = " 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.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "mooooiggged") - res = c.Message(makeMessage("!seabass2 says")) + res = bp.Message(makeMessage("!seabass2 says")) assert.True(t, res) assert.Len(t, mb.Messages, 2) @@ -312,29 +318,29 @@ func TestBabblerMerge(t *testing.T) { func TestHelp(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - c.Help("channel", []string{}) + bp := newBabblerPlugin(mb) + assert.NotNil(t, bp) + bp.Help("channel", []string{}) assert.Len(t, mb.Messages, 1) } func TestBotMessage(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.False(t, c.BotMessage(makeMessage("test"))) + bp := newBabblerPlugin(mb) + assert.NotNil(t, bp) + assert.False(t, bp.BotMessage(makeMessage("test"))) } func TestEvent(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.False(t, c.Event("dummy", makeMessage("test"))) + bp := newBabblerPlugin(mb) + assert.NotNil(t, bp) + assert.False(t, bp.Event("dummy", makeMessage("test"))) } func TestRegisterWeb(t *testing.T) { mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.Nil(t, c.RegisterWeb()) + bp := newBabblerPlugin(mb) + assert.NotNil(t, bp) + assert.Nil(t, bp.RegisterWeb()) } diff --git a/plugins/babbler/commands.go b/plugins/babbler/commands.go index 38e50d9..52291bf 100644 --- a/plugins/babbler/commands.go +++ b/plugins/babbler/commands.go @@ -17,7 +17,11 @@ func (p *BabblerPlugin) initializeBabbler(tokens []string) (string, bool) { func (p *BabblerPlugin) addToBabbler(babblerName, whatWasSaid string) (string, bool) { babblerId, err := p.getOrCreateBabbler(babblerName) if err == nil { - go p.addToMarkovChain(babblerId, whatWasSaid) + if p.WithGoRoutines { + go p.addToMarkovChain(babblerId, whatWasSaid) + } else { + p.addToMarkovChain(babblerId, whatWasSaid) + } } return "", false } diff --git a/plugins/nerdepedia/nerdepedia.go b/plugins/nerdepedia/nerdepedia.go index 5c2373f..aa2665a 100644 --- a/plugins/nerdepedia/nerdepedia.go +++ b/plugins/nerdepedia/nerdepedia.go @@ -3,11 +3,11 @@ package nerdepedia import ( + "bufio" "fmt" - "strings" "html" "net/http" - "bufio" + "strings" "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" @@ -16,7 +16,7 @@ import ( const ( descriptionPrefix = "" ) From bfe910f4db762ea308aef8180083169041523813 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 19 Jan 2019 09:59:53 -0500 Subject: [PATCH 6/8] tests: rm some beers tests, add gok and fix errs --- gok.sh | 23 +++++++++++++++ plugins/beers/beers_test.go | 49 ++++++------------------------- plugins/emojifyme/emojifyme.go | 2 +- plugins/reminder/reminder_test.go | 4 +-- plugins/zork/zork.go | 2 +- 5 files changed, 36 insertions(+), 44 deletions(-) create mode 100755 gok.sh diff --git a/gok.sh b/gok.sh new file mode 100755 index 0000000..50b19d6 --- /dev/null +++ b/gok.sh @@ -0,0 +1,23 @@ +#!/bin/sh +o=$(mktemp tmp.XXXXXXXXXX) + +fail() { + echo Failed + cat $o | grep -v deprecated + rm $o + exit 1 +} + +trap fail INT TERM + +echo gofmt +gofmt -l $(find . -name '*.go') > $o 2>&1 +test $(wc -l $o | awk '{ print $1 }') = "0" || fail + +echo govet +go vet ./... > $o 2>&1 || fail + +echo go test +go test -test.timeout=60s ./... > $o 2>&1 || fail + +rm $o diff --git a/plugins/beers/beers_test.go b/plugins/beers/beers_test.go index 46840fc..8d14d86 100644 --- a/plugins/beers/beers_test.go +++ b/plugins/beers/beers_test.go @@ -32,56 +32,25 @@ func makeBeersPlugin(t *testing.T) (*BeersPlugin, *bot.MockBot) { b := New(mb) assert.NotNil(t, b) b.Message(makeMessage("!mkalias beer :beer:")) + b.Message(makeMessage("!mkalias beers :beer:")) return b, mb } -func TestBeersPlusPlus(t *testing.T) { - b, mb := makeBeersPlugin(t) - b.Message(makeMessage("beers++")) - assert.Len(t, mb.Messages, 1) - b.Message(makeMessage("beers++")) - assert.Len(t, mb.Messages, 2) - it, err := counter.GetItem(mb.DB(), "tester", "booze") - assert.Nil(t, err) - assert.Equal(t, 2, it.Count) -} - -func TestBeersMinusMinus(t *testing.T) { - b, mb := makeBeersPlugin(t) - b.Message(makeMessage("beers = 5")) - assert.Len(t, mb.Messages, 1) - b.Message(makeMessage("beers--")) - assert.Len(t, mb.Actions, 1) - it, err := counter.GetItem(mb.DB(), "tester", "booze") - assert.Nil(t, err) - assert.Equal(t, 4, it.Count) -} - func TestImbibe(t *testing.T) { b, mb := makeBeersPlugin(t) b.Message(makeMessage("!imbibe")) assert.Len(t, mb.Messages, 1) b.Message(makeMessage("!imbibe")) assert.Len(t, mb.Messages, 2) - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 2, it.Count) } - -func TestBourbon(t *testing.T) { - b, mb := makeBeersPlugin(t) - b.Message(makeMessage("bourbon++")) - assert.Len(t, mb.Messages, 1) - it, err := counter.GetItem(mb.DB(), "tester", "booze") - assert.Nil(t, err) - assert.Equal(t, 2, it.Count) -} - func TestEq(t *testing.T) { b, mb := makeBeersPlugin(t) b.Message(makeMessage("!beers = 3")) assert.Len(t, mb.Messages, 1) - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 3, it.Count) } @@ -90,7 +59,7 @@ func TestEqNeg(t *testing.T) { b, mb := makeBeersPlugin(t) b.Message(makeMessage("!beers = -3")) assert.Len(t, mb.Messages, 1) - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 0, it.Count) } @@ -101,7 +70,7 @@ func TestEqZero(t *testing.T) { b.Message(makeMessage("!beers = 0")) assert.Len(t, mb.Messages, 2) assert.Contains(t, mb.Messages[1], "reversal of fortune") - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 0, it.Count) } @@ -112,7 +81,7 @@ func TestBeersPlusEq(t *testing.T) { assert.Len(t, mb.Messages, 1) b.Message(makeMessage("beers += 5")) assert.Len(t, mb.Messages, 2) - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 10, it.Count) } @@ -120,11 +89,11 @@ func TestBeersPlusEq(t *testing.T) { func TestPuke(t *testing.T) { b, mb := makeBeersPlugin(t) b.Message(makeMessage("beers += 5")) - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 5, it.Count) b.Message(makeMessage("puke")) - it, err = counter.GetItem(mb.DB(), "tester", "booze") + it, err = counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 0, it.Count) } @@ -132,7 +101,7 @@ func TestPuke(t *testing.T) { func TestBeersReport(t *testing.T) { b, mb := makeBeersPlugin(t) b.Message(makeMessage("beers += 5")) - it, err := counter.GetItem(mb.DB(), "tester", "booze") + it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 5, it.Count) b.Message(makeMessage("beers")) diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index e6e3e11..424a88b 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -32,7 +32,7 @@ func New(bot bot.Bot) *EmojifyMePlugin { } type Emoji struct { - Aliases []string `json:aliases` + Aliases []string `json:"aliases"` } var emoji []Emoji diff --git a/plugins/reminder/reminder_test.go b/plugins/reminder/reminder_test.go index dc9f38b..afafd5d 100644 --- a/plugins/reminder/reminder_test.go +++ b/plugins/reminder/reminder_test.go @@ -178,9 +178,9 @@ func TestBatch(t *testing.T) { c := New(mb) c.config.Reminder.MaxBatchAdd = 50 assert.NotNil(t, c) - res := c.Message(makeMessage("!remind testuser every 1s for 5s yikes")) + res := c.Message(makeMessage("!remind testuser every 1ms for 5ms yikes")) assert.True(t, res) - time.Sleep(6 * time.Second) + time.Sleep(2 * time.Second) assert.Len(t, mb.Messages, 6) for i := 0; i < 5; i++ { assert.Contains(t, mb.Messages[i+1], "Hey testuser, tester wanted you to be reminded: yikes") diff --git a/plugins/zork/zork.go b/plugins/zork/zork.go index cabc6d2..7e5d0af 100644 --- a/plugins/zork/zork.go +++ b/plugins/zork/zork.go @@ -49,7 +49,7 @@ func (p *ZorkPlugin) runZork(ch string) error { var w io.WriteCloser cmd.Stdin, w = io.Pipe() - log.Printf("zork running %s\n", cmd) + log.Printf("zork running %v\n", cmd) if err := cmd.Start(); err != nil { w.Close() return err From 7a5cfcbe44025218143c10264ae7a6fa4b479482 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 19 Jan 2019 10:01:51 -0500 Subject: [PATCH 7/8] travis: check some new settings out --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 15abc0f..23b41e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: go go: 1.x -script: go build +install: go get -t -v ./... && go build -v ./... +script: ./gok.sh From 69f02ed0773c01b7aefd15ffec46d1f4892bdcc5 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 19 Jan 2019 10:08:26 -0500 Subject: [PATCH 8/8] travis: turn modules on --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 23b41e7..0ad5529 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: go go: 1.x +env: + - GO111MODULE=on install: go get -t -v ./... && go build -v ./... script: ./gok.sh