mirror of https://github.com/velour/catbase.git
Fix leftpad query
This commit is contained in:
parent
a14a2b2e61
commit
3cdb40ab5c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue