From 41dff2d35f6dc6d23e6c858a9c3699ad24f42e35 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, 16 Nov 2023 23:49:29 +0900 Subject: [PATCH] fix uid gid --- context.go | 13 +++++++++++-- rule.go | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/context.go b/context.go index 008e022..ca15044 100644 --- a/context.go +++ b/context.go @@ -285,8 +285,8 @@ func (ctx *Ctx) Break() { ctx.ma.Break = true } -// SenderID 唯一的发送者 ID -func (ctx *Ctx) SenderID() uint64 { +// GroupID 唯一的发送者所属组 ID +func (ctx *Ctx) GroupID() uint64 { grp := uint64(0) if ctx.IsQQ { if OnlyQQGroup(ctx) { @@ -305,3 +305,12 @@ func (ctx *Ctx) SenderID() uint64 { } return grp } + +// GroupID 唯一的发送者 ID +func (ctx *Ctx) UserID() uint64 { + if ctx.IsQQ { + return DigestID(ctx.Message.Author.ID) + } + grp, _ := strconv.ParseUint(ctx.Message.Author.ID, 10, 64) + return grp +} diff --git a/rule.go b/rule.go index d1859ca..c56c7fd 100644 --- a/rule.go +++ b/rule.go @@ -17,8 +17,11 @@ func newctrl(service string, o *ctrl.Options[*Ctx]) Rule { return func(ctx *Ctx) bool { ctx.State["manager"] = c if ctx.Message != nil { - gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64) - uid, _ := strconv.ParseUint(ctx.Message.Author.ID, 10, 64) + gid := ctx.GroupID() + uid := ctx.UserID() + if gid == 0 || uid == 0 { + return false + } return c.Handler(int64(gid), int64(uid)) } return false @@ -41,7 +44,7 @@ func init() { }, UserOrGrpAdmin).SetBlock(true).Limit(func(ctx *Ctx) *rate.Limiter { return respLimiterManager.Load(ctx.Message.ChannelID) }).secondPriority().Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return } @@ -105,7 +108,7 @@ func init() { OnMessageCommandGroup([]string{ "启用", "enable", "禁用", "disable", }, UserOrGrpAdmin).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return } @@ -156,7 +159,7 @@ func init() { }) OnMessageCommandGroup([]string{"还原", "reset"}, UserOrGrpAdmin).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return } @@ -177,7 +180,7 @@ func init() { OnMessageCommandGroup([]string{ "禁止", "ban", "允许", "permit", }, AdminPermission).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return } @@ -327,7 +330,7 @@ func init() { OnMessageCommandGroup([]string{"用法", "usage"}, UserOrGrpAdmin).SetBlock(true).secondPriority(). Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return } @@ -347,7 +350,7 @@ func init() { OnMessageCommandGroup([]string{"服务列表", "service_list"}, UserOrGrpAdmin).SetBlock(true).secondPriority(). Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return } @@ -364,7 +367,7 @@ func init() { OnMessageCommandGroup([]string{"服务详情", "service_detail"}, UserOrGrpAdmin).SetBlock(true).secondPriority(). Handle(func(ctx *Ctx) { - grp := ctx.SenderID() + grp := ctx.GroupID() if grp == 0 { return }