This commit is contained in:
cdle
2023-06-19 10:37:49 +08:00
parent 9ae82539b4
commit f18e8506fa
3 changed files with 54 additions and 11 deletions
+19 -7
View File
@@ -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
+2 -2
View File
@@ -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")
+33 -2
View File
@@ -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
}