add more limiter (#241)

This commit is contained in:
源文雨 2022-05-26 13:55:14 +08:00
parent c8072171f0
commit cb1b7d5da7
5 changed files with 10 additions and 9 deletions

View File

@ -105,7 +105,7 @@ func init() {
} }
return true return true
}, },
)).SetBlock(true). )).Limit(ctxext.LimitByGroup).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
// 获取该群背景类型,默认车万 // 获取该群背景类型,默认车万
kind := "车万" kind := "车万"

View File

@ -35,7 +35,7 @@ func init() {
"- 来份萝莉\n" + "- 来份萝莉\n" +
"- 设置随机图片地址[http...]", "- 设置随机图片地址[http...]",
}).ApplySingle(ctxext.DefaultSingle) }).ApplySingle(ctxext.DefaultSingle)
en.OnFullMatch("来份萝莉").SetBlock(true). en.OnFullMatch("来份萝莉").Limit(ctxext.LimitByGroup).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
go func() { go func() {
for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ { for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ {

View File

@ -158,7 +158,7 @@ func init() {
"--------------------------------\n以下技能每人只能二选一\n CD24H不跨天刷新\n--------------------------------\n" + "--------------------------------\n以下技能每人只能二选一\n CD24H不跨天刷新\n--------------------------------\n" +
"- (娶|嫁)@对方QQ\n- 当[对方Q号|@对方QQ]的小三\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) { Handle(func(ctx *zero.Ctx) {
if time.Now().Day() != lastdate.Day() { 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) { Handle(func(ctx *zero.Ctx) {
if !民政局.有登记(ctx.Event.GroupID) { if !民政局.有登记(ctx.Event.GroupID) {
ctx.SendChain(message.Text("你群并没有任何的CP额")) ctx.SendChain(message.Text("你群并没有任何的CP额"))

View File

@ -16,6 +16,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
control "github.com/FloatTech/zbputils/control" control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/img" "github.com/FloatTech/zbputils/img"
"github.com/FloatTech/zbputils/img/text" "github.com/FloatTech/zbputils/img/text"
@ -49,7 +50,7 @@ func init() {
} }
sdb = initialize(engine.DataFolder() + "score.db") 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) { Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID uid := ctx.Event.UserID
now := time.Now() now := time.Now()
@ -158,7 +159,7 @@ func init() {
} }
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile)) 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) { Handle(func(ctx *zero.Ctx) {
param := ctx.State["args"].(string) param := ctx.State["args"].(string)
var uidStr string var uidStr string
@ -174,7 +175,7 @@ func init() {
} }
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + picFile)) 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) { Handle(func(ctx *zero.Ctx) {
today := time.Now().Format("20060102") today := time.Now().Format("20060102")
drawedFile := cachePath + today + "scoreRank.png" drawedFile := cachePath + today + "scoreRank.png"

View File

@ -58,7 +58,7 @@ func init() {
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap)) logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
return true 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] match := ctx.State["regex_matched"].([]string)[1]
n := 1 n := 1
reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"} reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
@ -148,7 +148,7 @@ func init() {
} }
return true 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] match := ctx.State["regex_matched"].([]string)[1]
info, ok := infoMap[match] info, ok := infoMap[match]
if ok { if ok {