-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhitelist.go
106 lines (94 loc) · 2.5 KB
/
whitelist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package hkbot
import (
. "github.com/CuteReimu/onebot"
"log/slog"
"strconv"
"strings"
)
func init() {
addCmdListener(&delWhitelist{})
addCmdListener(&addWhitelist{})
}
type delWhitelist struct{}
func (d *delWhitelist) Name() string {
return "删除词条权限"
}
func (d *delWhitelist) ShowTips(int64, int64) string {
return "删除词条权限 对方QQ号"
}
func (d *delWhitelist) CheckAuth(_ int64, senderId int64) bool {
return IsAdmin(senderId)
}
func (d *delWhitelist) Execute(_ *GroupMessage, content string) MessageChain {
ss := strings.Split(content, " ")
qqNumbers := make([]int64, 0, len(ss))
for _, s := range ss {
s = strings.TrimSpace(s)
if len(s) == 0 {
continue
}
qq, err := strconv.ParseInt(s, 10, 64)
if err != nil {
slog.Error("parse failed: "+s, "error", err)
return nil
}
if !IsWhitelist(qq) {
return MessageChain{&Text{Text: s + "并没有词条权限"}}
}
qqNumbers = append(qqNumbers, qq)
}
if len(qqNumbers) == 0 {
return MessageChain{&Text{Text: "指令格式如下:\n删除词条权限 对方QQ号"}}
}
for _, qq := range qqNumbers {
RemoveWhitelist(qq)
}
ret := "已删除词条权限"
if len(qqNumbers) == 1 {
ret += ":" + strconv.FormatInt(qqNumbers[0], 10)
}
return MessageChain{&Text{Text: ret}}
}
type addWhitelist struct{}
func (a *addWhitelist) Name() string {
return "增加词条权限"
}
func (a *addWhitelist) ShowTips(int64, int64) string {
return "增加词条权限 对方QQ号"
}
func (a *addWhitelist) CheckAuth(_ int64, senderId int64) bool {
return IsAdmin(senderId)
}
func (a *addWhitelist) Execute(msg *GroupMessage, content string) MessageChain {
ss := strings.Split(content, " ")
qqNumbers := make([]int64, 0, len(ss))
for _, s := range ss {
s = strings.TrimSpace(s)
if len(s) == 0 {
continue
}
qq, err := strconv.ParseInt(s, 10, 64)
if err != nil {
slog.Error("parse failed: "+s, "error", err)
return nil
}
if IsWhitelist(qq) {
return MessageChain{&Text{Text: s + "已经有词条权限了"}}
}
if _, err := B.GetGroupMemberInfo(msg.GroupId, qq, false); err != nil {
return MessageChain{&Text{Text: s + "不是群成员"}}
}
qqNumbers = append(qqNumbers, qq)
}
if len(qqNumbers) == 0 {
return MessageChain{&Text{Text: "指令格式如下:\n增加词条权限 对方QQ号"}}
}
for _, qq := range qqNumbers {
AddWhitelist(qq)
}
ret := "已增加词条权限"
if len(qqNumbers) == 1 {
ret += ":" + strconv.FormatInt(qqNumbers[0], 10)
}
return MessageChain{&Text{Text: ret}}
}