1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-08 04:00:23 +08:00

fix uid gid

This commit is contained in:
源文雨
2023-11-16 23:49:29 +09:00
parent 0beca59240
commit 41dff2d35f
2 changed files with 23 additions and 11 deletions

View File

@@ -285,8 +285,8 @@ func (ctx *Ctx) Break() {
ctx.ma.Break = true ctx.ma.Break = true
} }
// SenderID 唯一的发送者 ID // GroupID 唯一的发送者所属组 ID
func (ctx *Ctx) SenderID() uint64 { func (ctx *Ctx) GroupID() uint64 {
grp := uint64(0) grp := uint64(0)
if ctx.IsQQ { if ctx.IsQQ {
if OnlyQQGroup(ctx) { if OnlyQQGroup(ctx) {
@@ -305,3 +305,12 @@ func (ctx *Ctx) SenderID() uint64 {
} }
return grp 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
}

21
rule.go
View File

@@ -17,8 +17,11 @@ func newctrl(service string, o *ctrl.Options[*Ctx]) Rule {
return func(ctx *Ctx) bool { return func(ctx *Ctx) bool {
ctx.State["manager"] = c ctx.State["manager"] = c
if ctx.Message != nil { if ctx.Message != nil {
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64) gid := ctx.GroupID()
uid, _ := strconv.ParseUint(ctx.Message.Author.ID, 10, 64) uid := ctx.UserID()
if gid == 0 || uid == 0 {
return false
}
return c.Handler(int64(gid), int64(uid)) return c.Handler(int64(gid), int64(uid))
} }
return false return false
@@ -41,7 +44,7 @@ func init() {
}, UserOrGrpAdmin).SetBlock(true).Limit(func(ctx *Ctx) *rate.Limiter { }, UserOrGrpAdmin).SetBlock(true).Limit(func(ctx *Ctx) *rate.Limiter {
return respLimiterManager.Load(ctx.Message.ChannelID) return respLimiterManager.Load(ctx.Message.ChannelID)
}).secondPriority().Handle(func(ctx *Ctx) { }).secondPriority().Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }
@@ -105,7 +108,7 @@ func init() {
OnMessageCommandGroup([]string{ OnMessageCommandGroup([]string{
"启用", "enable", "禁用", "disable", "启用", "enable", "禁用", "disable",
}, UserOrGrpAdmin).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) { }, UserOrGrpAdmin).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }
@@ -156,7 +159,7 @@ func init() {
}) })
OnMessageCommandGroup([]string{"还原", "reset"}, UserOrGrpAdmin).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) { OnMessageCommandGroup([]string{"还原", "reset"}, UserOrGrpAdmin).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }
@@ -177,7 +180,7 @@ func init() {
OnMessageCommandGroup([]string{ OnMessageCommandGroup([]string{
"禁止", "ban", "允许", "permit", "禁止", "ban", "允许", "permit",
}, AdminPermission).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) { }, AdminPermission).SetBlock(true).secondPriority().Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }
@@ -327,7 +330,7 @@ func init() {
OnMessageCommandGroup([]string{"用法", "usage"}, UserOrGrpAdmin).SetBlock(true).secondPriority(). OnMessageCommandGroup([]string{"用法", "usage"}, UserOrGrpAdmin).SetBlock(true).secondPriority().
Handle(func(ctx *Ctx) { Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }
@@ -347,7 +350,7 @@ func init() {
OnMessageCommandGroup([]string{"服务列表", "service_list"}, UserOrGrpAdmin).SetBlock(true).secondPriority(). OnMessageCommandGroup([]string{"服务列表", "service_list"}, UserOrGrpAdmin).SetBlock(true).secondPriority().
Handle(func(ctx *Ctx) { Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }
@@ -364,7 +367,7 @@ func init() {
OnMessageCommandGroup([]string{"服务详情", "service_detail"}, UserOrGrpAdmin).SetBlock(true).secondPriority(). OnMessageCommandGroup([]string{"服务详情", "service_detail"}, UserOrGrpAdmin).SetBlock(true).secondPriority().
Handle(func(ctx *Ctx) { Handle(func(ctx *Ctx) {
grp := ctx.SenderID() grp := ctx.GroupID()
if grp == 0 { if grp == 0 {
return return
} }