Skip to content

Commit dfdf779

Browse files
committed
feat(chat): agnet add hooked mark
1 parent b2fb69a commit dfdf779

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

chat/agent.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"io"
99
"reflect"
1010
"strconv"
11-
"sync"
1211
"time"
1312

1413
"github.com/RomiChan/syncx"
@@ -34,8 +33,7 @@ var AgentChar []byte
3433
var IsAgentCharReady = false
3534

3635
var (
37-
inActionMu = sync.Mutex{}
38-
ags = syncx.Map[int64, *goba.Agent]{}
36+
ags = syncx.Map[int64, *goba.Agent]{}
3937
)
4038

4139
type charcfg struct {
@@ -92,19 +90,15 @@ var checkgids = map[string]struct{}{
9290
}
9391

9492
// CallAgent and check group API permission
95-
func CallAgent(ag *goba.Agent, issudo bool, iter int, api deepinfra.API, p model.Protocol, grp int64, role goba.PermRole) (
96-
[]zero.APIRequest, func(),
97-
) {
98-
inActionMu.Lock()
93+
func CallAgent(ag *goba.Agent, issudo bool, iter int, api deepinfra.API, p model.Protocol, grp int64, role goba.PermRole) []zero.APIRequest {
9994
reqs, err := ag.GetAction(api, p, grp, role, iter, false)
10095
if err != nil {
101-
inActionMu.Unlock()
10296
if !errors.Is(err, io.EOF) {
10397
logrus.Warnln("[chat] agent err:", err, reqs)
10498
} else {
10599
logrus.Infoln("[chat] agent end action")
106100
}
107-
return nil, nil
101+
return nil
108102
}
109103
logrus.Infoln("[chat] agent do:", reqs)
110104
checkedreqs := make([]zero.APIRequest, 0, len(reqs))
@@ -153,7 +147,7 @@ func CallAgent(ag *goba.Agent, issudo bool, iter int, api deepinfra.API, p model
153147
}
154148
checkedreqs = append(checkedreqs, req)
155149
}
156-
return checkedreqs, inActionMu.Unlock
150+
return checkedreqs
157151
}
158152

159153
func togobaev(ev *zero.Event) *goba.Event {
@@ -220,11 +214,6 @@ func logev(ctx *zero.Ctx) {
220214
if countParamsLength(req.Params) > 256 { // skip too long req&resp
221215
return
222216
}
223-
if inActionMu.TryLock() {
224-
defer inActionMu.Unlock()
225-
} else {
226-
return
227-
}
228217
gid := ctx.Event.GroupID
229218
if gid == 0 {
230219
gid = -ctx.Event.UserID
@@ -242,11 +231,7 @@ func logev(ctx *zero.Ctx) {
242231
})
243232
}),
244233
)
245-
if inActionMu.TryLock() {
246-
defer inActionMu.Unlock()
247-
} else {
248-
return
249-
}
234+
ctx.State[zero.StateKeyPrefixKeep+"_chat_ag_hooked__"] = struct{}{}
250235
gid := ctx.Event.GroupID
251236
if gid == 0 {
252237
gid = -ctx.Event.UserID

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/swaggo/gin-swagger v1.6.1
2626
github.com/swaggo/swag v1.16.6
2727
github.com/tidwall/gjson v1.18.0
28-
github.com/wdvxdr1123/ZeroBot v1.8.3-0.20260103120253-8a8f1347f983
28+
github.com/wdvxdr1123/ZeroBot v1.8.3-0.20260108153355-cbf2ab0dd527
2929
gopkg.in/yaml.v3 v3.0.1
3030
)
3131

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
189189
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
190190
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
191191
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
192-
github.com/wdvxdr1123/ZeroBot v1.8.3-0.20260103120253-8a8f1347f983 h1:hb2FUDooAf3u32wCTgJcBBuGPZF1sjgj8NfJaSy529s=
193-
github.com/wdvxdr1123/ZeroBot v1.8.3-0.20260103120253-8a8f1347f983/go.mod h1:trueIIVRywKJa3ov4QphzVvzYzgCNrlXdf9JvPJOFW8=
192+
github.com/wdvxdr1123/ZeroBot v1.8.3-0.20260108153355-cbf2ab0dd527 h1:QQAAftj7MvP+Ebxfs1MV5d6fswYi6YJ2YFkoicFpcEY=
193+
github.com/wdvxdr1123/ZeroBot v1.8.3-0.20260108153355-cbf2ab0dd527/go.mod h1:trueIIVRywKJa3ov4QphzVvzYzgCNrlXdf9JvPJOFW8=
194194
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
195195
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
196196
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=

0 commit comments

Comments
 (0)