From 6c27e0cafd61a9bc7ccbb9fa8bb7a21511251f5f Mon Sep 17 00:00:00 2001 From: Scott Kiesel Date: Fri, 13 Mar 2020 10:23:00 -0400 Subject: [PATCH] go fmt because apparently we're all too amazing to handle ill-formatted code, wimps --- plugins/impossible/impossible.go | 34 ++++++++++++++------------- plugins/impossible/impossible_test.go | 10 ++++---- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/plugins/impossible/impossible.go b/plugins/impossible/impossible.go index 00d912b..a508b97 100644 --- a/plugins/impossible/impossible.go +++ b/plugins/impossible/impossible.go @@ -4,12 +4,12 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math/rand" "net/http" "net/url" - "math/rand" "regexp" "strings" - "time" + "time" "github.com/rs/zerolog/log" @@ -25,7 +25,7 @@ type Impossible struct { title string content []string updated time.Time - testing bool + testing bool } func New(b bot.Bot) *Impossible { @@ -35,7 +35,7 @@ func New(b bot.Bot) *Impossible { title: "", content: []string{}, updated: getTodaysMidnight().Add(time.Hour * -24), - testing: false, + testing: false, } b.Register(i, bot.Help, i.help) @@ -51,7 +51,7 @@ func newTesting(b bot.Bot) *Impossible { title: "", content: []string{}, updated: getTodaysMidnight().Add(time.Hour * -24), - testing: true, + testing: true, } b.Register(i, bot.Help, i.help) @@ -72,12 +72,13 @@ func (p *Impossible) message(c bot.Connector, kind bot.Kind, message msg.Message p.b.Send(c, bot.Message, message.Channel, fmt.Sprintf("The last impossible wikipedia article was: \"%s\"", p.title)) messaged = true } - for !p.refreshImpossible() {} + for !p.refreshImpossible() { + } - if p.testing { - p.b.Send(c, bot.Message, message.Channel, p.title) + if p.testing { + p.b.Send(c, bot.Message, message.Channel, p.title) messaged = true - } + } } lowercase := strings.ToLower(message.Body) @@ -87,7 +88,8 @@ func (p *Impossible) message(c bot.Connector, kind bot.Kind, message msg.Message } else if strings.Contains(lowercase, strings.ToLower(p.title)) { messaged = true p.b.Send(c, bot.Message, message.Channel, fmt.Sprintf("You guessed the last impossible wikipedia article: \"%s\"", p.title)) - for !p.refreshImpossible() {} + for !p.refreshImpossible() { + } } return messaged @@ -103,12 +105,12 @@ func (p *Impossible) refreshImpossible() bool { body, err := ioutil.ReadAll(resp.Body) titleRegex := regexp.MustCompile(`id="firstHeading"[^>]*(?P[^<]*)`) - results := titleRegex.FindStringSubmatch(string(body)) - title := results[1][1:] //remove the leading < + results := titleRegex.FindStringSubmatch(string(body)) + title := results[1][1:] //remove the leading < - if title == "" { - return false - } + if title == "" { + return false + } p.title = title p.content = []string{} @@ -138,7 +140,7 @@ func (p *Impossible) refreshImpossible() bool { p.content = append(p.content, censored) } } - return true + return true } func getTodaysMidnight() time.Time { diff --git a/plugins/impossible/impossible_test.go b/plugins/impossible/impossible_test.go index c67fd90..284a87c 100644 --- a/plugins/impossible/impossible_test.go +++ b/plugins/impossible/impossible_test.go @@ -1,7 +1,7 @@ package impossible import ( - "fmt" + "fmt" "github.com/velour/catbase/plugins/cli" "strings" "testing" @@ -37,23 +37,23 @@ func makePlugin(t *testing.T) (*Impossible, *bot.MockBot) { func TestNothing(t *testing.T) { p, mb := makePlugin(t) p.message(makeMessage("hi")) - p.message(makeMessage("nothing")) + p.message(makeMessage("nothing")) assert.Len(t, mb.Messages, 1) } func TestHint(t *testing.T) { p, mb := makePlugin(t) p.message(makeMessage("hi")) - p.message(makeMessage("!hint")) + p.message(makeMessage("!hint")) assert.Len(t, mb.Messages, 2) } func TestCorrect(t *testing.T) { p, mb := makePlugin(t) p.message(makeMessage("hi")) - p.message(makeMessage(mb.Messages[0])) + p.message(makeMessage(mb.Messages[0])) - congrats := fmt.Sprintf("You guessed the last impossible wikipedia article: \"%s\"", mb.Messages[0]) + congrats := fmt.Sprintf("You guessed the last impossible wikipedia article: \"%s\"", mb.Messages[0]) assert.Contains(t, mb.Messages[1], congrats) }