update
This commit is contained in:
+26
-6
@@ -59,6 +59,7 @@ func InitReplies() {
|
|||||||
Url = strings.Replace(Url, fmt.Sprintf(`{{encode(%d)}}`, k+1), url.QueryEscape(v), -1)
|
Url = strings.Replace(Url, fmt.Sprintf(`{{encode(%d)}}`, k+1), url.QueryEscape(v), -1)
|
||||||
body = strings.Replace(body, fmt.Sprintf(`{{encode(%d)}}`, k+1), url.QueryEscape(v), -1)
|
body = strings.Replace(body, fmt.Sprintf(`{{encode(%d)}}`, k+1), url.QueryEscape(v), -1)
|
||||||
}
|
}
|
||||||
|
data := func() []byte {
|
||||||
var req httplib.BeegoHTTPRequest
|
var req httplib.BeegoHTTPRequest
|
||||||
if strings.ToLower(reply.Request.Method) == "post" {
|
if strings.ToLower(reply.Request.Method) == "post" {
|
||||||
req = *httplib.Post(Url)
|
req = *httplib.Post(Url)
|
||||||
@@ -83,10 +84,17 @@ func InitReplies() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
d, _ := ioutil.ReadAll(rsp.Body)
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
switch reply.Request.ResponseType {
|
switch reply.Request.ResponseType {
|
||||||
case "image":
|
case "image":
|
||||||
if reply.Request.Get != "" {
|
if reply.Request.Get != "" {
|
||||||
d, _ := ioutil.ReadAll(rsp.Body)
|
d := data()
|
||||||
|
if d == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Reply(err)
|
s.Reply(err)
|
||||||
@@ -96,16 +104,22 @@ func InitReplies() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if reply.Request.Regex != "" {
|
if reply.Request.Regex != "" {
|
||||||
d, _ := ioutil.ReadAll(rsp.Body)
|
d := data()
|
||||||
|
if d == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
res := regexp.MustCompile(reply.Request.Regex).FindStringSubmatch(string(d))
|
res := regexp.MustCompile(reply.Request.Regex).FindStringSubmatch(string(d))
|
||||||
if len(res) != 0 {
|
if len(res) != 0 {
|
||||||
s.Reply(ImageUrl(res[1]))
|
s.Reply(ImageUrl(res[1]))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.Reply(rsp)
|
s.Reply(ImageUrl(Url))
|
||||||
case "json":
|
case "json":
|
||||||
d, _ := ioutil.ReadAll(rsp.Body)
|
d := data()
|
||||||
|
if d == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Reply(err)
|
s.Reply(err)
|
||||||
@@ -113,7 +127,10 @@ func InitReplies() {
|
|||||||
}
|
}
|
||||||
s.Reply(f)
|
s.Reply(f)
|
||||||
case "template":
|
case "template":
|
||||||
data, _ := ioutil.ReadAll(rsp.Body)
|
data := data()
|
||||||
|
if data == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
content := reply.Request.Template
|
content := reply.Request.Template
|
||||||
for _, re := range regexp.MustCompile(`tfmt[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
for _, re := range regexp.MustCompile(`tfmt[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
||||||
v := re[0]
|
v := re[0]
|
||||||
@@ -182,7 +199,10 @@ func InitReplies() {
|
|||||||
content = strings.Replace(content, `[d]`, ",", -1)
|
content = strings.Replace(content, `[d]`, ",", -1)
|
||||||
s.Reply(content)
|
s.Reply(content)
|
||||||
default:
|
default:
|
||||||
d, _ := ioutil.ReadAll(rsp.Body)
|
d := data()
|
||||||
|
if d == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
s.Reply(d)
|
s.Reply(d)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user