From cb1b7d5da7f66431bd5aaa60e9636beec0fa33ce 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: Thu, 26 May 2022 13:55:14 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20more=20limiter=20(#241)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/fortune/fortune.go | 2 +- plugin/lolicon/lolicon.go | 2 +- plugin/qqwife/qqmapwife.go | 4 ++-- plugin/score/sign_in.go | 7 ++++--- plugin/tarot/tarot.go | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugin/fortune/fortune.go b/plugin/fortune/fortune.go index ad9cc94b..9647d21b 100644 --- a/plugin/fortune/fortune.go +++ b/plugin/fortune/fortune.go @@ -105,7 +105,7 @@ func init() { } return true }, - )).SetBlock(true). + )).Limit(ctxext.LimitByGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { // 获取该群背景类型,默认车万 kind := "车万" diff --git a/plugin/lolicon/lolicon.go b/plugin/lolicon/lolicon.go index fb1d52ed..5d70624e 100644 --- a/plugin/lolicon/lolicon.go +++ b/plugin/lolicon/lolicon.go @@ -35,7 +35,7 @@ func init() { "- 来份萝莉\n" + "- 设置随机图片地址[http...]", }).ApplySingle(ctxext.DefaultSingle) - en.OnFullMatch("来份萝莉").SetBlock(true). + en.OnFullMatch("来份萝莉").Limit(ctxext.LimitByGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { go func() { for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ { diff --git a/plugin/qqwife/qqmapwife.go b/plugin/qqwife/qqmapwife.go index bb5e7b7d..68940d38 100644 --- a/plugin/qqwife/qqmapwife.go +++ b/plugin/qqwife/qqmapwife.go @@ -158,7 +158,7 @@ func init() { "--------------------------------\n以下技能每人只能二选一\n CD24H,不跨天刷新\n--------------------------------\n" + "- (娶|嫁)@对方QQ\n- 当[对方Q号|@对方QQ]的小三\n", }) - engine.OnFullMatch("娶群友", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser). + engine.OnFullMatch("娶群友", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByGroup). Handle(func(ctx *zero.Ctx) { if time.Now().Day() != lastdate.Day() { 民政局.重置() @@ -315,7 +315,7 @@ func init() { ), ) }) - engine.OnFullMatch("群老婆列表", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser). + engine.OnFullMatch("群老婆列表", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByGroup). Handle(func(ctx *zero.Ctx) { if !民政局.有登记(ctx.Event.GroupID) { ctx.SendChain(message.Text("你群并没有任何的CP额")) diff --git a/plugin/score/sign_in.go b/plugin/score/sign_in.go index 60b8e452..ba65556f 100644 --- a/plugin/score/sign_in.go +++ b/plugin/score/sign_in.go @@ -16,6 +16,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" control "github.com/FloatTech/zbputils/control" + "github.com/FloatTech/zbputils/ctxext" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/img" "github.com/FloatTech/zbputils/img/text" @@ -49,7 +50,7 @@ func init() { } sdb = initialize(engine.DataFolder() + "score.db") }() - engine.OnFullMatch("签到", zero.OnlyGroup).SetBlock(true). + engine.OnFullMatch("签到", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID now := time.Now() @@ -158,7 +159,7 @@ func init() { } ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile)) }) - engine.OnPrefix("获得签到背景", zero.OnlyGroup).SetBlock(true). + engine.OnPrefix("获得签到背景", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { param := ctx.State["args"].(string) var uidStr string @@ -174,7 +175,7 @@ func init() { } ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + picFile)) }) - engine.OnFullMatch("查看分数排名", zero.OnlyGroup).SetBlock(true). + engine.OnFullMatch("查看分数排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { today := time.Now().Format("20060102") drawedFile := cachePath + today + "scoreRank.png" diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index a5319378..204bbdb7 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -58,7 +58,7 @@ func init() { logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap)) return true }, - )).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { + )).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { match := ctx.State["regex_matched"].([]string)[1] n := 1 reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"} @@ -148,7 +148,7 @@ func init() { } return true }, - )).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { + )).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { match := ctx.State["regex_matched"].([]string)[1] info, ok := infoMap[match] if ok {