update
This commit is contained in:
+18
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/httplib"
|
"github.com/beego/beego/v2/adapter/httplib"
|
||||||
"github.com/buger/jsonparser"
|
"github.com/buger/jsonparser"
|
||||||
@@ -96,9 +97,15 @@ func InitReplies() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
s.Reply(f)
|
s.Reply(f)
|
||||||
case "template": //gjson(list, i?, \n)
|
case "template":
|
||||||
data, _ := ioutil.ReadAll(rsp.Body)
|
data, _ := ioutil.ReadAll(rsp.Body)
|
||||||
content := reply.Request.Template
|
content := reply.Request.Template
|
||||||
|
for _, re := range regexp.MustCompile(`tfmt[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
||||||
|
v := re[0]
|
||||||
|
get := strings.Replace(strings.TrimRight(v, ")"), "tfmt(", "", -1)
|
||||||
|
f := time.Now().Format(get)
|
||||||
|
content = strings.Replace(content, v, f, -1)
|
||||||
|
}
|
||||||
for _, re := range regexp.MustCompile(`gjson[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
for _, re := range regexp.MustCompile(`gjson[(][^()]+[)]`).FindAllStringSubmatch(content, -1) {
|
||||||
v := re[0]
|
v := re[0]
|
||||||
get := strings.Replace(strings.TrimRight(v, ")"), "gjson(", "", -1)
|
get := strings.Replace(strings.TrimRight(v, ")"), "gjson(", "", -1)
|
||||||
@@ -119,22 +126,26 @@ func InitReplies() {
|
|||||||
ptn = ps[1]
|
ptn = ps[1]
|
||||||
con = ps[2]
|
con = ps[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
ptns := []string{}
|
ptns := []string{}
|
||||||
for {
|
for {
|
||||||
cptn := ptn
|
cptn := ptn
|
||||||
cget := strings.Replace(get, "[i]", fmt.Sprintf(`[%d]`, i), -1)
|
cget := strings.Replace(get, "[i]", fmt.Sprintf(`[%d]`, i), -1)
|
||||||
f, err := jsonparser.GetString(data, strings.Split(cget, ".")...)
|
f, _, _, err := jsonparser.Get(data, strings.Split(cget, ".")...)
|
||||||
i++
|
i++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
cptn = strings.Replace(cptn, "[i]", fmt.Sprintf(`%d`, i), -1)
|
cptn = strings.Replace(cptn, "[i]", fmt.Sprintf(`%d`, i), -1)
|
||||||
|
for _, v := range regexp.MustCompile(`\[(\?[^\[\]]*)\]`).FindAllStringSubmatch(cptn, -1) {
|
||||||
cptn = strings.Replace(cptn, "[?]", f, -1)
|
g := ""
|
||||||
|
if v[1] == "?" {
|
||||||
|
g = string(f)
|
||||||
|
} else {
|
||||||
|
g, _ = jsonparser.GetString(data, strings.Split(v[1], ".")[1:]...)
|
||||||
|
}
|
||||||
|
cptn = strings.Replace(cptn, fmt.Sprintf(`"[%s]"`, v[1]), g, -1)
|
||||||
|
}
|
||||||
ptns = append(ptns, cptn)
|
ptns = append(ptns, cptn)
|
||||||
}
|
}
|
||||||
content = strings.Replace(content, v, strings.Join(ptns, con), -1)
|
content = strings.Replace(content, v, strings.Join(ptns, con), -1)
|
||||||
|
|||||||
Reference in New Issue
Block a user