Skip to content

Commit c549f6f

Browse files
committed
✨ 添加违禁词解释
1 parent 21aa3bc commit c549f6f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ zerobot [-h] [-m] [-n nickname] [-t token] [-u url] [-g url] [-p prefix] [-d|w]
192192

193193
- [x] 早安 | 晚安
194194

195+
</details>
196+
<details>
197+
<summary>违禁词检测</summary>
198+
199+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/antiabuse"
200+
`
201+
- [x] 添加违禁词
202+
203+
- [x] 删除违禁词
204+
205+
- [x] 查看违禁词
206+
195207
</details>
196208
<details>
197209
<summary>ATRI</summary>

plugin/antiabuse/anti.go

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

20-
const bandur time.Duration = time.Minute * 10
20+
const bandur time.Duration = time.Minute * 2
2121

2222
var (
2323
managers *ctrl.Manager[*zero.Ctx] // managers lazy load
@@ -41,7 +41,7 @@ func init() {
4141
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
4242
DisableOnDefault: false,
4343
Brief: "违禁词检测",
44-
Help: "- /[添加|删除|查看]违禁词",
44+
Help: "- [添加|删除|查看]违禁词",
4545
PrivateDataFolder: "anti_abuse",
4646
})
4747

@@ -57,9 +57,6 @@ func init() {
5757
})
5858

5959
engine.OnMessage(onceRule, zero.OnlyGroup, func(ctx *zero.Ctx) bool {
60-
if !ctx.Event.IsToMe {
61-
return true
62-
}
6360
uid := ctx.Event.UserID
6461
gid := ctx.Event.GroupID
6562
msg := strings.ReplaceAll(ctx.MessageString(), "\n", "")
@@ -71,6 +68,7 @@ func init() {
7168
t := time.Now().Unix()
7269
cache.Set(uid, struct{}{})
7370
ctx.SetThisGroupBan(uid, int64(bandur.Minutes()))
71+
ctx.DeleteMessage(ctx.Event.MessageID)
7472
ctx.SendChain(message.Text("检测到违禁词, 已封禁/屏蔽", bandur))
7573
db.Lock()
7674
defer db.Unlock()
@@ -92,27 +90,27 @@ func init() {
9290
return true
9391
})
9492

95-
engine.OnCommand("添加违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).Handle(
93+
engine.OnPrefix("添加违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).Handle(
9694
func(ctx *zero.Ctx) {
97-
args := ctx.State["args"].(string)
95+
args := strings.TrimSpace(ctx.State["args"].(string))
9896
if err := db.insertWord(ctx.Event.GroupID, args); err != nil {
9997
ctx.SendChain(message.Text("ERROR: ", err))
10098
} else {
10199
ctx.SendChain(message.Text("成功"))
102100
}
103101
})
104102

105-
engine.OnCommand("删除违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).Handle(
103+
engine.OnPrefix("删除违禁词", zero.OnlyGroup, zero.AdminPermission, onceRule).Handle(
106104
func(ctx *zero.Ctx) {
107-
args := ctx.State["args"].(string)
105+
args := strings.TrimSpace(ctx.State["args"].(string))
108106
if err := db.deleteWord(ctx.Event.GroupID, args); err != nil {
109107
ctx.SendChain(message.Text("ERROR: ", err))
110108
} else {
111109
ctx.SendChain(message.Text("成功"))
112110
}
113111
})
114112

115-
engine.OnCommand("查看违禁词", zero.OnlyGroup, onceRule).Handle(
113+
engine.OnPrefix("查看违禁词", zero.OnlyGroup, onceRule).Handle(
116114
func(ctx *zero.Ctx) {
117115
b, err := text.RenderToBase64(db.listWords(ctx.Event.GroupID), text.FontFile, 400, 20)
118116
if err != nil {

0 commit comments

Comments
 (0)