From a455a5df6cf292e19376bb8144a7782f74b094a0 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: Wed, 22 Nov 2023 21:42:08 +0900
Subject: [PATCH] fix: qq group rules
---
README.md | 6 +++---
bot.go | 7 ++++++-
example/handler/main.go | 2 +-
example/main.go | 2 +-
rules.go | 4 ++--
5 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 580e0b3..695b3a6 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
NanoBot
- 类 ZeroBot 的官方 QQ 频道适配器
+ 类ZeroBot的官方QQ频道/群聊全域机器人框架, 简单易用

@@ -54,7 +54,7 @@ func main() {
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
- Secret: "你的Secret, 目前没用到, 可以不填",
+ Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentPublic,
SuperUsers: []string{"用户ID1", "用户ID2"},
})
@@ -83,7 +83,7 @@ func main() {
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
- Secret: "你的Secret, 目前没用到, 可以不填",
+ Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentPublic,
Handler: &nano.Handler{
OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) {
diff --git a/bot.go b/bot.go
index 16e0089..93575f2 100644
--- a/bot.go
+++ b/bot.go
@@ -23,13 +23,18 @@ var (
isrunning uintptr
)
+const (
+ // SuperUserAllQQUsers 使所有 QQ 用户成为超级用户
+ SuperUserAllQQUsers = "AllQQUsers"
+)
+
// Bot 一个机器人实例的配置
type Bot struct {
AppID string `yaml:"AppID"` // AppID is BotAppID(开发者ID)
Token string `yaml:"Token"` // Token is 机器人令牌 有 Secret 则使用新版 API
token string // token 是通过 secret 获得的残血 token
Secret string `yaml:"Secret"` // Secret is 机器人令牌 V2 (AppSecret/ClientSecret) 沙盒目前虽然能登录但无法收发消息
- SuperUsers []string `yaml:"SuperUsers"` // SuperUsers 超级用户
+ SuperUsers []string `yaml:"SuperUsers"` // SuperUsers 超级用户, 特殊: AllQQUsers 将使所有 QQ 用户成为超级用户
Timeout time.Duration `yaml:"Timeout"` // Timeout is API 调用超时
Handler *Handler `yaml:"-"` // Handler 注册对各种事件的处理
Intents uint32 `yaml:"Intents"` // Intents 欲接收的事件
diff --git a/example/handler/main.go b/example/handler/main.go
index 2d786de..9e3be34 100644
--- a/example/handler/main.go
+++ b/example/handler/main.go
@@ -13,7 +13,7 @@ func main() {
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
- Secret: "你的Secret, 目前没用到, 可以不填",
+ Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentGuildPublic,
Handler: &nano.Handler{
OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) {
diff --git a/example/main.go b/example/main.go
index 934b2e2..fa6995d 100644
--- a/example/main.go
+++ b/example/main.go
@@ -17,7 +17,7 @@ func main() {
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
- Secret: "你的Secret, 目前没用到, 可以不填",
+ Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentGuildPublic,
SuperUsers: []string{"用户ID1", "用户ID2"},
})
diff --git a/rules.go b/rules.go
index edcf070..b68673f 100644
--- a/rules.go
+++ b/rules.go
@@ -313,7 +313,7 @@ func OnlyChannel(ctx *Ctx) bool {
// OnlyPublic 消息类型包含 At 或 Public (包括QQ群)
func OnlyPublic(ctx *Ctx) bool {
if ctx.Type != "" {
- return strings.HasPrefix(ctx.Type, "At") || strings.HasPrefix(ctx.Type, "Public")
+ return strings.HasPrefix(ctx.Type, "At") || strings.HasPrefix(ctx.Type, "Public") || strings.HasPrefix(ctx.Type, "GroupAt")
}
return false
}
@@ -341,7 +341,7 @@ func SuperUserPermission(ctx *Ctx) bool {
return false
}
for _, su := range ctx.caller.SuperUsers {
- if su == msg.Author.ID {
+ if su == msg.Author.ID || (ctx.IsQQ && su == SuperUserAllQQUsers) {
return true
}
}