File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 "reflect"
1010 "strconv"
1111 "strings"
12+ "sync"
1213 "time"
1314
1415 "github.com/RomiChan/syncx"
@@ -253,6 +254,8 @@ func truncatecopy(params map[string]any) map[string]any {
253254 return cpp
254255}
255256
257+ var logevmu sync.Mutex
258+
256259func logev (ctx * zero.Ctx ) {
257260 gid := ctx .Event .GroupID
258261 if gid == 0 {
@@ -265,18 +268,28 @@ func logev(ctx *zero.Ctx) {
265268 data , _ := json .Marshal (ev )
266269 logrus .Debugln ("[chat] agent" , gid , "add ev:" , binary .BytesToString (data ))
267270 AgentOf (ctx .Event .SelfID , "aichat" ).AddEvent (gid , ev )
271+
272+ logevmu .Lock ()
273+ if _ , ok := ctx .State [zero .StateKeyPrefixKeep + "_chat_ag_hooked__" ]; ok {
274+ logevmu .Unlock ()
275+ return
276+ }
268277 ctx .State [zero .StateKeyPrefixKeep + "_chat_ag_hooked__" ] = struct {}{}
278+ logevmu .Unlock ()
269279
270280 vevent .HookCtxCaller (ctx , vevent .NewAPICallerReturnHook (
271281 ctx , func (req zero.APIRequest , rsp zero.APIResponse , _ error ) {
272282 gid := ctx .Event .GroupID
273283 if gid == 0 {
274284 gid = - ctx .Event .UserID
275285 }
286+ logevmu .Lock ()
276287 if _ , ok := ctx .State [zero .StateKeyPrefixKeep + "_chat_ag_triggered__" ]; ok {
288+ logevmu .Unlock ()
277289 logrus .Debugln ("[chat] agent" , gid , "skip agent triggered requ:" , & req )
278290 return
279291 }
292+ logevmu .Unlock ()
280293 if req .Action != "send_private_msg" &&
281294 req .Action != "send_group_msg" &&
282295 req .Action != "delete_msg" {
You can’t perform that action at this time.
0 commit comments