Skip to content

Commit 8247d65

Browse files
committed
🐛 时间错误
1 parent c549f6f commit 8247d65

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

plugin/antiabuse/anti.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import (
1717
"github.com/wdvxdr1123/ZeroBot/message"
1818
)
1919

20-
const bandur time.Duration = time.Minute * 2
20+
const (
21+
bandur time.Duration = time.Minute * 2
22+
add = "添加违禁词"
23+
delete = "删除违禁词"
24+
list = "查看违禁词"
25+
)
2126

2227
var (
2328
managers *ctrl.Manager[*zero.Ctx] // managers lazy load
@@ -56,7 +61,14 @@ func init() {
5661
return true
5762
})
5863

59-
engine.OnMessage(onceRule, zero.OnlyGroup, func(ctx *zero.Ctx) bool {
64+
notAntiabuse := func(ctx *zero.Ctx) bool {
65+
if zero.PrefixRule(add)(ctx) || zero.PrefixRule(delete)(ctx) || zero.PrefixRule(list)(ctx) {
66+
return false
67+
}
68+
return true
69+
}
70+
71+
engine.OnMessage(notAntiabuse, zero.OnlyGroup, func(ctx *zero.Ctx) bool {
6072
uid := ctx.Event.UserID
6173
gid := ctx.Event.GroupID
6274
msg := strings.ReplaceAll(ctx.MessageString(), "\n", "")
@@ -67,7 +79,7 @@ func init() {
6779
if err := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]).Manager.DoBlock(uid); err == nil {
6880
t := time.Now().Unix()
6981
cache.Set(uid, struct{}{})
70-
ctx.SetThisGroupBan(uid, int64(bandur.Minutes()))
82+
ctx.SetThisGroupBan(uid, int64(bandur.Seconds()))
7183
ctx.DeleteMessage(ctx.Event.MessageID)
7284
ctx.SendChain(message.Text("检测到违禁词, 已封禁/屏蔽", bandur))
7385
db.Lock()
@@ -90,7 +102,7 @@ func init() {
90102
return true
91103
})
92104

93-
engine.OnPrefix("添加违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).Handle(
105+
engine.OnPrefix("添加违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).SetBlock(true).Handle(
94106
func(ctx *zero.Ctx) {
95107
args := strings.TrimSpace(ctx.State["args"].(string))
96108
if err := db.insertWord(ctx.Event.GroupID, args); err != nil {
@@ -100,7 +112,7 @@ func init() {
100112
}
101113
})
102114

103-
engine.OnPrefix("删除违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).Handle(
115+
engine.OnPrefix("删除违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).SetBlock(true).Handle(
104116
func(ctx *zero.Ctx) {
105117
args := strings.TrimSpace(ctx.State["args"].(string))
106118
if err := db.deleteWord(ctx.Event.GroupID, args); err != nil {
@@ -110,7 +122,7 @@ func init() {
110122
}
111123
})
112124

113-
engine.OnPrefix("查看违禁词", zero.OnlyGroup, onceRule).Handle(
125+
engine.OnPrefix("查看违禁词", zero.OnlyGroup, onceRule).SetBlock(true).Handle(
114126
func(ctx *zero.Ctx) {
115127
b, err := text.RenderToBase64(db.listWords(ctx.Event.GroupID), text.FontFile, 400, 20)
116128
if err != nil {

0 commit comments

Comments
 (0)