Skip to content

Commit 7d47971

Browse files
committed
fix(chat): concurrent map write
1 parent 8103788 commit 7d47971

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

chat/agent.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ func truncatecopy(params map[string]any) map[string]any {
254254
}
255255

256256
func logev(ctx *zero.Ctx) {
257+
gid := ctx.Event.GroupID
258+
if gid == 0 {
259+
gid = -ctx.Event.UserID
260+
}
261+
ev := togobaev(ctx.Event)
262+
if ev == nil {
263+
return
264+
}
265+
data, _ := json.Marshal(ev)
266+
logrus.Debugln("[chat] agent", gid, "add ev:", binary.BytesToString(data))
267+
AgentOf(ctx.Event.SelfID, "aichat").AddEvent(gid, ev)
268+
ctx.State[zero.StateKeyPrefixKeep+"_chat_ag_hooked__"] = struct{}{}
269+
257270
vevent.HookCtxCaller(ctx, vevent.NewAPICallerReturnHook(
258271
ctx, func(req zero.APIRequest, rsp zero.APIResponse, _ error) {
259272
gid := ctx.Event.GroupID
@@ -284,18 +297,6 @@ func logev(ctx *zero.Ctx) {
284297
})
285298
}),
286299
)
287-
ctx.State[zero.StateKeyPrefixKeep+"_chat_ag_hooked__"] = struct{}{}
288-
gid := ctx.Event.GroupID
289-
if gid == 0 {
290-
gid = -ctx.Event.UserID
291-
}
292-
ev := togobaev(ctx.Event)
293-
if ev == nil {
294-
return
295-
}
296-
data, _ := json.Marshal(ev)
297-
logrus.Debugln("[chat] agent", gid, "add ev:", binary.BytesToString(data))
298-
AgentOf(ctx.Event.SelfID, "aichat").AddEvent(gid, ev)
299300
}
300301

301302
func init() {

0 commit comments

Comments
 (0)