@q78kg/koishi-plugin-text-censor 1.0.4-beta.5 → 1.0.4-beta.7

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Context, Schema } from 'koishi';
2
2
  export declare const name = "text-censor";
3
3
  export interface Config {
4
- textDatabase: [string, string][];
4
+ textDatabase: [string][];
5
5
  removeWords: boolean;
6
6
  transformToUpper: boolean;
7
7
  }
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/Censor.txt")
49
+ import_koishi.Schema.string().default("data/text-censor/censor.txt")
50
50
  ])
51
- ).description("敏感词库的文件路径。").default([["", "data/Censor.txt"]])
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),
@@ -60,11 +60,13 @@ var Config = import_koishi.Schema.intersect([
60
60
  ]);
61
61
  function apply(ctx, config) {
62
62
  let words = [];
63
- for (const [_, file] of config.textDatabase) {
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(`dictionary file not found: ${filePath}`);
67
- continue;
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 MintOptions = {
81
+ const mintOptions = {
80
82
  transform: config.transformToUpper ? "capital" : "none"
81
83
  // 这里我们将值设置为可能的类型
82
84
  };
83
- const filter = new import_mint_filter.default(words, MintOptions);
85
+ const filter = new import_mint_filter.default(words, mintOptions);
84
86
  ctx.plugin(import_censor.default);
85
- ctx.get("Censor").intercept({
87
+ ctx.get("censor").intercept({
86
88
  async text(attrs) {
87
89
  const originalText = attrs.content;
88
90
  const result = await filter.filter(originalText);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@q78kg/koishi-plugin-text-censor",
3
3
  "description": "A text censor provider for Koishi",
4
- "version": "1.0.4-beta.5",
4
+ "version": "1.0.4-beta.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [