This commit is contained in:
1-6
2023-07-13 20:27:10 +08:00
parent a3fb6a5da4
commit 7777fb73cd
6 changed files with 195 additions and 20 deletions
+6 -6
View File
@@ -298,8 +298,8 @@ func initCarry() {
}
if ncg.In {
if ncg.Enable {
AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name))
AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name))
AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name), ncg.Platform)
AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name), ncg.Platform)
} else {
RemListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)关闭监听模式", name))
}
@@ -321,8 +321,8 @@ func initCarry() {
if name == "" {
name = ncg.ID
}
AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name))
AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name))
AddListenOnGroup(ncg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name), ncg.Platform)
AddNoReplyGroups(ncg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name), ncg.Platform)
}
} else {
return nil
@@ -349,8 +349,8 @@ func setCgs() {
if name == "" {
name = cg.ID
}
AddListenOnGroup(cg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name))
AddNoReplyGroups(cg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name))
AddListenOnGroup(cg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name), cg.Platform)
AddNoReplyGroups(cg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name), cg.Platform)
}
cgs = append(cgs, cg)
return nil
+4 -4
View File
@@ -39,15 +39,15 @@ type GroupInfo struct {
Enable bool `json:"enable"`
}
var AddNoReplyGroups = func(code string, desc string) {
_, loaded := NoReplyGroups.LoadOrStore(code, true)
var AddNoReplyGroups = func(code string, desc string, plt string) {
_, loaded := NoReplyGroups.LoadOrStore(code, plt)
if !loaded {
logs.Info(desc)
}
}
var AddListenOnGroup = func(code string, desc string) {
_, loaded := ListenOnGroups.LoadOrStore(code, true)
var AddListenOnGroup = func(code string, desc string, plt string) {
_, loaded := ListenOnGroups.LoadOrStore(code, plt)
if !loaded {
logs.Info(desc)
}
+17
View File
@@ -365,6 +365,23 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
vm: vm,
})
vm.Set("createNickName", CreateNickName)
vm.Set("getListenOnGroups", func(plt string) []string {
groups := []string{}
ListenOnGroups.Range(func(key, value any) bool {
if value == plt {
groups = append(groups, key.(string))
}
return true
})
StaticListenOnGroups.Range(func(key, value any) bool {
if value == plt {
groups = append(groups, key.(string))
}
return true
})
groups = utils.Unique(groups)
return groups
})
}
func EncryptPlugin(script string) string {
+5 -1
View File
@@ -27,6 +27,7 @@ type Response struct {
status int
isRedirect bool
conn *WsConn
vm *goja.Runtime
}
func (r *Response) Send(gv goja.Value) *Response {
@@ -81,7 +82,10 @@ func (r *Response) Json(ps ...interface{}) interface{} {
r.content += fmt.Sprint(data)
}
if r.conn != nil {
_, result := r.conn.WriteMessage(1, d, pattern)
err, result := r.conn.WriteMessage(1, d, pattern)
if err != nil {
panic(Error(r.vm, err))
}
r.content = ""
return result
}
+19 -9
View File
@@ -50,7 +50,7 @@ func (wc *WsConn) WriteMessage(messageType int, data []byte, pattern map[string]
if v, ok := pattern["$timeout"]; ok {
timeout = utils.Int(v)
delete(pattern, "$timeout")
} //
}
wp.Value = pattern
key := atomic.AddInt64(&wc.Key, 1)
wp.Chan = make(chan map[string]interface{}, 1)
@@ -94,9 +94,7 @@ func handleWebsocket(c *gin.Context) {
c: c,
// uuid: uuid,
}
var res = &Response{
c: c,
}
var upGrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
@@ -108,16 +106,20 @@ func handleWebsocket(c *gin.Context) {
return
}
wc := &WsConn{}
res.conn = wc
req._event = "connect"
wc.conn = ws
go function.Handle(&Faker{
Type: "websocket",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("res", &Response{
c: c,
conn: wc,
vm: vm,
})
vm.Set("req", req)
})
time.Sleep(time.Millisecond*500)
time.Sleep(time.Millisecond * 500)
for {
_, data, err := ws.ReadMessage()
wc.patterns.Range(func(key, value any) bool {
@@ -174,7 +176,11 @@ func handleWebsocket(c *gin.Context) {
function.Handle(&Faker{
Type: "websocket",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("res", &Response{
c: c,
conn: wc,
vm: vm,
})
vm.Set("req", req)
})
ws.Close()
@@ -190,7 +196,11 @@ func handleWebsocket(c *gin.Context) {
go function.Handle(&Faker{
Type: "websocket",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("res", &Response{
c: c,
conn: wc,
vm: vm,
})
vm.Set("req", req)
})
}