From 3cdb40ab5cf8ec1708233a7f6fdcbca3ae04128e Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 25 Mar 2016 12:42:21 -0400 Subject: [PATCH] Fix leftpad query --- plugins/leftpad/leftpad.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/leftpad/leftpad.go b/plugins/leftpad/leftpad.go index 533f6a8..0a5a190 100644 --- a/plugins/leftpad/leftpad.go +++ b/plugins/leftpad/leftpad.go @@ -5,10 +5,10 @@ package leftpad import ( "encoding/json" - "fmt" "io/ioutil" "log" "net/http" + "net/url" "strings" "github.com/velour/catbase/bot" @@ -39,14 +39,16 @@ func (p *LeftpadPlugin) Message(message bot.Message) bool { if len(parts) > 3 && parts[0] == "leftpad" { padchar := parts[1] length := parts[2] - text := parts[3:][0] - url := fmt.Sprintf("https://api.left-pad.io/?str=%s&len=%s&ch=%s", - text, - length, - padchar, - ) + text := strings.Join(parts[3:], " ") + url, _ := url.Parse("https://api.left-pad.io") + q := url.Query() + q.Set("str", text) + q.Set("len", length) + q.Set("ch", padchar) + url.RawQuery = q.Encode() + log.Printf("Requesting leftpad url: %s", url) - resp, err := http.Get(url) + resp, err := http.Get(url.String()) if err != nil { p.bot.SendMessage(message.Channel, err.Error()) return true