update
This commit is contained in:
+10
-6
@@ -24,6 +24,7 @@ type Reply struct {
|
|||||||
Regex string
|
Regex string
|
||||||
Template string
|
Template string
|
||||||
}
|
}
|
||||||
|
Replace [][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitReplies() {
|
func InitReplies() {
|
||||||
@@ -97,16 +98,19 @@ func InitReplies() {
|
|||||||
s.Reply(f)
|
s.Reply(f)
|
||||||
case "template":
|
case "template":
|
||||||
data, _ := ioutil.ReadAll(rsp.Body)
|
data, _ := ioutil.ReadAll(rsp.Body)
|
||||||
for _, re := range regexp.MustCompile(`gjson[(][^()]+[)]`).FindAllStringSubmatch(reply.Request.Template, -1) {
|
content := reply.Request.Template
|
||||||
|
for _, re := range regexp.MustCompile(`gjson[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
||||||
v := re[0]
|
v := re[0]
|
||||||
fmt.Println(v)
|
|
||||||
get := strings.Replace(strings.TrimRight(v, ")"), "gjson(", "", -1)
|
get := strings.Replace(strings.TrimRight(v, ")"), "gjson(", "", -1)
|
||||||
fmt.Println(get)
|
|
||||||
f, _ := jsonparser.GetString(data, strings.Split(get, ".")...)
|
f, _ := jsonparser.GetString(data, strings.Split(get, ".")...)
|
||||||
fmt.Println(f)
|
content = strings.Replace(content, v, f, -1)
|
||||||
reply.Request.Template = strings.Replace(reply.Request.Template, v, f, -1)
|
|
||||||
}
|
}
|
||||||
s.Reply(reply.Request.Template)
|
for i := range reply.Replace {
|
||||||
|
if len(reply.Replace[i]) >= 2 {
|
||||||
|
strings.Replace(content, reply.Replace[i][0], reply.Replace[i][1], -1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Reply(content)
|
||||||
default:
|
default:
|
||||||
d, _ := ioutil.ReadAll(rsp.Body)
|
d, _ := ioutil.ReadAll(rsp.Body)
|
||||||
s.Reply(d)
|
s.Reply(d)
|
||||||
|
|||||||
Reference in New Issue
Block a user