mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
🐛 定时指令触发器插件增加限速器
This commit is contained in:
parent
051b7dd182
commit
ff068a05b0
@ -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,9 +109,11 @@ 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 {
|
||||
return int64(crc64.Checksum(binary.StringToBytes(cron+cmd), crc64.MakeTable(crc64.ISO)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user