@@ -17,7 +17,12 @@ import (
17
17
"github.com/wdvxdr1123/ZeroBot/message"
18
18
)
19
19
20
- const bandur time.Duration = time .Minute * 10
20
+ const (
21
+ bandur time.Duration = time .Minute * 2
22
+ add = "添加违禁词"
23
+ del = "删除违禁词"
24
+ list = "查看违禁词"
25
+ )
21
26
22
27
var (
23
28
managers * ctrl.Manager [* zero.Ctx ] // managers lazy load
@@ -41,7 +46,7 @@ func init() {
41
46
engine := control .AutoRegister (& ctrl.Options [* zero.Ctx ]{
42
47
DisableOnDefault : false ,
43
48
Brief : "违禁词检测" ,
44
- Help : "- / [添加|删除|查看]违禁词" ,
49
+ Help : "- [添加|删除|查看]违禁词" ,
45
50
PrivateDataFolder : "anti_abuse" ,
46
51
})
47
52
@@ -56,10 +61,14 @@ func init() {
56
61
return true
57
62
})
58
63
59
- engine . OnMessage ( onceRule , zero . OnlyGroup , func (ctx * zero.Ctx ) bool {
60
- if ! ctx . Event . IsToMe {
61
- return true
64
+ notAntiabuse := func (ctx * zero.Ctx ) bool {
65
+ if zero . PrefixRule ( add )( ctx ) || zero . PrefixRule ( del )( ctx ) || zero . PrefixRule ( list )( ctx ) {
66
+ return false
62
67
}
68
+ return true
69
+ }
70
+
71
+ engine .OnMessage (onceRule , notAntiabuse , zero .OnlyGroup , func (ctx * zero.Ctx ) bool {
63
72
uid := ctx .Event .UserID
64
73
gid := ctx .Event .GroupID
65
74
msg := strings .ReplaceAll (ctx .MessageString (), "\n " , "" )
@@ -70,7 +79,8 @@ func init() {
70
79
if err := ctx .State ["manager" ].(* ctrl.Control [* zero.Ctx ]).Manager .DoBlock (uid ); err == nil {
71
80
t := time .Now ().Unix ()
72
81
cache .Set (uid , struct {}{})
73
- ctx .SetThisGroupBan (uid , int64 (bandur .Minutes ()))
82
+ ctx .SetThisGroupBan (uid , int64 (bandur .Seconds ()))
83
+ ctx .DeleteMessage (ctx .Event .MessageID )
74
84
ctx .SendChain (message .Text ("检测到违禁词, 已封禁/屏蔽" , bandur ))
75
85
db .Lock ()
76
86
defer db .Unlock ()
@@ -92,27 +102,27 @@ func init() {
92
102
return true
93
103
})
94
104
95
- engine .OnCommand ( "添加违禁词" , zero .OnlyGroup , zero .AdminPermission , onceRule ).Handle (
105
+ engine .OnPrefix ( add , zero .OnlyGroup , zero .AdminPermission , onceRule ). SetBlock ( true ).Handle (
96
106
func (ctx * zero.Ctx ) {
97
- args := ctx .State ["args" ].(string )
107
+ args := strings . TrimSpace ( ctx .State ["args" ].(string ) )
98
108
if err := db .insertWord (ctx .Event .GroupID , args ); err != nil {
99
109
ctx .SendChain (message .Text ("ERROR: " , err ))
100
110
} else {
101
111
ctx .SendChain (message .Text ("成功" ))
102
112
}
103
113
})
104
114
105
- engine .OnCommand ( "删除违禁词" , zero .OnlyGroup , zero .AdminPermission , onceRule ).Handle (
115
+ engine .OnPrefix ( del , zero .OnlyGroup , zero .AdminPermission , onceRule ). SetBlock ( true ).Handle (
106
116
func (ctx * zero.Ctx ) {
107
- args := ctx .State ["args" ].(string )
117
+ args := strings . TrimSpace ( ctx .State ["args" ].(string ) )
108
118
if err := db .deleteWord (ctx .Event .GroupID , args ); err != nil {
109
119
ctx .SendChain (message .Text ("ERROR: " , err ))
110
120
} else {
111
121
ctx .SendChain (message .Text ("成功" ))
112
122
}
113
123
})
114
124
115
- engine .OnCommand ( "查看违禁词" , zero .OnlyGroup , onceRule ).Handle (
125
+ engine .OnPrefix ( list , zero .OnlyGroup , onceRule ). SetBlock ( true ).Handle (
116
126
func (ctx * zero.Ctx ) {
117
127
b , err := text .RenderToBase64 (db .listWords (ctx .Event .GroupID ), text .FontFile , 400 , 20 )
118
128
if err != nil {
0 commit comments