mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-05 02:30:23 +08:00
fix uid gid
This commit is contained in:
13
context.go
13
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
|
||||
}
|
||||
|
||||
21
rule.go
21
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user