@zhin.js/sensitive-filter 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@zhin.js/sensitive-filter",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "Content moderation plugin for Zhin.js - filters sensitive words",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "files": [
8
+ "src",
9
+ "lib",
10
+ "client",
11
+ "dist",
12
+ "skills",
13
+ "README.md"
14
+ ],
7
15
  "keywords": [
8
16
  "zhin",
9
17
  "bot",
@@ -21,11 +29,11 @@
21
29
  },
22
30
  "license": "MIT",
23
31
  "peerDependencies": {
24
- "zhin.js": "1.0.50"
32
+ "zhin.js": "1.0.52"
25
33
  },
26
34
  "devDependencies": {
27
35
  "typescript": "^5.3.3",
28
- "zhin.js": "1.0.50"
36
+ "zhin.js": "1.0.52"
29
37
  },
30
38
  "type": "module",
31
39
  "repository": {
package/CHANGELOG.md DELETED
@@ -1,232 +0,0 @@
1
- # @zhin.js/sensitive-filter
2
-
3
- ## 0.0.36
4
-
5
- ### Patch Changes
6
-
7
- - zhin.js@1.0.50
8
-
9
- ## 0.0.35
10
-
11
- ### Patch Changes
12
-
13
- - zhin.js@1.0.49
14
-
15
- ## 0.0.34
16
-
17
- ### Patch Changes
18
-
19
- - zhin.js@1.0.48
20
-
21
- ## 0.0.33
22
-
23
- ### Patch Changes
24
-
25
- - Updated dependencies [de3e352]
26
- - zhin.js@1.0.47
27
-
28
- ## 0.0.32
29
-
30
- ### Patch Changes
31
-
32
- - Updated dependencies [7394603]
33
- - zhin.js@1.0.46
34
-
35
- ## 0.0.31
36
-
37
- ### Patch Changes
38
-
39
- - zhin.js@1.0.45
40
-
41
- ## 0.0.30
42
-
43
- ### Patch Changes
44
-
45
- - zhin.js@1.0.44
46
-
47
- ## 0.0.29
48
-
49
- ### Patch Changes
50
-
51
- - Updated dependencies [72ec4ba]
52
- - zhin.js@1.0.43
53
-
54
- ## 0.0.28
55
-
56
- ### Patch Changes
57
-
58
- - zhin.js@1.0.42
59
-
60
- ## 0.0.27
61
-
62
- ### Patch Changes
63
-
64
- - zhin.js@1.0.41
65
-
66
- ## 0.0.26
67
-
68
- ### Patch Changes
69
-
70
- - Updated dependencies [7ef9057]
71
- - zhin.js@1.0.40
72
-
73
- ## 0.0.25
74
-
75
- ### Patch Changes
76
-
77
- - zhin.js@1.0.39
78
-
79
- ## 0.0.24
80
-
81
- ### Patch Changes
82
-
83
- - Updated dependencies [ab5c54a]
84
- - zhin.js@1.0.38
85
-
86
- ## 0.0.23
87
-
88
- ### Patch Changes
89
-
90
- - zhin.js@1.0.37
91
-
92
- ## 0.0.22
93
-
94
- ### Patch Changes
95
-
96
- - zhin.js@1.0.36
97
-
98
- ## 0.0.21
99
-
100
- ### Patch Changes
101
-
102
- - zhin.js@1.0.35
103
-
104
- ## 0.0.20
105
-
106
- ### Patch Changes
107
-
108
- - zhin.js@1.0.34
109
-
110
- ## 0.0.19
111
-
112
- ### Patch Changes
113
-
114
- - zhin.js@1.0.33
115
-
116
- ## 0.0.18
117
-
118
- ### Patch Changes
119
-
120
- - zhin.js@1.0.32
121
-
122
- ## 0.0.17
123
-
124
- ### Patch Changes
125
-
126
- - zhin.js@1.0.31
127
-
128
- ## 0.0.16
129
-
130
- ### Patch Changes
131
-
132
- - Updated dependencies [460a6c6]
133
- - zhin.js@1.0.30
134
-
135
- ## 0.0.15
136
-
137
- ### Patch Changes
138
-
139
- - zhin.js@1.0.29
140
-
141
- ## 0.0.14
142
-
143
- ### Patch Changes
144
-
145
- - zhin.js@1.0.28
146
-
147
- ## 0.0.13
148
-
149
- ### Patch Changes
150
-
151
- - Updated dependencies [b27e633]
152
- - zhin.js@1.0.27
153
-
154
- ## 0.0.12
155
-
156
- ### Patch Changes
157
-
158
- - 106d357: fix: ai
159
- - Updated dependencies [106d357]
160
- - zhin.js@1.0.26
161
-
162
- ## 0.0.11
163
-
164
- ### Patch Changes
165
-
166
- - 26d2942: fix: ai
167
- - 6b02c41: fix: ai
168
- - Updated dependencies [26d2942]
169
- - Updated dependencies [6b02c41]
170
- - zhin.js@1.0.25
171
-
172
- ## 0.0.10
173
-
174
- ### Patch Changes
175
-
176
- - zhin.js@1.0.24
177
-
178
- ## 0.0.9
179
-
180
- ### Patch Changes
181
-
182
- - Updated dependencies [52ae08a]
183
- - zhin.js@1.0.23
184
-
185
- ## 0.0.8
186
-
187
- ### Patch Changes
188
-
189
- - Updated dependencies [26aba27]
190
- - zhin.js@1.0.22
191
-
192
- ## 0.0.7
193
-
194
- ### Patch Changes
195
-
196
- - zhin.js@1.0.21
197
-
198
- ## 0.0.6
199
-
200
- ### Patch Changes
201
-
202
- - a3b7673: fix: 调整依赖项
203
- - Updated dependencies [5141137]
204
- - zhin.js@1.0.20
205
-
206
- ## 0.0.5
207
-
208
- ### Patch Changes
209
-
210
- - f9faa1d: fix: test release
211
- - Updated dependencies [f9faa1d]
212
- - zhin.js@1.0.19
213
-
214
- ## 0.0.4
215
-
216
- ### Patch Changes
217
-
218
- - d16a69c: fix: test trust publish
219
- - Updated dependencies [d16a69c]
220
- - zhin.js@1.0.18
221
-
222
- ## 0.0.3
223
-
224
- ### Patch Changes
225
-
226
- - zhin.js@1.0.17
227
-
228
- ## 0.0.2
229
-
230
- ### Patch Changes
231
-
232
- - 960e2ee: fix: 增加敏感词过滤插件
@@ -1,198 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import {
3
- createSensitiveWordRegex,
4
- getEnabledWords,
5
- type SensitiveFilterOptions,
6
- politicalWords,
7
- violenceWords,
8
- pornWords,
9
- homophoneWords,
10
- } from '../src/sensitive-words'
11
-
12
- describe('敏感词过滤测试', () => {
13
- describe('敏感词正则表达式', () => {
14
- it('应该创建有效的正则表达式', () => {
15
- const words = ['测试', '敏感词']
16
- const regex = createSensitiveWordRegex(words)
17
-
18
- expect(regex).toBeInstanceOf(RegExp)
19
- // 使用 match 方法测试,因为正则表达式带有 'g' 标志,test() 方法会有状态问题
20
- expect('这是测试'.match(regex)).toBeTruthy()
21
- expect('这是敏感词'.match(regex)).toBeTruthy()
22
- expect('这是正常内容'.match(regex)).toBeNull()
23
- })
24
-
25
- it('应该转义特殊字符', () => {
26
- const words = ['$test', '.*word']
27
- const regex = createSensitiveWordRegex(words)
28
-
29
- expect('$test'.match(regex)).toBeTruthy()
30
- expect('.*word'.match(regex)).toBeTruthy()
31
- })
32
-
33
- it('应该不区分大小写', () => {
34
- const words = ['Test']
35
- const regex = createSensitiveWordRegex(words)
36
-
37
- expect('test'.match(regex)).toBeTruthy()
38
- expect('TEST'.match(regex)).toBeTruthy()
39
- expect('TeSt'.match(regex)).toBeTruthy()
40
- })
41
- })
42
-
43
- describe('获取启用的敏感词', () => {
44
- it('应该返回所有启用的敏感词', () => {
45
- const options: SensitiveFilterOptions = {
46
- political: true,
47
- violence: true,
48
- porn: true,
49
- homophone: true,
50
- }
51
-
52
- const words = getEnabledWords(options)
53
-
54
- expect(words.length).toBeGreaterThan(0)
55
- expect(words).toContain(politicalWords[0])
56
- expect(words).toContain(violenceWords[0])
57
- expect(words).toContain(pornWords[0])
58
- expect(words).toContain(homophoneWords[0])
59
- })
60
-
61
- it('应该只返回启用类别的敏感词', () => {
62
- const options: SensitiveFilterOptions = {
63
- political: true,
64
- violence: false,
65
- porn: false,
66
- homophone: false,
67
- }
68
-
69
- const words = getEnabledWords(options)
70
-
71
- expect(words).toContain(politicalWords[0])
72
- expect(words).not.toContain(violenceWords[0])
73
- expect(words).not.toContain(pornWords[0])
74
- })
75
-
76
- it('应该包含自定义敏感词', () => {
77
- const options: SensitiveFilterOptions = {
78
- custom: ['自定义词1', '自定义词2'],
79
- }
80
-
81
- const words = getEnabledWords(options)
82
-
83
- expect(words).toContain('自定义词1')
84
- expect(words).toContain('自定义词2')
85
- })
86
-
87
- it('应该正确过滤谐音词', () => {
88
- const options: SensitiveFilterOptions = {
89
- political: false,
90
- violence: false,
91
- porn: false,
92
- prohibited: false,
93
- fraud: false,
94
- illegal: false,
95
- homophone: true,
96
- }
97
-
98
- const words = getEnabledWords(options)
99
-
100
- expect(words).toContain('GCD')
101
- expect(words).toContain('sb')
102
- expect(words).toContain('cao')
103
- })
104
- })
105
-
106
- describe('敏感词检测', () => {
107
- it('应该检测出敏感词', () => {
108
- const words = ['测试', '敏感']
109
- const regex = createSensitiveWordRegex(words)
110
-
111
- const text = '这是一个测试敏感词的文本'
112
- const matches = text.match(regex)
113
-
114
- expect(matches).not.toBeNull()
115
- expect(matches?.length).toBe(2)
116
- expect(matches).toContain('测试')
117
- expect(matches).toContain('敏感')
118
- })
119
-
120
- it('应该去重检测结果', () => {
121
- const words = ['测试']
122
- const regex = createSensitiveWordRegex(words)
123
-
124
- const text = '测试 测试 测试'
125
- const matches = text.match(regex)
126
- const unique = [...new Set(matches || [])]
127
-
128
- expect(unique.length).toBe(1)
129
- })
130
- })
131
-
132
- describe('敏感词替换', () => {
133
- it('应该替换敏感词为指定字符', () => {
134
- const words = ['敏感词']
135
- const regex = createSensitiveWordRegex(words)
136
-
137
- const text = '这是一个敏感词测试'
138
- const result = text.replace(regex, (match) => '*'.repeat(match.length))
139
-
140
- expect(result).toBe('这是一个***测试')
141
- })
142
-
143
- it('应该替换所有匹配的敏感词', () => {
144
- const words = ['测试', '敏感']
145
- const regex = createSensitiveWordRegex(words)
146
-
147
- const text = '测试敏感测试敏感'
148
- const result = text.replace(regex, (match) => '*'.repeat(match.length))
149
-
150
- // 文本共8个字符(每个中文字符算1个):"测试"(2) + "敏感"(2) + "测试"(2) + "敏感"(2) = 8
151
- expect(result).toBe('********')
152
- })
153
- })
154
-
155
- describe('谐音词和变体词过滤', () => {
156
- it('应该检测拼音缩写', () => {
157
- const words = ['GCD', 'FLG', 'CNM']
158
- const regex = createSensitiveWordRegex(words)
159
-
160
- expect('这是GCD的东西'.match(regex)).toBeTruthy()
161
- expect('flg是邪教'.match(regex)).toBeTruthy()
162
- expect('cnm骂人'.match(regex)).toBeTruthy()
163
- })
164
-
165
- it('应该检测谐音变体', () => {
166
- const words = ['共惨党', '政腐', '尼玛']
167
- const regex = createSensitiveWordRegex(words)
168
-
169
- expect('共惨党说法'.match(regex)).toBeTruthy()
170
- expect('政腐机关'.match(regex)).toBeTruthy()
171
- expect('尼玛真是'.match(regex)).toBeTruthy()
172
- })
173
-
174
- it('应该检测符号分隔词', () => {
175
- const words = ['法_轮_功', '六_四', '毒_品']
176
- const regex = createSensitiveWordRegex(words)
177
-
178
- expect('法_轮_功邪教'.match(regex)).toBeTruthy()
179
- expect('六_四事件'.match(regex)).toBeTruthy()
180
- expect('毒_品交易'.match(regex)).toBeTruthy()
181
- })
182
-
183
- it('应该替换谐音词', () => {
184
- const words = ['sb', 'cao', 'fuck']
185
- const regex = createSensitiveWordRegex(words)
186
-
187
- const text = '你个sb,去cao,fuck off'
188
- const result = text.replace(regex, (match) => '*'.repeat(match.length))
189
-
190
- expect(result).toContain('**')
191
- expect(result).toContain('***')
192
- expect(result).toContain('****')
193
- expect(result).not.toContain('sb')
194
- expect(result).not.toContain('cao')
195
- expect(result).not.toContain('fuck')
196
- })
197
- })
198
- })
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "outDir": "./lib",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "jsx": "react-jsx",
15
- "jsxImportSource": "zhin.js",
16
- "allowSyntheticDefaultImports": true,
17
- "experimentalDecorators": true,
18
- "emitDecoratorMetadata": true,
19
- "declaration": true,
20
- "declarationMap": true,
21
- "sourceMap": true
22
- },
23
- "include": ["src/**/*"],
24
- "exclude": ["lib", "node_modules", "client", "dist"]
25
- }
@@ -1 +0,0 @@
1
- {"root":["./src/index.ts","./src/sensitive-words.ts"],"version":"5.9.3"}