MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / collectsend

Function collectsend

plugin/manager/slow.go:14–46  ·  view source on GitHub ↗
(ctx *zero.Ctx, msgs ...message.Segment)

Source from the content-addressed store, hash-verified

12var slowsenders = syncx.Map[int64, *syncx.Lazy[*slowdo.Job[*zero.Ctx, message.Segment]]]{}
13
14func collectsend(ctx *zero.Ctx, msgs ...message.Segment) {
15 id := ctx.Event.GroupID
16 if id == 0 {
17 // only support group
18 return
19 }
20 lazy, _ := slowsenders.LoadOrStore(id, &syncx.Lazy[*slowdo.Job[*zero.Ctx, message.Segment]]{
21 Init: func() *slowdo.Job[*zero.Ctx, message.Segment] {
22 x, err := slowdo.NewJob(time.Second*5, ctx, func(ctx *zero.Ctx, msg []message.Segment) {
23 if len(msg) == 1 {
24 ctx.Send(msg)
25 return
26 }
27 m := make(message.Message, len(msg))
28 for i, item := range msg {
29 m[i] = message.CustomNode(
30 zero.BotConfig.NickName[0],
31 ctx.Event.SelfID,
32 message.Message{item})
33 }
34 ctx.SendGroupForwardMessage(id, m)
35 })
36 if err != nil {
37 panic(err)
38 }
39 return x
40 },
41 })
42 job := lazy.Get()
43 for _, msg := range msgs {
44 job.Add(msg)
45 }
46}

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected