Fix leftpad query

This commit is contained in:
Chris Sexton 2016-03-25 12:42:21 -04:00
parent a14a2b2e61
commit 3cdb40ab5c
1 changed files with 10 additions and 8 deletions

View File

@ -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