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

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.
Files changed (2) hide show
  1. package/lib/index.js +27 -13
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
8
  var __export = (target, all) => {
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -27,7 +37,8 @@ __export(src_exports, {
27
37
  module.exports = __toCommonJS(src_exports);
28
38
  var import_koishi = require("koishi");
29
39
  var import_url = require("url");
30
- var import_path = require("path");
40
+ var fs = __toESM(require("fs/promises"));
41
+ var path = __toESM(require("path"));
31
42
  var name = "auto-reply";
32
43
  var Config = import_koishi.Schema.intersect([
33
44
  import_koishi.Schema.object({
@@ -46,12 +57,14 @@ var Config = import_koishi.Schema.intersect([
46
57
  debugger: import_koishi.Schema.boolean().default(false).description("日志调试模式")
47
58
  }).description("开发者选项")
48
59
  ]);
60
+ var lastUserIndexMap = /* @__PURE__ */ new Map();
49
61
  function apply(ctx, config) {
50
62
  ctx.on("ready", async () => {
51
63
  const logger = ctx.logger("auto-reply");
52
- const lastUserIndexMap = /* @__PURE__ */ new Map();
64
+ const root = path.join(ctx.baseDir, "data", name);
65
+ await fs.mkdir(root, { recursive: true });
53
66
  ctx.on("message", (session) => {
54
- logInfo((0, import_url.pathToFileURL)((0, import_path.resolve)(__dirname, "logo.png")).href);
67
+ logInfo(root);
55
68
  const matchList = config.replyList.filter((item) => {
56
69
  return item.type == "完全匹配" ? session.content == item.command : session.content.indexOf(item.command) > -1;
57
70
  });
@@ -59,18 +72,19 @@ function apply(ctx, config) {
59
72
  logInfo("没有匹配到指令");
60
73
  return;
61
74
  }
75
+ let link = "";
76
+ let index = 0;
62
77
  if (matchList[0].mode == "随机") {
63
- const randomIndex = Math.floor(Math.random() * matchList[0].address.length);
64
- logger.info("匹配到指令", matchList[0].command, ",随机[" + randomIndex + "]:", matchList[0].address[randomIndex].link);
65
- session.send(import_koishi.h.audio(matchList[0].address[randomIndex].link));
66
- return;
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);
67
84
  }
68
- lastUserIndexMap.set(matchList[0].command, lastUserIndexMap.get(matchList[0].command) ? lastUserIndexMap.get(matchList[0].command) : 0);
69
- let index = lastUserIndexMap.get(matchList[0].command);
70
- index = index > matchList.length - 1 ? 0 : index;
71
- logInfo(`匹配到指令[${matchList[0].command}]顺序[${index}]:${matchList[0].address[index].link}`);
72
- session.send(import_koishi.h.audio(matchList[0].address[index].link));
73
- lastUserIndexMap.set(matchList[0].command, ++index);
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));
74
88
  });
75
89
  function logInfo(...args) {
76
90
  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.3",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [