🐛 定时指令触发器插件增加限速器

This commit is contained in:
源文雨 2022-03-06 22:52:38 +08:00
parent 051b7dd182
commit ff068a05b0

View File

@ -16,6 +16,7 @@ import (
"github.com/fumiama/cron"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
)
@ -23,6 +24,7 @@ var (
lo map[int64]vevent.Loop
entries map[int64]cron.EntryID // id entryid
mu sync.Mutex
limit = rate.NewLimiter(time.Second*10, 5)
)
func init() {
@ -107,8 +109,10 @@ func islonotnil(ctx *zero.Ctx) bool {
func inject(bot int64, response []byte) func() {
return func() {
if limit.Acquire() {
lo[bot].Echo(response)
}
}
}
func idof(cron, cmd string) int64 {