@q78kg/koishi-plugin-text-censor 1.0.4-beta.1 → 1.0.4-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.js +6 -12
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -64,21 +64,15 @@ function apply(ctx, config) {
|
|
64
64
|
ctx.plugin(import_censor.default);
|
65
65
|
ctx.get("censor").intercept({
|
66
66
|
async text(attrs) {
|
67
|
-
const
|
68
|
-
const result = await filter.filter(originalText);
|
67
|
+
const result = await filter.filter(attrs.content);
|
69
68
|
if (typeof result.text !== "string")
|
70
69
|
return [];
|
71
70
|
if (config.removeWords) {
|
72
|
-
const filteredText =
|
73
|
-
|
74
|
-
(
|
75
|
-
|
76
|
-
|
77
|
-
const cleanedText = originalText.split("").filter(
|
78
|
-
(char) => !removedCharacters.includes(char)
|
79
|
-
// 过滤掉被移除的字符
|
80
|
-
).join("");
|
81
|
-
return [cleanedText.trim()];
|
71
|
+
const filteredText = words.reduce((text, word) => {
|
72
|
+
const regex = new RegExp(`\\b${word}\\b`, "gi");
|
73
|
+
return text.replace(regex, "");
|
74
|
+
}, result.text);
|
75
|
+
return [filteredText.trim()];
|
82
76
|
} else {
|
83
77
|
return [result.text];
|
84
78
|
}
|