From 2dc45f473739ec0cc168e0df29dfacc3bc1e3c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:48:01 +0800 Subject: [PATCH 1/2] feat(manager): onregex -> pattern --- plugin/manager/manager.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugin/manager/manager.go b/plugin/manager/manager.go index a0c96292b3..f1f98f6d9d 100644 --- a/plugin/manager/manager.go +++ b/plugin/manager/manager.go @@ -156,10 +156,11 @@ func init() { // 插件主体 ctx.SendChain(message.Text("全员自闭结束~")) }) // 禁言 - engine.OnRegex(`^禁言.*?(\d+).*?\s(\d+)(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + engine.OnMessage(zero.NewPattern(nil).Text("^禁言").At().Text("(\\d+)\\s*(.*)").AsRule(), zero.OnlyGroup, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { - duration := math.Str2Int64(ctx.State["regex_matched"].([]string)[2]) - switch ctx.State["regex_matched"].([]string)[3] { + parsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed) + duration := math.Str2Int64(parsed[2].Text()[1]) + switch parsed[2].Text()[2] { case "分钟": // case "小时": @@ -172,9 +173,9 @@ func init() { // 插件主体 if duration >= 43200 { duration = 43199 // qq禁言最大时长为一个月 } - ctx.SetThisGroupBan( - math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 要禁言的人的qq - duration*60, // 要禁言的时间(分钟) + ctx.SetThisGroupBan( + math.Str2Int64(parsed[1].At()), // 要禁言的人的qq + duration*60, // 要禁言的时间(分钟) ) ctx.SendChain(message.Text("小黑屋收留成功~")) }) From a2d12d617ef5351955aa7ced9c1ce0f597b22658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:51:58 +0800 Subject: [PATCH 2/2] delete nil --- plugin/manager/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/manager/manager.go b/plugin/manager/manager.go index f1f98f6d9d..fc71aa27bb 100644 --- a/plugin/manager/manager.go +++ b/plugin/manager/manager.go @@ -156,7 +156,7 @@ func init() { // 插件主体 ctx.SendChain(message.Text("全员自闭结束~")) }) // 禁言 - engine.OnMessage(zero.NewPattern(nil).Text("^禁言").At().Text("(\\d+)\\s*(.*)").AsRule(), zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + engine.OnMessage(zero.NewPattern().Text("^禁言").At().Text("(\\d+)\\s*(.*)").AsRule(), zero.OnlyGroup, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { parsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed) duration := math.Str2Int64(parsed[2].Text()[1])