From ff068a05b0fbe16c1f02f75f3769d74505aedf2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 6 Mar 2022 22:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E5=AE=9A=E6=97=B6=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E8=A7=A6=E5=8F=91=E5=99=A8=E6=8F=92=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=99=90=E9=80=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/job/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/job/main.go b/plugin/job/main.go index a2b2dada..f1c92e30 100644 --- a/plugin/job/main.go +++ b/plugin/job/main.go @@ -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,7 +109,9 @@ func islonotnil(ctx *zero.Ctx) bool { func inject(bot int64, response []byte) func() { return func() { - lo[bot].Echo(response) + if limit.Acquire() { + lo[bot].Echo(response) + } } }