diff --git a/core/carry.go b/core/carry.go index 7ed518e..87c38ce 100644 --- a/core/carry.go +++ b/core/carry.go @@ -213,7 +213,11 @@ func initCarry() { for i, cg := range tmp { if cg.ID == ocg.ID { tmp = append(tmp[:i], tmp[i+1:]...) - RemListenOnGroup(cg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", cg.ID)) + name := cg.ChatName + if name == "" { + name = cg.ID + } + RemListenOnGroup(cg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", name)) break } } @@ -225,15 +229,19 @@ func initCarry() { for i, cg := range tmp { if cg.ID == ocg.ID { tmp[i] = ncg + name := ncg.ChatName + if name == "" { + name = ncg.ID + } if ncg.In { if ncg.Enable { - AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", ncg.ID)) - AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", ncg.ID)) + AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name)) + AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name)) } else { - RemListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", ncg.ID)) + RemListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", name)) } } else { - RemListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", ncg.ID)) + RemListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", name)) } break } @@ -246,8 +254,12 @@ func initCarry() { if ncg.ID != "" { tmp = append(tmp, ncg) if ncg.In && ncg.Enable { - AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", ncg.ID)) - AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", ncg.ID)) + name := ncg.ChatName + if name == "" { + name = ncg.ID + } + AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name)) + AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name)) } } else { return nil diff --git a/core/plugin_core.go b/core/plugin_core.go index 5ec34c9..68d5eca 100644 --- a/core/plugin_core.go +++ b/core/plugin_core.go @@ -169,8 +169,8 @@ func initPlugins() { su.DeleteValue("platform") } } else { - su.DeleteValue("rule") - su.DeleteValue("cron") + // su.DeleteValue("rule") + // su.DeleteValue("cron") su.DeleteValue("web") su.DeleteValue("admin") su.DeleteValue("priority") diff --git a/mongodb/main.go b/mongodb/main.go index 49c3252..31ba20e 100644 --- a/mongodb/main.go +++ b/mongodb/main.go @@ -3,6 +3,7 @@ package mongodb import ( "context" + "github.com/cdle/sillyplus/utils" "github.com/dop251/goja" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" @@ -96,8 +97,31 @@ func (cl *Collection) FindOneAndUpdate(filter interface{}, update interface{}) i return result } -func (cl *Collection) Find(filter interface{}) interface{} { - cur, err := cl.collection.Find(context.Background(), filter) +func (cl *Collection) Find(filter interface{}, params map[string]interface{}) interface{} { + opts := []*options.FindOptions{} + count := false + if v, ok := params["sort"]; ok { + opt := options.Find() + opt.SetSort(v) + opts = append(opts, opt) + } + if _, ok := params["count"]; ok { + count = true + } else { + if v, ok := params["skip"]; ok { + opt := options.Find() + opt.SetSkip(utils.Int64(v)) + opts = append(opts, opt) + } + if v, ok := params["limit"]; ok { + opt := options.Find() + opt.SetLimit(utils.Int64(v)) + opts = append(opts, opt) + } + } + // opts.SetSkip((pageNumber - 1) * pageSize) + // opts.SetLimit(pageSize) + cur, err := cl.collection.Find(context.Background(), filter, opts...) if err != nil { panic(cl.Vm.NewGoError(err)) } @@ -114,6 +138,13 @@ func (cl *Collection) Find(filter interface{}) interface{} { if err := cur.Err(); err != nil { panic(cl.Vm.NewGoError(err)) } + if count { + v, _ := cl.collection.CountDocuments(context.Background(), filter) + return map[string]interface{}{ + "count": v, + "results": results, + } + } return results }