From 1da8d6a48ac5ee0a36a43670b1326219535c5bc1 Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Sat, 16 Oct 2021 17:48:12 +0800 Subject: [PATCH] update --- .gitignore | 3 ++- core/otto.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d7b071c..f3e8653 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ data dwz replies qinglongs -sets.conf \ No newline at end of file +sets.conf +_* \ No newline at end of file diff --git a/core/otto.go b/core/otto.go index 74b8e46..ca6af2f 100644 --- a/core/otto.go +++ b/core/otto.go @@ -22,6 +22,8 @@ func init() { }() } +var OttoFuncs = map[string]func(string) string{} + func init123() { files, err := ioutil.ReadDir(ExecPath + "/develop/replies") if err != nil { @@ -141,8 +143,8 @@ func init123() { if res := regexp.MustCompile(`\[admin:([^\[\]]+)\]`).FindStringSubmatch(data); len(res) != 0 { admin = strings.Trim(res[1], " ") == "true" } - if len(rules) == 0 { - logs.Warn("回复:%s找不到规则", jr, err) + if len(rules) == 0 && cron == "" { + logs.Warn("回复:%s无效文件", jr, err) continue } var handler = func(s Sender) interface{} { @@ -155,6 +157,15 @@ func init123() { return v } vm := otto.New() + vm.Set("call", func(call otto.FunctionCall) otto.Value { + key := call.Argument(0).String() + value := call.Argument(1).String() + if f, ok := OttoFuncs[key]; ok { + v, _ := otto.ToValue(f(value)) + return v + } + return otto.Value{} + }) vm.Set("Delete", func() { s.Delete() })