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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
|
@ -39,14 +39,16 @@ func (p *LeftpadPlugin) Message(message bot.Message) bool {
|
||||||
if len(parts) > 3 && parts[0] == "leftpad" {
|
if len(parts) > 3 && parts[0] == "leftpad" {
|
||||||
padchar := parts[1]
|
padchar := parts[1]
|
||||||
length := parts[2]
|
length := parts[2]
|
||||||
text := parts[3:][0]
|
text := strings.Join(parts[3:], " ")
|
||||||
url := fmt.Sprintf("https://api.left-pad.io/?str=%s&len=%s&ch=%s",
|
url, _ := url.Parse("https://api.left-pad.io")
|
||||||
text,
|
q := url.Query()
|
||||||
length,
|
q.Set("str", text)
|
||||||
padchar,
|
q.Set("len", length)
|
||||||
)
|
q.Set("ch", padchar)
|
||||||
|
url.RawQuery = q.Encode()
|
||||||
|
|
||||||
log.Printf("Requesting leftpad url: %s", url)
|
log.Printf("Requesting leftpad url: %s", url)
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.bot.SendMessage(message.Channel, err.Error())
|
p.bot.SendMessage(message.Channel, err.Error())
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue