update
This commit is contained in:
+31
-1
@@ -96,7 +96,7 @@ func InitReplies() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
s.Reply(f)
|
s.Reply(f)
|
||||||
case "template":
|
case "template": //gjson(list, i?, \n)
|
||||||
data, _ := ioutil.ReadAll(rsp.Body)
|
data, _ := ioutil.ReadAll(rsp.Body)
|
||||||
content := reply.Request.Template
|
content := reply.Request.Template
|
||||||
for _, re := range regexp.MustCompile(`gjson[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
for _, re := range regexp.MustCompile(`gjson[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
||||||
@@ -105,6 +105,36 @@ func InitReplies() {
|
|||||||
f, _ := jsonparser.GetString(data, strings.Split(get, ".")...)
|
f, _ := jsonparser.GetString(data, strings.Split(get, ".")...)
|
||||||
content = strings.Replace(content, v, f, -1)
|
content = strings.Replace(content, v, f, -1)
|
||||||
}
|
}
|
||||||
|
for _, re := range regexp.MustCompile(`fjson[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
||||||
|
v := re[0]
|
||||||
|
ins := strings.Replace(strings.TrimRight(v, ")"), "gjson(", "", -1)
|
||||||
|
ps := strings.Split(ins, ",")
|
||||||
|
get := ps[0]
|
||||||
|
ptn := ""
|
||||||
|
con := ""
|
||||||
|
switch len(ps) {
|
||||||
|
case 2:
|
||||||
|
ptn = ps[1]
|
||||||
|
case 3:
|
||||||
|
con = ps[2]
|
||||||
|
}
|
||||||
|
i := 0
|
||||||
|
ptns := []string{}
|
||||||
|
for {
|
||||||
|
cptn := ptn
|
||||||
|
index := fmt.Sprintf(`[%d]`, i)
|
||||||
|
cget := strings.Replace(get, "[x]", index, -1)
|
||||||
|
f, err := jsonparser.GetString(data, strings.Split(cget, ".")...)
|
||||||
|
i++
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
cptn = strings.Replace(cptn, "[i]", index, -1)
|
||||||
|
cptn = strings.Replace(cptn, "[?]", f, -1)
|
||||||
|
ptns = append(ptns, cptn)
|
||||||
|
}
|
||||||
|
content = strings.Replace(content, v, strings.Join(ptns, con), -1)
|
||||||
|
}
|
||||||
for i := range reply.Replace {
|
for i := range reply.Replace {
|
||||||
if len(reply.Replace[i]) >= 2 {
|
if len(reply.Replace[i]) >= 2 {
|
||||||
content = strings.Replace(content, reply.Replace[i][0], reply.Replace[i][1], -1)
|
content = strings.Replace(content, reply.Replace[i][0], reply.Replace[i][1], -1)
|
||||||
|
|||||||
Reference in New Issue
Block a user