@meteorstream/koishi-plugin-auto-reply 0.0.7 → 0.0.9

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/lib/index.d.ts CHANGED
@@ -14,10 +14,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
14
14
  address: Schema<Schemastery.ObjectS<{
15
15
  source: Schema<"本地" | "url", "本地" | "url">;
16
16
  fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
17
+ weight: Schema<number, number>;
17
18
  link: Schema<string, string>;
18
19
  }>[], Schemastery.ObjectT<{
19
20
  source: Schema<"本地" | "url", "本地" | "url">;
20
21
  fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
22
+ weight: Schema<number, number>;
21
23
  link: Schema<string, string>;
22
24
  }>[]>;
23
25
  }>[], Schemastery.ObjectT<{
@@ -27,10 +29,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
27
29
  address: Schema<Schemastery.ObjectS<{
28
30
  source: Schema<"本地" | "url", "本地" | "url">;
29
31
  fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
32
+ weight: Schema<number, number>;
30
33
  link: Schema<string, string>;
31
34
  }>[], Schemastery.ObjectT<{
32
35
  source: Schema<"本地" | "url", "本地" | "url">;
33
36
  fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
37
+ weight: Schema<number, number>;
34
38
  link: Schema<string, string>;
35
39
  }>[]>;
36
40
  }>[]>;
@@ -46,10 +50,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
46
50
  address: Schema<Schemastery.ObjectS<{
47
51
  source: Schema<"本地" | "url", "本地" | "url">;
48
52
  fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
53
+ weight: Schema<number, number>;
49
54
  link: Schema<string, string>;
50
55
  }>[], Schemastery.ObjectT<{
51
56
  source: Schema<"本地" | "url", "本地" | "url">;
52
57
  fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
58
+ weight: Schema<number, number>;
53
59
  link: Schema<string, string>;
54
60
  }>[]>;
55
61
  }>[];
package/lib/index.js CHANGED
@@ -43,8 +43,8 @@ var name = "auto-reply";
43
43
  var Config = import_koishi.Schema.intersect([
44
44
  import_koishi.Schema.object({
45
45
  debugger: import_koishi.Schema.boolean().default(false).description("日志调试模式"),
46
- sendErrMsg: import_koishi.Schema.boolean().default(false).description("相应失败时是否发送文字提示"),
47
- errMsg: import_koishi.Schema.string().default("发生错误").description("相应失败时发送的文字提示")
46
+ sendErrMsg: import_koishi.Schema.boolean().default(false).description("响应失败时是否发送文字提示"),
47
+ errMsg: import_koishi.Schema.string().default("发生错误").description("响应失败时发送的文字提示")
48
48
  }).description("开发者选项"),
49
49
  import_koishi.Schema.object({
50
50
  replyList: import_koishi.Schema.array(import_koishi.Schema.object({
@@ -54,6 +54,7 @@ var Config = import_koishi.Schema.intersect([
54
54
  address: import_koishi.Schema.array(import_koishi.Schema.object({
55
55
  source: import_koishi.Schema.union(["本地", "url"]).description("来源").default("url"),
56
56
  fileType: import_koishi.Schema.union(["文本", "图片", "音频", "视频"]).description("文件类型").default("文本"),
57
+ weight: import_koishi.Schema.number().description("权重(仅随机生效)").role("slider").min(1).max(100).step(1).default(1),
57
58
  link: import_koishi.Schema.string().description("路径")
58
59
  })).description("响应情况").role("table")
59
60
  })).description("响应指令").role("table")
@@ -67,22 +68,31 @@ function apply(ctx, config) {
67
68
  const root = path.join(ctx.baseDir, "data", name);
68
69
  await fs.mkdir(root, { recursive: true });
69
70
  ctx.on("message", (session) => {
71
+ logInfo("收到消息:", JSON.stringify(session));
70
72
  const matchList = config.replyList.filter((item) => {
71
73
  return item.type == "完全匹配" ? session.content == item.command : session.content.indexOf(item.command) > -1;
72
74
  });
73
75
  if (matchList && matchList.length > 0) {
74
76
  let match = matchList[0];
75
- let link = "";
76
77
  let index = 0;
77
78
  if (match.mode == "随机") {
78
- index = Math.floor(Math.random() * match.address.length);
79
+ const totalWeight = match.address.reduce((sum, item) => sum + (item.weight ? item.weight : 1), 0);
80
+ const random = Math.random() * totalWeight;
81
+ let currentWeight = 0;
82
+ for (let i = 0; i < match.address.length; i++) {
83
+ currentWeight += match.address[i].weight ? match.address[i].weight : 1;
84
+ if (random < currentWeight) {
85
+ index = i;
86
+ break;
87
+ }
88
+ }
79
89
  } else {
80
90
  lastUserIndexMap.set(match.command, lastUserIndexMap.get(match.command) ? lastUserIndexMap.get(match.command) : 0);
81
91
  index = lastUserIndexMap.get(match.command);
82
92
  index = ++index > match.address.length - 1 ? 0 : index;
83
93
  lastUserIndexMap.set(match.command, index);
84
94
  }
85
- link = match.address[index].source == "本地" ? (0, import_url.pathToFileURL)(path.join(root, match.address[index].link)).href : match.address[index].link;
95
+ const link = match.address[index].source == "本地" ? (0, import_url.pathToFileURL)(path.join(root, match.address[index].link)).href : match.address[index].link;
86
96
  logInfo(`匹配到指令[${match.command}]${match.mode}[${index}]:${link}`);
87
97
  try {
88
98
  switch (match.address[index].fileType) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meteorstream/koishi-plugin-auto-reply",
3
3
  "description": "meteorstream自用",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [