mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
🐛 定时指令触发器插件增加限速器
This commit is contained in:
parent
051b7dd182
commit
ff068a05b0
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/fumiama/cron"
|
"github.com/fumiama/cron"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ var (
|
|||||||
lo map[int64]vevent.Loop
|
lo map[int64]vevent.Loop
|
||||||
entries map[int64]cron.EntryID // id entryid
|
entries map[int64]cron.EntryID // id entryid
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
limit = rate.NewLimiter(time.Second*10, 5)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -107,7 +109,9 @@ func islonotnil(ctx *zero.Ctx) bool {
|
|||||||
|
|
||||||
func inject(bot int64, response []byte) func() {
|
func inject(bot int64, response []byte) func() {
|
||||||
return func() {
|
return func() {
|
||||||
lo[bot].Echo(response)
|
if limit.Acquire() {
|
||||||
|
lo[bot].Echo(response)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user