@meteorstream/koishi-plugin-auto-reply 0.0.4 → 0.0.6

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
@@ -11,9 +11,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
11
11
  mode: Schema<"顺序" | "随机", "顺序" | "随机">;
12
12
  address: Schema<Schemastery.ObjectS<{
13
13
  source: Schema<"本地" | "url", "本地" | "url">;
14
+ fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
14
15
  link: Schema<string, string>;
15
16
  }>[], Schemastery.ObjectT<{
16
17
  source: Schema<"本地" | "url", "本地" | "url">;
18
+ fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
17
19
  link: Schema<string, string>;
18
20
  }>[]>;
19
21
  }>[], Schemastery.ObjectT<{
@@ -22,9 +24,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
22
24
  mode: Schema<"顺序" | "随机", "顺序" | "随机">;
23
25
  address: Schema<Schemastery.ObjectS<{
24
26
  source: Schema<"本地" | "url", "本地" | "url">;
27
+ fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
25
28
  link: Schema<string, string>;
26
29
  }>[], Schemastery.ObjectT<{
27
30
  source: Schema<"本地" | "url", "本地" | "url">;
31
+ fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
28
32
  link: Schema<string, string>;
29
33
  }>[]>;
30
34
  }>[]>;
@@ -37,9 +41,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
37
41
  mode: Schema<"顺序" | "随机", "顺序" | "随机">;
38
42
  address: Schema<Schemastery.ObjectS<{
39
43
  source: Schema<"本地" | "url", "本地" | "url">;
44
+ fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
40
45
  link: Schema<string, string>;
41
46
  }>[], Schemastery.ObjectT<{
42
47
  source: Schema<"本地" | "url", "本地" | "url">;
48
+ fileType: Schema<"文本" | "图片" | "音频" | "视频", "文本" | "图片" | "音频" | "视频">;
43
49
  link: Schema<string, string>;
44
50
  }>[]>;
45
51
  }>[];
package/lib/index.js CHANGED
@@ -48,6 +48,7 @@ var Config = import_koishi.Schema.intersect([
48
48
  mode: import_koishi.Schema.union(["顺序", "随机"]).description("响应模式").default("随机"),
49
49
  address: import_koishi.Schema.array(import_koishi.Schema.object({
50
50
  source: import_koishi.Schema.union(["本地", "url"]).description("来源").default("url"),
51
+ fileType: import_koishi.Schema.union(["文本", "图片", "音频", "视频"]).description("文件类型").default("文本"),
51
52
  link: import_koishi.Schema.string().description("路径")
52
53
  })).description("响应情况").role("table")
53
54
  })).description("响应指令").role("table")
@@ -64,27 +65,40 @@ function apply(ctx, config) {
64
65
  const root = path.join(ctx.baseDir, "data", name);
65
66
  await fs.mkdir(root, { recursive: true });
66
67
  ctx.on("message", (session) => {
67
- logInfo(root);
68
68
  const matchList = config.replyList.filter((item) => {
69
69
  return item.type == "完全匹配" ? session.content == item.command : session.content.indexOf(item.command) > -1;
70
70
  });
71
- if (!matchList || matchList.length == 0) {
72
- logInfo("没有匹配到指令");
73
- return;
71
+ if (matchList && matchList.length > 0) {
72
+ let match = matchList[0];
73
+ let link = "";
74
+ let index = 0;
75
+ if (match.mode == "随机") {
76
+ index = Math.floor(Math.random() * match.address.length);
77
+ } else {
78
+ lastUserIndexMap.set(match.command, lastUserIndexMap.get(match.command) ? lastUserIndexMap.get(match.command) : 0);
79
+ index = lastUserIndexMap.get(match.command);
80
+ index = ++index > match.address.length - 1 ? 0 : index;
81
+ lastUserIndexMap.set(match.command, index);
82
+ }
83
+ link = match.address[index].source == "本地" ? (0, import_url.pathToFileURL)(path.join(root, match.address[index].link)).href : match.address[index].link;
84
+ logInfo(`匹配到指令[${match.command}]${match.mode}[${index}]:${link}`);
85
+ switch (match.address[index].fileType) {
86
+ case "文本":
87
+ session.send(link);
88
+ break;
89
+ case "图片":
90
+ session.send(import_koishi.h.image(link));
91
+ break;
92
+ case "视频":
93
+ session.send(import_koishi.h.video(link));
94
+ break;
95
+ case "音频":
96
+ session.send(import_koishi.h.audio(link));
97
+ break;
98
+ default:
99
+ session.send(link);
100
+ }
74
101
  }
75
- let link = "";
76
- let index = 0;
77
- if (matchList[0].mode == "随机") {
78
- index = Math.floor(Math.random() * matchList[0].address.length);
79
- } else {
80
- lastUserIndexMap.set(matchList[0].command, lastUserIndexMap.get(matchList[0].command) ? lastUserIndexMap.get(matchList[0].command) : 0);
81
- index = lastUserIndexMap.get(matchList[0].command);
82
- index = ++index > matchList[0].address.length - 1 ? 0 : index;
83
- lastUserIndexMap.set(matchList[0].command, index);
84
- }
85
- link = matchList[0].address[index].source == "本地" ? (0, import_url.pathToFileURL)(path.join(root, matchList[0].address[index].link)).href : matchList[0].address[index].link;
86
- logInfo(`匹配到指令[${matchList[0].command}]${matchList[0].mode}[${index}]:${link}`);
87
- session.send(import_koishi.h.audio(link));
88
102
  });
89
103
  function logInfo(...args) {
90
104
  if (config.debugger) {
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.4",
4
+ "version": "0.0.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -3,3 +3,10 @@
3
3
  [![npm](https://img.shields.io/npm/v/@meteorstream/koishi-plugin-auto-reply?style=flat-square)](https://www.npmjs.com/package/@meteorstream/koishi-plugin-auto-reply)
4
4
 
5
5
  meteorstream自用
6
+
7
+
8
+ 发布插件
9
+ npm run build auto-reply
10
+ npm login --registry=https://registry.npmjs.org/
11
+ cd .\external\auto-reply\
12
+ npm publish --registry=https://registry.npmjs.org/ --access=public