@q78kg/koishi-plugin-text-censor 1.0.4-beta.5 → 1.0.4-beta.6
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.js +9 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -46,9 +46,9 @@ var Config = import_koishi.Schema.intersect([
|
|
46
46
|
textDatabase: import_koishi.Schema.array(
|
47
47
|
import_koishi.Schema.tuple([
|
48
48
|
import_koishi.Schema.string().role("text"),
|
49
|
-
import_koishi.Schema.string().default("data/
|
49
|
+
import_koishi.Schema.string().default("data/text-censor/censor.txt")
|
50
50
|
])
|
51
|
-
).description("敏感词库的文件路径。").default([["", "data/
|
51
|
+
).description("敏感词库的文件路径。").default([["", "data/text-censor/censor.txt"]])
|
52
52
|
}),
|
53
53
|
import_koishi.Schema.object({
|
54
54
|
removeWords: import_koishi.Schema.boolean().description("是否直接删除敏感词。").default(false),
|
@@ -63,8 +63,10 @@ function apply(ctx, config) {
|
|
63
63
|
for (const [_, file] of config.textDatabase) {
|
64
64
|
const filePath = (0, import_node_path.resolve)(ctx.baseDir, file);
|
65
65
|
if (!(0, import_node_fs.existsSync)(filePath)) {
|
66
|
-
ctx.logger.warn(
|
67
|
-
|
66
|
+
ctx.logger.warn(
|
67
|
+
`dictionary file not found: ${filePath}, creating a new one.`
|
68
|
+
);
|
69
|
+
(0, import_node_fs.writeFileSync)(filePath, "");
|
68
70
|
}
|
69
71
|
const source = (0, import_node_fs.readFileSync)(filePath, "utf8");
|
70
72
|
const fileWords = source.split("\n").map((word) => word.trim()).filter(
|
@@ -76,13 +78,13 @@ function apply(ctx, config) {
|
|
76
78
|
ctx.logger.warn("no sensitive words found");
|
77
79
|
return;
|
78
80
|
}
|
79
|
-
const
|
81
|
+
const mintOptions = {
|
80
82
|
transform: config.transformToUpper ? "capital" : "none"
|
81
83
|
// 这里我们将值设置为可能的类型
|
82
84
|
};
|
83
|
-
const filter = new import_mint_filter.default(words,
|
85
|
+
const filter = new import_mint_filter.default(words, mintOptions);
|
84
86
|
ctx.plugin(import_censor.default);
|
85
|
-
ctx.get("
|
87
|
+
ctx.get("censor").intercept({
|
86
88
|
async text(attrs) {
|
87
89
|
const originalText = attrs.content;
|
88
90
|
const result = await filter.filter(originalText);
|