mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
feat(manager): add slow send (#985)
This commit is contained in:
parent
fbadd8924f
commit
817c4fab61
1
go.mod
1
go.mod
@ -25,6 +25,7 @@ require (
|
||||
github.com/fumiama/go-registry v0.2.7
|
||||
github.com/fumiama/gotracemoe v0.0.3
|
||||
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
|
||||
github.com/fumiama/slowdo v0.0.0-20241001065001-bc474bd3fb21
|
||||
github.com/fumiama/terasu v0.0.0-20240507144117-547a591149c0
|
||||
github.com/fumiama/unibase2n v0.0.0-20240530074540-ec743fd5a6d6
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||
|
||||
2
go.sum
2
go.sum
@ -76,6 +76,8 @@ github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 h1:sQuR2+N5HurnvsZhi
|
||||
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565/go.mod h1:UUEvyLTJ7yoOA/viKG4wEis4ERydM7+Ny6gZUWgkS80=
|
||||
github.com/fumiama/libc v0.0.0-20240530081950-6f6d8586b5c5 h1:jDxsIupsT84A6WHcs6kWbst+KqrRQ8/o0VyoFMnbBOA=
|
||||
github.com/fumiama/libc v0.0.0-20240530081950-6f6d8586b5c5/go.mod h1:15P6ublJ9FJR8YQCGy8DeQ2Uwur7iW9Hserr/T3OFZE=
|
||||
github.com/fumiama/slowdo v0.0.0-20241001065001-bc474bd3fb21 h1:sqg6DgXnL7PcArzLnKgaiQbs2nY6xdR21ChA+ciAjz0=
|
||||
github.com/fumiama/slowdo v0.0.0-20241001065001-bc474bd3fb21/go.mod h1:nFAMdYFZxaTG/HLmRO0mKmvaGJ/vKtgYj06x8q2LusY=
|
||||
github.com/fumiama/sqlite3 v1.29.10-simp h1:c5y3uKyU0q9t0/SyfynzYyuslQ5zP+5CD8e0yYY554A=
|
||||
github.com/fumiama/sqlite3 v1.29.10-simp/go.mod h1:ItX2a1OVGgNsFh6Dv60JQvGfJfTPHPVpV6DF59akYOA=
|
||||
github.com/fumiama/terasu v0.0.0-20240507144117-547a591149c0 h1:So/3Bg/m2ZcUvqCzzEjjkjHBjcvnV3AN5tCxwsdMwYU=
|
||||
|
||||
@ -496,10 +496,10 @@ func init() { // 插件主体
|
||||
var w welcome
|
||||
err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
|
||||
if err == nil {
|
||||
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg)))
|
||||
collectsend(ctx, message.ParseMessageFromString(welcometocq(ctx, w.Msg))...)
|
||||
} else {
|
||||
userid := ctx.Event.UserID
|
||||
ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们..."))
|
||||
collectsend(ctx, message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们..."))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
40
plugin/manager/slow.go
Normal file
40
plugin/manager/slow.go
Normal file
@ -0,0 +1,40 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/RomiChan/syncx"
|
||||
"github.com/fumiama/slowdo"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
var slowsenders = syncx.Map[int64, *syncx.Lazy[*slowdo.Job[message.MessageSegment, *zero.Ctx]]]{}
|
||||
|
||||
func collectsend(ctx *zero.Ctx, msgs ...message.MessageSegment) {
|
||||
id := ctx.Event.GroupID
|
||||
if id == 0 {
|
||||
// only support group
|
||||
return
|
||||
}
|
||||
lazy, _ := slowsenders.LoadOrStore(id, &syncx.Lazy[*slowdo.Job[message.MessageSegment, *zero.Ctx]]{
|
||||
Init: func() *slowdo.Job[message.MessageSegment, *zero.Ctx] {
|
||||
x, err := slowdo.NewJob(time.Second*5, ctx, func(ctx *zero.Ctx, msg []message.MessageSegment) {
|
||||
m := make(message.Message, len(msg))
|
||||
for i, item := range msg {
|
||||
m[i] = ctxext.FakeSenderForwardNode(ctx, item)
|
||||
}
|
||||
ctx.SendGroupForwardMessage(id, m)
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return x
|
||||
},
|
||||
})
|
||||
job := lazy.Get()
|
||||
for _, msg := range msgs {
|
||||
job.Add(msg)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user