-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadmin.go
133 lines (116 loc) · 2.91 KB
/
admin.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package tfcc
import (
. "github.com/CuteReimu/onebot"
"log/slog"
"strconv"
"strings"
)
func init() {
addCmdListener(&delAdmin{})
addCmdListener(&addAdmin{})
addCmdListener(&listAllAdmin{})
}
type delAdmin struct{}
func (d *delAdmin) Name() string {
return "删除管理员"
}
func (d *delAdmin) ShowTips(int64, int64) string {
return "删除管理员 对方QQ号"
}
func (d *delAdmin) CheckAuth(_ int64, senderId int64) bool {
return IsSuperAdmin(senderId)
}
func (d *delAdmin) 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 IsSuperAdmin(qq) {
return MessageChain{&Text{Text: "你不能删除自己"}}
}
if !IsAdmin(qq) {
return MessageChain{&Text{Text: s + "并不是管理员"}}
}
qqNumbers = append(qqNumbers, qq)
}
if len(qqNumbers) == 0 {
return nil
}
for _, qq := range qqNumbers {
RemoveAdmin(qq)
}
ret := "已删除管理员"
if len(qqNumbers) == 1 {
ret += ":" + strconv.FormatInt(qqNumbers[0], 10)
}
return MessageChain{&Text{Text: ret}}
}
type addAdmin struct{}
func (a *addAdmin) Name() string {
return "增加管理员"
}
func (a *addAdmin) ShowTips(int64, int64) string {
return "增加管理员 对方QQ号"
}
func (a *addAdmin) CheckAuth(_ int64, senderId int64) bool {
return IsSuperAdmin(senderId)
}
func (a *addAdmin) 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 IsSuperAdmin(qq) || IsAdmin(qq) {
return MessageChain{&Text{Text: s + "已经是管理员了"}}
}
qqNumbers = append(qqNumbers, qq)
}
if len(qqNumbers) == 0 {
return nil
}
for _, qq := range qqNumbers {
AddAdmin(qq)
}
ret := "已增加管理员"
if len(qqNumbers) == 1 {
ret += ":" + strconv.FormatInt(qqNumbers[0], 10)
}
return MessageChain{&Text{Text: ret}}
}
type listAllAdmin struct{}
func (l *listAllAdmin) Name() string {
return "查看管理员"
}
func (l *listAllAdmin) ShowTips(int64, int64) string {
return ""
}
func (l *listAllAdmin) CheckAuth(int64, int64) bool {
return true
}
func (l *listAllAdmin) Execute(*GroupMessage, string) MessageChain {
superAdmin := tfccConfig.GetInt64("qq.super_admin_qq")
admin := permData.GetIntSlice("admin")
s := make([]string, 0, len(admin)+2)
s = append(s, "管理员列表:")
s = append(s, strconv.FormatInt(superAdmin, 10))
for _, qq := range admin {
s = append(s, strconv.Itoa(qq))
}
return MessageChain{&Text{Text: strings.Join(s, "\n")}}
}