@zhin.js/sensitive-filter 0.0.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @zhin.js/sensitive-filter
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 960e2ee: fix: 增加敏感词过滤插件
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,236 @@
1
+ # @zhin.js/plugin-sensitive-filter
2
+
3
+ 敏感词过滤插件,用于过滤不符合中国国情的敏感内容。
4
+
5
+ ## 功能特性
6
+
7
+ - ✅ **多类别敏感词库**:政治、暴力、色情、违禁品、诈骗、违法违规等多个类别
8
+ - ✅ **智能过滤**:自动检测并替换敏感词为 `*` 字符
9
+ - ✅ **拦截模式**:可选择直接拦截包含敏感词的消息
10
+ - ✅ **日志记录**:自动记录检测到的敏感词和过滤结果
11
+ - ✅ **自定义词库**:支持添加自定义敏感词
12
+ - ✅ **灵活配置**:可按类别启用/禁用敏感词过滤
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ pnpm add @zhin.js/plugin-sensitive-filter
18
+ ```
19
+
20
+ ## 使用方法
21
+
22
+ ### 基础使用
23
+
24
+ 在配置文件中启用插件:
25
+
26
+ ```typescript
27
+ // zhin.config.ts
28
+ import { defineConfig } from 'zhin.js'
29
+
30
+ export default defineConfig({
31
+ plugins: [
32
+ 'database', // 敏感词过滤插件依赖数据库
33
+ 'sensitive-filter'
34
+ ]
35
+ })
36
+ ```
37
+
38
+ ### 配置选项
39
+
40
+ 插件支持以下配置选项:
41
+
42
+ ```typescript
43
+ interface SensitiveFilterOptions {
44
+ /** 是否启用政治敏感词过滤(默认: true) */
45
+ political?: boolean
46
+
47
+ /** 是否启用暴力恐怖词汇过滤(默认: true) */
48
+ violence?: boolean
49
+
50
+ /** 是否启用色情低俗词汇过滤(默认: true) */
51
+ porn?: boolean
52
+
53
+ /** 是否启用违禁品词汇过滤(默认: true) */
54
+ prohibited?: boolean
55
+
56
+ /** 是否启用诈骗相关词汇过滤(默认: true) */
57
+ fraud?: boolean
58
+
59
+ /** 是否启用其他违法违规词汇过滤(默认: true) */
60
+ illegal?: boolean
61
+
62
+ /** 自定义敏感词列表 */
63
+ custom?: string[]
64
+
65
+ /** 替换字符(默认: "*") */
66
+ replacement?: string
67
+
68
+ /** 是否直接拦截包含敏感词的消息(默认: false) */
69
+ block?: boolean
70
+ }
71
+ ```
72
+
73
+ ### 自定义配置
74
+
75
+ 修改 `src/index.ts` 中的配置:
76
+
77
+ ```typescript
78
+ const config: SensitiveFilterOptions = {
79
+ political: true,
80
+ violence: true,
81
+ porn: true,
82
+ prohibited: false, // 禁用违禁品词汇过滤
83
+ fraud: true,
84
+ illegal: true,
85
+ custom: ['自定义敏感词1', '自定义敏感词2'],
86
+ replacement: "█", // 使用不同的替换字符
87
+ block: true, // 直接拦截包含敏感词的消息
88
+ }
89
+ ```
90
+
91
+ ## 工作原理
92
+
93
+ ### 过滤流程
94
+
95
+ 1. **拦截发送消息**:使用 `plugin.beforeSend()` 钩子拦截所有即将发送的消息
96
+ 2. **敏感词检测**:使用正则表达式匹配敏感词
97
+ 3. **内容过滤**:
98
+ - **替换模式**(默认):将敏感词替换为 `*` 字符
99
+ - **拦截模式**:直接拦截消息并返回警告
100
+ 4. **日志记录**:将检测结果保存到数据库
101
+
102
+ ### 示例效果
103
+
104
+ **替换模式**:
105
+ ```
106
+ 输入: "这是一条包含敏感词的消息"
107
+ 输出: "这是一条包含***的消息"
108
+ ```
109
+
110
+ **拦截模式**:
111
+ ```
112
+ 输入: "这是一条包含敏感词的消息"
113
+ 输出: "⚠️ 消息包含敏感词,已被拦截。检测到: 敏感词"
114
+ ```
115
+
116
+ ## 敏感词分类
117
+
118
+ 插件包含以下敏感词分类:
119
+
120
+ ### 1. 政治敏感词
121
+ 涉及政治敏感话题的词汇,如:法轮功、达赖、台独、藏独等
122
+
123
+ ### 2. 暴力恐怖词汇
124
+ 涉及暴力、恐怖主义的词汇,如:恐怖主义、爆炸、炸弹等
125
+
126
+ ### 3. 色情低俗词汇
127
+ 涉及色情、低俗内容的词汇,如:色情、淫秽、裸体等
128
+
129
+ ### 4. 违禁品词汇
130
+ 涉及毒品、赌博、枪支等违禁品的词汇
131
+
132
+ ### 5. 诈骗相关词汇
133
+ 涉及网络诈骗、传销等欺诈行为的词汇
134
+
135
+ ### 6. 其他违法违规词汇
136
+ 涉及翻墙、假证、作弊等违法违规行为的词汇
137
+
138
+ ## 数据库表结构
139
+
140
+ 插件会自动创建 `sensitive_logs` 表记录过滤日志:
141
+
142
+ ```typescript
143
+ {
144
+ id: number // 自增主键
145
+ content: string // 原始内容
146
+ filtered_content: string // 过滤后内容
147
+ detected_words: string[] // 检测到的敏感词列表
148
+ user_id: string // 用户ID
149
+ adapter: string // 适配器名称
150
+ bot: string // 机器人名称
151
+ timestamp: Date // 时间戳
152
+ }
153
+ ```
154
+
155
+ ## 注意事项
156
+
157
+ 1. **依赖数据库**:本插件需要数据库支持来记录日志,请确保已启用 `database` 插件
158
+ 2. **性能考虑**:敏感词库较大时可能影响性能,建议按需启用分类
159
+ 3. **误判问题**:简单的关键词匹配可能存在误判,建议根据实际情况调整词库
160
+ 4. **合规使用**:请根据当地法律法规和平台规则合理使用本插件
161
+
162
+ ## 最佳实践
163
+
164
+ ### 1. 按场景启用分类
165
+
166
+ ```typescript
167
+ // 公开群聊:启用所有过滤
168
+ const publicGroupConfig = {
169
+ political: true,
170
+ violence: true,
171
+ porn: true,
172
+ prohibited: true,
173
+ fraud: true,
174
+ illegal: true,
175
+ }
176
+
177
+ // 私聊:只启用必要过滤
178
+ const privateConfig = {
179
+ political: false,
180
+ violence: false,
181
+ porn: true,
182
+ prohibited: true,
183
+ fraud: true,
184
+ illegal: false,
185
+ }
186
+ ```
187
+
188
+ ### 2. 自定义词库管理
189
+
190
+ ```typescript
191
+ // 添加行业特定敏感词
192
+ const config = {
193
+ custom: [
194
+ '公司机密信息',
195
+ '内部文档',
196
+ '未公开产品',
197
+ ]
198
+ }
199
+ ```
200
+
201
+ ### 3. 日志分析
202
+
203
+ 定期查询日志分析敏感词趋势:
204
+
205
+ ```typescript
206
+ import { useContext } from 'zhin.js'
207
+
208
+ useContext('database', async (db) => {
209
+ const logs = db.model('sensitive_logs')
210
+
211
+ // 查询最近检测到的敏感词
212
+ const recent = await logs.select()
213
+ .orderBy('timestamp', 'desc')
214
+ .limit(10)
215
+
216
+ console.log('最近检测到的敏感词:', recent)
217
+ })
218
+ ```
219
+
220
+ ## 开发
221
+
222
+ ```bash
223
+ # 构建
224
+ pnpm build
225
+
226
+ # 开发模式
227
+ pnpm dev
228
+ ```
229
+
230
+ ## 许可证
231
+
232
+ MIT
233
+
234
+ ---
235
+
236
+ **警告**:本插件仅用于内容过滤和安全防护,请遵守相关法律法规,不要用于非法用途。
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/lib/index.js ADDED
@@ -0,0 +1,137 @@
1
+ import { usePlugin, useLogger, segment, defineSchema, Schema, } from "zhin.js";
2
+ import { getEnabledWords, createSensitiveWordRegex, } from "./sensitive-words.js";
3
+ const logger = useLogger();
4
+ const plugin = usePlugin();
5
+ const schema = defineSchema(Schema.object({
6
+ political: Schema.boolean("political")
7
+ .default(true)
8
+ .description("启用政治类敏感词过滤"),
9
+ violence: Schema.boolean("violence")
10
+ .default(true)
11
+ .description("启用暴力类敏感词过滤"),
12
+ porn: Schema.boolean("porn")
13
+ .default(true)
14
+ .description("启用色情类敏感词过滤"),
15
+ prohibited: Schema.boolean("prohibited")
16
+ .default(true)
17
+ .description("启用禁用类敏感词过滤"),
18
+ fraud: Schema.boolean("fraud")
19
+ .default(true)
20
+ .description("启用诈骗类敏感词过滤"),
21
+ illegal: Schema.boolean("illegal")
22
+ .default(true)
23
+ .description("启用违法类敏感词过滤"),
24
+ custom: Schema.list(Schema.string()).default([]).description("自定义敏感词"),
25
+ replacement: Schema.string("replacement")
26
+ .default("*")
27
+ .description("替换字符"),
28
+ block: Schema.boolean("block").default(false).description("是否拦截消息"),
29
+ }).default({
30
+ political: true,
31
+ violence: true,
32
+ porn: true,
33
+ prohibited: true,
34
+ fraud: true,
35
+ illegal: true,
36
+ custom: [],
37
+ replacement: "*",
38
+ block: false,
39
+ }));
40
+ // 插件配置
41
+ const config = schema(plugin.config, "sensitive-filter");
42
+ /**
43
+ * 检测文本中的敏感词
44
+ */
45
+ function detectSensitiveWords(text, regex) {
46
+ const matches = text.match(regex);
47
+ return matches ? [...new Set(matches)] : [];
48
+ }
49
+ /**
50
+ * 替换文本中的敏感词
51
+ */
52
+ function replaceSensitiveWords(text, regex, replacement) {
53
+ return text.replace(regex, (match) => replacement.repeat(match.length));
54
+ }
55
+ /**
56
+ * 过滤消息内容
57
+ */
58
+ function filterContent(content, regex, replacement) {
59
+ let detected = [];
60
+ // 处理字符串内容
61
+ if (typeof content === "string") {
62
+ detected = detectSensitiveWords(content, regex);
63
+ const filtered = replaceSensitiveWords(content, regex, replacement);
64
+ return { filtered, detected };
65
+ }
66
+ // 处理消息段数组
67
+ if (Array.isArray(content)) {
68
+ const filteredContent = [];
69
+ for (const element of content) {
70
+ if (typeof element === "string") {
71
+ const words = detectSensitiveWords(element, regex);
72
+ detected.push(...words);
73
+ filteredContent.push(replaceSensitiveWords(element, regex, replacement));
74
+ }
75
+ else if (element && typeof element === "object") {
76
+ // 处理消息段对象
77
+ if (element.type === "text" && element.data?.text) {
78
+ const words = detectSensitiveWords(element.data.text, regex);
79
+ detected.push(...words);
80
+ filteredContent.push({
81
+ ...element,
82
+ data: {
83
+ ...element.data,
84
+ text: replaceSensitiveWords(element.data.text, regex, replacement),
85
+ },
86
+ });
87
+ }
88
+ else {
89
+ // 其他类型的消息段不处理
90
+ filteredContent.push(element);
91
+ }
92
+ }
93
+ else {
94
+ filteredContent.push(element);
95
+ }
96
+ }
97
+ return { filtered: filteredContent, detected: [...new Set(detected)] };
98
+ }
99
+ return { filtered: content, detected: [] };
100
+ }
101
+ // 初始化敏感词过滤
102
+ const sensitiveWords = getEnabledWords(config);
103
+ const sensitiveRegex = createSensitiveWordRegex(sensitiveWords);
104
+ plugin.beforeSend(async (options) => {
105
+ const { content } = options;
106
+ // 如果内容为空,直接返回
107
+ if (!content)
108
+ return options;
109
+ // 转换内容为字符串用于检测
110
+ const contentStr = typeof content === "string" ? content : segment.toString(content);
111
+ // 检测敏感词
112
+ const detectedWords = detectSensitiveWords(contentStr, sensitiveRegex);
113
+ // 如果没有检测到敏感词,直接返回
114
+ if (detectedWords.length === 0) {
115
+ return options;
116
+ }
117
+ logger.warn(`检测到敏感词: ${detectedWords.join(", ")}`);
118
+ // 如果配置为拦截模式,返回警告消息
119
+ if (config.block) {
120
+ return {
121
+ ...options,
122
+ content: `⚠️ 消息包含敏感词,已被拦截。`,
123
+ };
124
+ }
125
+ // 替换模式:过滤敏感词
126
+ const { filtered, detected } = filterContent(content, sensitiveRegex, config.replacement || "*");
127
+ const filteredStr = typeof filtered === "string"
128
+ ? filtered
129
+ : segment.toString(filtered);
130
+ return {
131
+ ...options,
132
+ content: filtered,
133
+ };
134
+ });
135
+ logger.info("敏感词过滤功能已启用");
136
+ logger.info(`敏感词过滤插件已加载,共 ${sensitiveWords.length} 个敏感词`);
137
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,SAAS,EAGT,OAAO,EACP,YAAY,EACZ,MAAM,GACP,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,eAAe,EACf,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,MAAM,GAAG,YAAY,CACzB,MAAM,CAAC,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;SACnC,OAAO,CAAC,IAAI,CAAC;SACb,WAAW,CAAC,YAAY,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;SACjC,OAAO,CAAC,IAAI,CAAC;SACb,WAAW,CAAC,YAAY,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SACzB,OAAO,CAAC,IAAI,CAAC;SACb,WAAW,CAAC,YAAY,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC;SACrC,OAAO,CAAC,IAA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AC,UAAU,EAAE,cAAc,CAAC,CAAC;IAEvE,kBAAkB;IAClB,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,WAAW,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEnD,mBAAmB;IACnB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO;YACL,GAAG,OAAO;YACV,OAAO,EAAE,kBAAkB;SAC5B,CAAC;IACJ,CAAC;IAED,aAAa;IACb,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,aAAa,CAC1C,OAAO,EACP,cAAc,EACd,MAAM,CAAC,WAAW,IAAI,GAAG,CAC1B,CAAC;IAEF,MAAM,WAAW,GACf,OAAO,QAAQ,KAAK,QAAQ;QAC1B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;IACxC,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,QAAe;KACzB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5B,MAAM,CAAC,IAAI,CAAC,gBAAgB,cAAc,CAAC,MAAM,OAAO,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 敏感词库
3
+ * 包含政治、暴力、色情、违禁品等敏感词汇
4
+ */
5
+ export declare const politicalWords: string[];
6
+ export declare const violenceWords: string[];
7
+ export declare const pornWords: string[];
8
+ export declare const prohibitedWords: string[];
9
+ export declare const fraudWords: string[];
10
+ export declare const illegalWords: string[];
11
+ export declare const homophoneWords: string[];
12
+ export declare const allSensitiveWords: string[];
13
+ /**
14
+ * 创建敏感词正则表达式
15
+ */
16
+ export declare function createSensitiveWordRegex(words: string[]): RegExp;
17
+ /**
18
+ * 敏感词检测选项
19
+ */
20
+ export interface SensitiveFilterOptions {
21
+ /** 是否启用政治敏感词过滤 */
22
+ political?: boolean;
23
+ /** 是否启用暴力恐怖词汇过滤 */
24
+ violence?: boolean;
25
+ /** 是否启用色情低俗词汇过滤 */
26
+ porn?: boolean;
27
+ /** 是否启用违禁品词汇过滤 */
28
+ prohibited?: boolean;
29
+ /** 是否启用诈骗相关词汇过滤 */
30
+ fraud?: boolean;
31
+ /** 是否启用其他违法违规词汇过滤 */
32
+ illegal?: boolean;
33
+ /** 是否启用谐音词、变体词过滤 */
34
+ homophone?: boolean;
35
+ /** 自定义敏感词列表 */
36
+ custom?: string[];
37
+ /** 替换字符,默认为 * */
38
+ replacement?: string;
39
+ /** 是否直接拦截包含敏感词的消息 */
40
+ block?: boolean;
41
+ }
42
+ /**
43
+ * 获取启用的敏感词列表
44
+ */
45
+ export declare function getEnabledWords(options: SensitiveFilterOptions): string[];
46
+ //# sourceMappingURL=sensitive-words.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sensitive-words.d.ts","sourceRoot":"","sources":["../src/sensitive-words.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,cAAc,UA4F1B,CAAC;AAGF,eAAO,MAAM,aAAa,UAmFzB,CAAC;AAGF,eAAO,MAAM,SAAS,UAkGrB,CAAC;AAGF,eAAO,MAAM,eAAe,UA4H3B,CAAC;AAGF,eAAO,MAAM,UAAU,UAyFtB,CAAC;AAGF,eAAO,MAAM,YAAY,UAqHxB,CAAC;AAGF,eAAO,MAAM,cAAc,UAkY1B,CAAC;AAGF,eAAO,MAAM,iBAAiB,UAQ7B,CAAC;AAEF;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAQhE;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kBAAkB;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mBAAmB;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,kBAAkB;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mBAAmB;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qBAAqB;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oBAAoB;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,iBAAiB;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,EAAE,CAazE"}