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