From af0332f454a733cc121a4e07250654f1b8a5abd6 Mon Sep 17 00:00:00 2001 From: Yiwen-Chan Date: Mon, 12 Apr 2021 15:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0=E6=88=B3?= =?UTF-8?q?=E4=B8=80=E6=88=B3=E9=A2=91=E7=8E=87=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat/chat.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/chat/chat.go b/chat/chat.go index b9820c6e..259fa24e 100644 --- a/chat/chat.go +++ b/chat/chat.go @@ -4,14 +4,27 @@ import ( "time" zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/extension/rate" ) +var poke = rate.NewManager(time.Minute*5, 8) // 戳一戳 + func init() { // 插件主体 // 戳一戳 - zero.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).SetPriority(0). + zero.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).FirstPriority(). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) - ctx.Send("请不要戳我 >_<") + switch { + case poke.Load(ctx.Event.UserID).AcquireN(3): + // 5分钟共8块命令牌 一次消耗3块命令牌 + time.Sleep(time.Second * 1) + ctx.Send("请不要戳我 >_<") + case poke.Load(ctx.Event.UserID).Acquire(): + // 5分钟共8块命令牌 一次消耗1块命令牌 + time.Sleep(time.Second * 1) + ctx.Send("喂(#`O′) 戳我干嘛!") + default: + // 频繁触发,不回复 + } return }) }