node-karin 1.11.2 → 1.11.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.11.4](https://github.com/KarinJS/Karin/compare/core-v1.11.3...core-v1.11.4) (2025-10-08)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * use ID generator API for unique incremental IDs in input adapter ([#549](https://github.com/KarinJS/Karin/issues/549)) ([a373a71](https://github.com/KarinJS/Karin/commit/a373a711899682aa84ed417d1564ab6321d69396))
9
+
10
+ ## [1.11.3](https://github.com/KarinJS/Karin/compare/core-v1.11.2...core-v1.11.3) (2025-10-07)
11
+
12
+
13
+ ### 🐛 Bug Fixes
14
+
15
+ * correct Redis mock SET method options handling and type checking ([#546](https://github.com/KarinJS/Karin/issues/546)) ([fb6a999](https://github.com/KarinJS/Karin/commit/fb6a99957974932d7222eb0be1510906483d4483))
16
+
3
17
  ## [1.11.2](https://github.com/KarinJS/Karin/compare/core-v1.11.1...core-v1.11.2) (2025-10-07)
4
18
 
5
19
 
package/dist/index.d.ts CHANGED
@@ -9513,6 +9513,22 @@ declare const isNumber: (num: unknown, defaultValue?: number) => number;
9513
9513
  * isNumberInArray(['1', '2', '3'], 0) // 返回 0
9514
9514
  */
9515
9515
  declare const isNumberInArray: <T = number>(arr: unknown[], defaultValue?: number) => T;
9516
+ /**
9517
+ * 创建一个自增ID生成器
9518
+ * @description 返回一个函数,每次调用时返回一个递增的唯一ID
9519
+ * @param start 起始值,默认为 0
9520
+ * @returns 返回一个函数,调用时返回下一个ID
9521
+ * @example
9522
+ * const getId = createIdGenerator()
9523
+ * getId() // 返回 1
9524
+ * getId() // 返回 2
9525
+ * getId() // 返回 3
9526
+ *
9527
+ * const getIdFrom100 = createIdGenerator(100)
9528
+ * getIdFrom100() // 返回 101
9529
+ * getIdFrom100() // 返回 102
9530
+ */
9531
+ declare const createIdGenerator: (start?: number) => () => number;
9516
9532
 
9517
9533
  /**
9518
9534
  * 字符串工具
@@ -9716,6 +9732,7 @@ declare const index$1_axios: typeof axios;
9716
9732
  declare const index$1_base64: typeof base64;
9717
9733
  declare const index$1_buffer: typeof buffer;
9718
9734
  declare const index$1_clamp: typeof clamp;
9735
+ declare const index$1_createIdGenerator: typeof createIdGenerator;
9719
9736
  declare const index$1_createRawMessage: typeof createRawMessage;
9720
9737
  declare const index$1_diffArray: typeof diffArray;
9721
9738
  declare const index$1_diffSimpleArray: typeof diffSimpleArray;
@@ -9748,7 +9765,7 @@ declare const index$1_updateYaml: typeof updateYaml;
9748
9765
  declare const index$1_uptime: typeof uptime;
9749
9766
  declare const index$1_urlToPath: typeof urlToPath;
9750
9767
  declare namespace index$1 {
9751
- export { type index$1_AxiosFn as AxiosFn, type index$1_NpmInfo as NpmInfo, index$1_absPath as absPath, index$1_average as average, index$1_axios as axios, index$1_base64 as base64, index$1_buffer as buffer, karinToQQBot as buttonToQQBot, index$1_clamp as clamp, index$1_createRawMessage as createRawMessage, index$1_diffArray as diffArray, index$1_diffSimpleArray as diffSimpleArray, index$1_downFile as downFile, existToMkdir as exists, index$1_formatNumber as formatNumber, index$1_formatTime as formatTime, index$1_formatUnit as formatUnit, index$1_getAbsPath as getAbsPath, index$1_getGitPlugins as getGitPlugins, index$1_getNpmPlugins as getNpmPlugins, getPlugins$1 as getPlugins, index$1_getRelPath as getRelPath, index$1_isDir as isDir, index$1_isEven as isEven, index$1_isNumber as isNumber, index$1_isNumberInArray as isNumberInArray, index$1_isPlugin as isPlugin, index$1_karinToQQBot as karinToQQBot, index$1_makeForward as makeForward, index$1_makeMessage as makeMessage, createRawMessage as makeMessageLog, index$1_mergeImage as mergeImage, mkdirSync as mkdir, index$1_percentage as percentage, getPluginInfo as pkgJson, pkgRoot as pkgroot, index$1_qqbotToKarin as qqbotToKarin, index$1_random as random, readJsonSync as readJson, read as readYaml, index$1_round as round, index$1_sleep as sleep, index$1_splitPath as splitPath, index$1_strToBool as strToBool, index$1_stream as stream, index$1_updateYaml as updateYaml, index$1_uptime as uptime, index$1_urlToPath as urlToPath, writeJsonSync as writeJson, write as writeYaml };
9768
+ export { type index$1_AxiosFn as AxiosFn, type index$1_NpmInfo as NpmInfo, index$1_absPath as absPath, index$1_average as average, index$1_axios as axios, index$1_base64 as base64, index$1_buffer as buffer, karinToQQBot as buttonToQQBot, index$1_clamp as clamp, index$1_createIdGenerator as createIdGenerator, index$1_createRawMessage as createRawMessage, index$1_diffArray as diffArray, index$1_diffSimpleArray as diffSimpleArray, index$1_downFile as downFile, existToMkdir as exists, index$1_formatNumber as formatNumber, index$1_formatTime as formatTime, index$1_formatUnit as formatUnit, index$1_getAbsPath as getAbsPath, index$1_getGitPlugins as getGitPlugins, index$1_getNpmPlugins as getNpmPlugins, getPlugins$1 as getPlugins, index$1_getRelPath as getRelPath, index$1_isDir as isDir, index$1_isEven as isEven, index$1_isNumber as isNumber, index$1_isNumberInArray as isNumberInArray, index$1_isPlugin as isPlugin, index$1_karinToQQBot as karinToQQBot, index$1_makeForward as makeForward, index$1_makeMessage as makeMessage, createRawMessage as makeMessageLog, index$1_mergeImage as mergeImage, mkdirSync as mkdir, index$1_percentage as percentage, getPluginInfo as pkgJson, pkgRoot as pkgroot, index$1_qqbotToKarin as qqbotToKarin, index$1_random as random, readJsonSync as readJson, read as readYaml, index$1_round as round, index$1_sleep as sleep, index$1_splitPath as splitPath, index$1_strToBool as strToBool, index$1_stream as stream, index$1_updateYaml as updateYaml, index$1_uptime as uptime, index$1_urlToPath as urlToPath, writeJsonSync as writeJson, write as writeYaml };
9752
9769
  }
9753
9770
 
9754
9771
  /**
package/dist/index.mjs CHANGED
@@ -1637,12 +1637,12 @@ var init_yaml = __esm({
1637
1637
  logger.error("[YamlEditor] \u6307\u5B9A\u7684\u8DEF\u5F84\u4E0D\u662F\u6570\u7EC4");
1638
1638
  return false;
1639
1639
  }
1640
- const index6 = current.items.findIndex((item) => lodash3.isEqual(item.toJSON(), value));
1641
- if (index6 < 0) {
1640
+ const index5 = current.items.findIndex((item) => lodash3.isEqual(item.toJSON(), value));
1641
+ if (index5 < 0) {
1642
1642
  logger.error("[YamlEditor] \u672A\u627E\u5230\u8981\u5220\u9664\u7684\u503C");
1643
1643
  return false;
1644
1644
  }
1645
- current.items.splice(index6, 1);
1645
+ current.items.splice(index5, 1);
1646
1646
  logger.debug(`[YamlEditor] \u5DF2\u4ECE ${path36} \u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF1A${value}`);
1647
1647
  return true;
1648
1648
  } catch (error) {
@@ -1718,16 +1718,16 @@ var init_yaml = __esm({
1718
1718
  * 根据索引从根节点数组删除元素
1719
1719
  * @param index - 要删除元素的索引
1720
1720
  */
1721
- delarr(index6) {
1721
+ delarr(index5) {
1722
1722
  try {
1723
1723
  if (!(this.document.contents instanceof YAML.YAMLSeq)) {
1724
1724
  throw new Error("[YamlEditor] \u6839\u8282\u70B9\u4E0D\u662F\u6570\u7EC4");
1725
1725
  }
1726
- if (index6 < 0 || index6 >= this.document.contents.items.length) {
1726
+ if (index5 < 0 || index5 >= this.document.contents.items.length) {
1727
1727
  throw new Error("[YamlEditor] \u7D22\u5F15\u8D85\u51FA\u8303\u56F4");
1728
1728
  }
1729
- this.document.contents.items.splice(index6, 1);
1730
- logger.debug("[YamlEditor] \u5DF2\u6839\u636E\u7D22\u5F15\u4ECE\u6839\u8282\u70B9\u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF0C\u7D22\u5F15\uFF1A", index6);
1729
+ this.document.contents.items.splice(index5, 1);
1730
+ logger.debug("[YamlEditor] \u5DF2\u6839\u636E\u7D22\u5F15\u4ECE\u6839\u8282\u70B9\u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF0C\u7D22\u5F15\uFF1A", index5);
1731
1731
  return true;
1732
1732
  } catch (error) {
1733
1733
  logger.error(`[YamlEditor] \u6839\u636E\u7D22\u5F15\u5220\u9664\u6839\u8282\u70B9\u6570\u7EC4\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
@@ -1974,9 +1974,9 @@ var init_changelog = __esm({
1974
1974
  }
1975
1975
  const list2 = parseChangelog(data);
1976
1976
  const keys = Object.keys(list2);
1977
- const index6 = keys.indexOf(version2);
1978
- const start3 = reverse ? index6 - length : index6;
1979
- const end = reverse ? index6 : index6 + length;
1977
+ const index5 = keys.indexOf(version2);
1978
+ const start3 = reverse ? index5 - length : index5;
1979
+ const end = reverse ? index5 : index5 + length;
1980
1980
  const versions = keys.slice(start3, end).map((key) => list2[key] ? list2[key] : "");
1981
1981
  return versions.join("");
1982
1982
  };
@@ -2228,7 +2228,7 @@ var init_fs2 = __esm({
2228
2228
  init_fs();
2229
2229
  }
2230
2230
  });
2231
- var diffArray, diffSimpleArray, clamp, random, formatNumber, percentage, formatUnit, isEven, average, round, isNumber, isNumberInArray;
2231
+ var diffArray, diffSimpleArray, clamp, random, formatNumber, percentage, formatUnit, isEven, average, round, isNumber, isNumberInArray, createIdGenerator;
2232
2232
  var init_number = __esm({
2233
2233
  "src/utils/common/number.ts"() {
2234
2234
  diffArray = (old, data) => {
@@ -2288,6 +2288,10 @@ var init_number = __esm({
2288
2288
  }
2289
2289
  return defaultValue;
2290
2290
  };
2291
+ createIdGenerator = (start3 = 0) => {
2292
+ let id = start3;
2293
+ return () => ++id;
2294
+ };
2291
2295
  }
2292
2296
  });
2293
2297
  var TypedListeners, listeners;
@@ -10198,10 +10202,10 @@ var init_env3 = __esm({
10198
10202
  const lines = content.split("\n");
10199
10203
  const list2 = [];
10200
10204
  const obj = {};
10201
- lines.forEach((line, index6) => {
10202
- obj[index6] = line;
10205
+ lines.forEach((line, index5) => {
10206
+ obj[index5] = line;
10203
10207
  });
10204
- lines.forEach((line, index6) => {
10208
+ lines.forEach((line, index5) => {
10205
10209
  if (!line.includes("=")) return;
10206
10210
  let comment2 = "";
10207
10211
  let [key, value] = line.split("=").map((item) => item.trim());
@@ -10217,7 +10221,7 @@ var init_env3 = __esm({
10217
10221
  }
10218
10222
  }
10219
10223
  if (!comment2) {
10220
- const data = obj[index6 - 1]?.trim();
10224
+ const data = obj[index5 - 1]?.trim();
10221
10225
  if (data?.startsWith("#")) comment2 = data;
10222
10226
  }
10223
10227
  value = value?.replace(/^"|"$/g, "") || "";
@@ -10508,8 +10512,8 @@ var init_status_listener = __esm({
10508
10512
  }
10509
10513
  sysCpuInfo() {
10510
10514
  const currentTimes = os.cpus().map((cpu) => cpu.times);
10511
- const { total, active } = currentTimes.map((times, index6) => {
10512
- const prevTimes = this.cpuTimes[index6];
10515
+ const { total, active } = currentTimes.map((times, index5) => {
10516
+ const prevTimes = this.cpuTimes[index5];
10513
10517
  const totalCurrent = times.user + times.nice + times.sys + times.idle + times.irq;
10514
10518
  const totalPrev = prevTimes.user + prevTimes.nice + prevTimes.sys + prevTimes.idle + prevTimes.irq;
10515
10519
  const activeCurrent = totalCurrent - times.idle;
@@ -13009,6 +13013,7 @@ __export(common_exports, {
13009
13013
  buffer: () => buffer,
13010
13014
  buttonToQQBot: () => karinToQQBot,
13011
13015
  clamp: () => clamp,
13016
+ createIdGenerator: () => createIdGenerator,
13012
13017
  createRawMessage: () => createRawMessage,
13013
13018
  diffArray: () => diffArray,
13014
13019
  diffSimpleArray: () => diffSimpleArray,
@@ -13132,12 +13137,12 @@ var init_common = __esm({
13132
13137
  };
13133
13138
  getAbsPath = (images, root) => {
13134
13139
  const files = [];
13135
- images.forEach((image2, index6) => {
13140
+ images.forEach((image2, index5) => {
13136
13141
  if (typeof image2 !== "string") throw TypeError("\u4F20\u5165\u7684\u56FE\u7247\u53EA\u652F\u6301\u672C\u5730\u8DEF\u5F84 \u6216 \u5E26\u524D\u7F00base64://\u5B57\u7B26\u4E32");
13137
13142
  if (image2.startsWith("base64://")) {
13138
13143
  const base642 = image2.replace(/^base64:\/\//, "");
13139
13144
  const buffer2 = Buffer.from(base642, "base64");
13140
- const file3 = path4.join(root, `${index6}.png`);
13145
+ const file3 = path4.join(root, `${index5}.png`);
13141
13146
  fs5.writeFileSync(file3, buffer2);
13142
13147
  files.push(file3);
13143
13148
  return;
@@ -13155,9 +13160,9 @@ var init_common = __esm({
13155
13160
  return { width, height };
13156
13161
  };
13157
13162
  generateLayout = (dimensions, perRow, maxWidth, maxHeight) => {
13158
- const layouts = dimensions.map((_, index6) => {
13159
- const row = Math.floor(index6 / perRow);
13160
- const col = index6 % perRow;
13163
+ const layouts = dimensions.map((_, index5) => {
13164
+ const row = Math.floor(index5 / perRow);
13165
+ const col = index5 % perRow;
13161
13166
  return `${col * maxWidth}_${row * maxHeight}`;
13162
13167
  }).join("|");
13163
13168
  return layouts;
@@ -13172,11 +13177,11 @@ var init_common = __esm({
13172
13177
  const maxWidth = Math.max(...list2.map((d) => d.width));
13173
13178
  const maxHeight = Math.max(...list2.map((d) => d.height));
13174
13179
  let cmd = "";
13175
- list2.forEach((_, index6) => {
13176
- cmd += `[${index6}:v]pad=${maxWidth}:${maxHeight}:(ow-iw)/2:(oh-ih)/2[p${index6}]; `;
13180
+ list2.forEach((_, index5) => {
13181
+ cmd += `[${index5}:v]pad=${maxWidth}:${maxHeight}:(ow-iw)/2:(oh-ih)/2[p${index5}]; `;
13177
13182
  });
13178
13183
  const layouts = generateLayout(list2, perRow, maxWidth, maxHeight);
13179
- cmd += `${list2.map((_, index6) => `[p${index6}]`).join("")}xstack=inputs=${list2.length}:layout=${layouts}[out]`;
13184
+ cmd += `${list2.map((_, index5) => `[p${index5}]`).join("")}xstack=inputs=${list2.length}:layout=${layouts}[out]`;
13180
13185
  return cmd;
13181
13186
  };
13182
13187
  }
@@ -17050,9 +17055,9 @@ var init_bot = __esm({
17050
17055
  };
17051
17056
  unregisterBot = (type, idOrIndex, address) => {
17052
17057
  const findIndexAndRemove = (predicate) => {
17053
- const index6 = list.findIndex(predicate);
17054
- if (index6 !== -1) {
17055
- const [removed] = list.splice(index6, 1);
17058
+ const index5 = list.findIndex(predicate);
17059
+ if (index5 !== -1) {
17060
+ const [removed] = list.splice(index5, 1);
17056
17061
  logger.bot("info", removed.bot.selfId, `${logger.red("[service][\u5378\u8F7DBot]")} ${removed.bot.adapter.name}`);
17057
17062
  return true;
17058
17063
  }
@@ -19473,13 +19478,13 @@ var init_cache4 = __esm({
19473
19478
  logger.mark(`[render:${index4}] ${logger.green("\u6CE8\u518C\u6210\u529F")}: ${id}`);
19474
19479
  return i;
19475
19480
  };
19476
- unregisterRender = (index6) => {
19477
- const app5 = cache8.find((app6) => app6.index === index6);
19481
+ unregisterRender = (index5) => {
19482
+ const app5 = cache8.find((app6) => app6.index === index5);
19478
19483
  if (!app5) {
19479
- logger.error(`[render] \u5378\u8F7D\u5931\u8D25: \u4E0D\u5B58\u5728\u7D22\u5F15 ${index6}`);
19484
+ logger.error(`[render] \u5378\u8F7D\u5931\u8D25: \u4E0D\u5B58\u5728\u7D22\u5F15 ${index5}`);
19480
19485
  return false;
19481
19486
  }
19482
- cache8.splice(cache8.findIndex((app6) => app6.index === index6), 1);
19487
+ cache8.splice(cache8.findIndex((app6) => app6.index === index5), 1);
19483
19488
  logger.mark(`[render] ${logger.yellow("\u5378\u8F7D\u6210\u529F")}: ${app5.id}`);
19484
19489
  return true;
19485
19490
  };
@@ -19547,8 +19552,8 @@ var init_cache4 = __esm({
19547
19552
  * @param index 渲染器索引
19548
19553
  * @returns 是否卸载成功
19549
19554
  */
19550
- unapp(index6) {
19551
- return unregisterRender(index6);
19555
+ unapp(index5) {
19556
+ return unregisterRender(index5);
19552
19557
  }
19553
19558
  /**
19554
19559
  * 返回渲染器实例 未键入id返回第一个
@@ -19597,7 +19602,7 @@ var init_client = __esm({
19597
19602
  PREFIX = "[snapka-ws-clinet] ";
19598
19603
  snapkaMap = /* @__PURE__ */ new Map();
19599
19604
  createSnapkaClient = (clientOptions) => {
19600
- let index6 = -1;
19605
+ let index5 = -1;
19601
19606
  let isReconnect = true;
19602
19607
  let reconnectTimer;
19603
19608
  const { enable, url, token, reconnectTime = 5e3, heartbeatTime = 3e4, isSnapka = false } = clientOptions;
@@ -19620,7 +19625,7 @@ var init_client = __esm({
19620
19625
  const fnc2 = (isPrint = true) => {
19621
19626
  client.removeAllListeners();
19622
19627
  client?.close();
19623
- index6 > 0 && unregisterRender(index6);
19628
+ index5 > 0 && unregisterRender(index5);
19624
19629
  if (!isReconnect) {
19625
19630
  isPrint && logger.error(`${PREFIX}\u8FDE\u63A5\u5173\u95ED: ${url}`);
19626
19631
  return;
@@ -19639,7 +19644,7 @@ var init_client = __esm({
19639
19644
  setTimeout(() => {
19640
19645
  if (client.readyState !== WebSocket$1.OPEN) return;
19641
19646
  logger.info(`${PREFIX}\u8FDE\u63A5\u6210\u529F: ${url}`);
19642
- index6 = registerRender("snapka", render4);
19647
+ index5 = registerRender("snapka", render4);
19643
19648
  client.on("message", async (event) => onMessage(client, url, event, authorization));
19644
19649
  }, 3e3);
19645
19650
  });
@@ -19754,7 +19759,7 @@ var init_server = __esm({
19754
19759
  init_template();
19755
19760
  init_cache4();
19756
19761
  WebSocketPuppeteerServer = async (socket, request3) => {
19757
- let index6 = -1;
19762
+ let index5 = -1;
19758
19763
  const authorization = request3.headers["authorization"];
19759
19764
  if (!auth(authorization)) {
19760
19765
  socket.close();
@@ -19766,7 +19771,7 @@ var init_server = __esm({
19766
19771
  return sendWsScreenshotRequest(socket, options);
19767
19772
  };
19768
19773
  socket.on("close", () => {
19769
- index6 > 0 && unregisterRender(index6);
19774
+ index5 > 0 && unregisterRender(index5);
19770
19775
  socket.removeAllListeners();
19771
19776
  socket.close();
19772
19777
  });
@@ -19783,7 +19788,7 @@ var init_server = __esm({
19783
19788
  listeners.emit(key, { status, data });
19784
19789
  });
19785
19790
  const name = request3.headers["x-client-name"] || "snapka";
19786
- index6 = registerRender(name, render4);
19791
+ index5 = registerRender(name, render4);
19787
19792
  };
19788
19793
  initWebSocketPuppeteerServer = () => {
19789
19794
  listeners.on(WS_SNAPKA, (socket, request3, call2) => {
@@ -19835,14 +19840,14 @@ var init_http = __esm({
19835
19840
  };
19836
19841
  let pingTimer;
19837
19842
  let consecutiveFailures = 0;
19838
- const index6 = registerRender("snapka-http", render4);
19843
+ const index5 = registerRender("snapka-http", render4);
19839
19844
  const close = () => {
19840
19845
  if (pingTimer) {
19841
19846
  clearInterval(pingTimer);
19842
19847
  pingTimer = void 0;
19843
19848
  }
19844
19849
  snapkaMap2.delete(options.url);
19845
- unregisterRender(index6);
19850
+ unregisterRender(index5);
19846
19851
  };
19847
19852
  const startPingInterval = () => {
19848
19853
  pingTimer = setInterval(async () => {
@@ -20449,21 +20454,58 @@ var init_mock = __esm({
20449
20454
  const PXAT = Number(options.PXAT);
20450
20455
  if (!isNaN(PXAT)) expire = PXAT;
20451
20456
  this.store[key] = { type: "str" /* STR */, expire };
20457
+ this.#str[key] = value;
20452
20458
  } else if (options?.KEEPTTL) {
20453
- if (this.#str[key]) {
20459
+ if (this.#str[key] && this.store[key]) {
20454
20460
  this.#str[key] = value;
20461
+ expire = this.store[key].expire;
20455
20462
  } else {
20456
20463
  this.store[key] = { type: "str" /* STR */, expire: -1 };
20457
20464
  this.#str[key] = value;
20465
+ expire = -1;
20458
20466
  }
20459
20467
  } else if (options?.NX) {
20460
- if (!this.#str[key]) {
20468
+ if (!this.store[key] || this.checkExpire(key, false)) {
20461
20469
  this.store[key] = { type: "str" /* STR */, expire: -1 };
20462
20470
  this.#str[key] = value;
20471
+ this.#sqlite.set(key, value, "str" /* STR */, -1);
20463
20472
  }
20473
+ return "OK";
20464
20474
  } else if (options?.XX) {
20465
- if (this.#str[key]) {
20475
+ if (this.store[key]) {
20476
+ const currentExpire = this.store[key].expire;
20477
+ const oldType = this.store[key].type;
20478
+ if (oldType !== "str" /* STR */) {
20479
+ switch (oldType) {
20480
+ case "num" /* NUM */:
20481
+ delete this.#num[key];
20482
+ break;
20483
+ case "hash" /* HASH */:
20484
+ delete this.#hash[key];
20485
+ break;
20486
+ case "list" /* LIST */:
20487
+ delete this.#list[key];
20488
+ break;
20489
+ case "set" /* SET */:
20490
+ delete this.#set[key];
20491
+ break;
20492
+ case "zset" /* ZSET */:
20493
+ delete this.#zset[key];
20494
+ break;
20495
+ case "pf" /* PF */:
20496
+ delete this.#pf[key];
20497
+ break;
20498
+ case "bit" /* BIT */:
20499
+ delete this.#bit[key];
20500
+ break;
20501
+ }
20502
+ }
20503
+ this.store[key] = { type: "str" /* STR */, expire: currentExpire };
20466
20504
  this.#str[key] = value;
20505
+ this.#sqlite.set(key, value, "str" /* STR */, currentExpire);
20506
+ return "OK";
20507
+ } else {
20508
+ return null;
20467
20509
  }
20468
20510
  } else if (options?.GET) {
20469
20511
  this.store[key] = { type: "str" /* STR */, expire: -1 };
@@ -20519,13 +20561,14 @@ var init_mock = __esm({
20519
20561
  * @description 仅当键不存在时设置键值对
20520
20562
  * @param key 键
20521
20563
  * @param value 值
20564
+ * @returns 返回 1 表示键已设置,0 表示键已存在
20522
20565
  */
20523
20566
  async setNX(key, value) {
20524
20567
  if (this.store[key] && !this.checkExpire(key)) {
20525
- return false;
20568
+ return 0;
20526
20569
  }
20527
20570
  await this.set(key, value, { NX: true });
20528
- return true;
20571
+ return 1;
20529
20572
  }
20530
20573
  /**
20531
20574
  * @description 获取键值并设置过期时间
@@ -21101,11 +21144,11 @@ var init_mock = __esm({
21101
21144
  this.store[key].expire = -1;
21102
21145
  this.#zset[key] = [];
21103
21146
  }
21104
- const index6 = this.#zset[key].findIndex((entry) => entry.member === member.toString());
21105
- if (index6 === -1) {
21147
+ const index5 = this.#zset[key].findIndex((entry) => entry.member === member.toString());
21148
+ if (index5 === -1) {
21106
21149
  this.#zset[key].push({ score, member });
21107
21150
  } else {
21108
- this.#zset[key][index6] = { score, member };
21151
+ this.#zset[key][index5] = { score, member };
21109
21152
  }
21110
21153
  this.#sqlite.set(key, JSON.stringify(this.#zset[key]), "zset" /* ZSET */, this.store[key].expire);
21111
21154
  return 1;
@@ -21129,8 +21172,8 @@ var init_mock = __esm({
21129
21172
  async zRank(key, member) {
21130
21173
  if (!this.#list[key]) return null;
21131
21174
  if (this.checkExpire(key)) return null;
21132
- const index6 = this.#list[key].findIndex((entry) => entry === member.toString());
21133
- return index6 !== -1 ? index6 : null;
21175
+ const index5 = this.#list[key].findIndex((entry) => entry === member.toString());
21176
+ return index5 !== -1 ? index5 : null;
21134
21177
  }
21135
21178
  /**
21136
21179
  * 返回有序集合中指定成员的分数
@@ -21356,17 +21399,17 @@ var init_mock = __esm({
21356
21399
  * @param index 索引,0表示第一个元素,-1表示最后一个元素
21357
21400
  * @returns 返回元素值,索引超出范围返回null
21358
21401
  */
21359
- async lIndex(key, index6) {
21402
+ async lIndex(key, index5) {
21360
21403
  if (!this.#list[key]) return null;
21361
21404
  if (this.checkExpire(key)) return null;
21362
21405
  const list2 = this.#list[key];
21363
- if (index6 < 0) {
21364
- index6 = list2.length + index6;
21406
+ if (index5 < 0) {
21407
+ index5 = list2.length + index5;
21365
21408
  }
21366
- if (index6 < 0 || index6 >= list2.length) {
21409
+ if (index5 < 0 || index5 >= list2.length) {
21367
21410
  return null;
21368
21411
  }
21369
- return list2[index6].toString();
21412
+ return list2[index5].toString();
21370
21413
  }
21371
21414
  /**
21372
21415
  * 设置列表指定索引的元素值
@@ -21375,17 +21418,17 @@ var init_mock = __esm({
21375
21418
  * @param value 值
21376
21419
  * @returns 成功返回"OK",失败返回错误
21377
21420
  */
21378
- async lSet(key, index6, value) {
21421
+ async lSet(key, index5, value) {
21379
21422
  if (!this.#list[key]) return null;
21380
21423
  if (this.checkExpire(key)) return null;
21381
21424
  const list2 = this.#list[key];
21382
- if (index6 < 0) {
21383
- index6 = list2.length + index6;
21425
+ if (index5 < 0) {
21426
+ index5 = list2.length + index5;
21384
21427
  }
21385
- if (index6 < 0 || index6 >= list2.length) {
21428
+ if (index5 < 0 || index5 >= list2.length) {
21386
21429
  return null;
21387
21430
  }
21388
- list2[index6] = value;
21431
+ list2[index5] = value;
21389
21432
  this.#sqlite.set(key, JSON.stringify(list2), "list" /* LIST */, this.store[key].expire);
21390
21433
  return "OK";
21391
21434
  }
@@ -21599,9 +21642,9 @@ var init_mock = __esm({
21599
21642
  if (!this.#zset[key]) return 0;
21600
21643
  if (this.checkExpire(key)) return 0;
21601
21644
  const strMember = member.toString();
21602
- const index6 = this.#zset[key].findIndex((entry) => entry.member.toString() === strMember);
21603
- if (index6 !== -1) {
21604
- this.#zset[key].splice(index6, 1);
21645
+ const index5 = this.#zset[key].findIndex((entry) => entry.member.toString() === strMember);
21646
+ if (index5 !== -1) {
21647
+ this.#zset[key].splice(index5, 1);
21605
21648
  this.#sqlite.set(key, JSON.stringify(this.#zset[key]), "zset" /* ZSET */, this.store[key].expire);
21606
21649
  return 1;
21607
21650
  }
@@ -22715,7 +22758,7 @@ var init_http2 = __esm({
22715
22758
  }
22716
22759
  return;
22717
22760
  }
22718
- const index6 = registerRender("puppeteer", async (options) => {
22761
+ const index5 = registerRender("puppeteer", async (options) => {
22719
22762
  try {
22720
22763
  const result = await axios8.post(`${url}/puppeteer`, options, { headers });
22721
22764
  if (result.status !== 200) {
@@ -22725,7 +22768,7 @@ var init_http2 = __esm({
22725
22768
  } catch (error) {
22726
22769
  if (axios8.isAxiosError(error)) {
22727
22770
  if (!error.response) {
22728
- unregisterRender(index6);
22771
+ unregisterRender(index5);
22729
22772
  throw new Error(`[render][http] \u7F51\u7EDC\u8FDE\u63A5\u5931\u8D25: ${error.message}`);
22730
22773
  }
22731
22774
  const { response } = error;
@@ -26719,7 +26762,7 @@ var init_app = __esm({
26719
26762
  };
26720
26763
  }
26721
26764
  });
26722
- var index5, botID, AdapterConsole, adapter2;
26765
+ var getMessageId, getFileId, botID, AdapterConsole, adapter2;
26723
26766
  var init_input = __esm({
26724
26767
  "src/adapter/input/index.ts"() {
26725
26768
  init_base();
@@ -26729,9 +26772,11 @@ var init_input = __esm({
26729
26772
  init_service();
26730
26773
  init_message2();
26731
26774
  init_config();
26775
+ init_common();
26732
26776
  init_create();
26733
26777
  init_event2();
26734
- index5 = 0;
26778
+ getMessageId = createIdGenerator();
26779
+ getFileId = createIdGenerator();
26735
26780
  botID = "console";
26736
26781
  AdapterConsole = class extends AdapterBase {
26737
26782
  constructor() {
@@ -26812,7 +26857,7 @@ var init_input = __esm({
26812
26857
  }
26813
26858
  async sendMsg(contact3, elements, _) {
26814
26859
  const time2 = Date.now();
26815
- const messageId = (++index5).toString();
26860
+ const messageId = getMessageId().toString();
26816
26861
  const result = {
26817
26862
  message_id: messageId,
26818
26863
  messageId,
@@ -26851,7 +26896,7 @@ var init_input = __esm({
26851
26896
  }
26852
26897
  async getUrl(data, ext) {
26853
26898
  const cfg = adapter();
26854
- const name = (++index5).toString();
26899
+ const name = getFileId().toString();
26855
26900
  const file2 = path4.join(consolePath, `${name}${ext}`);
26856
26901
  await fs5.promises.writeFile(file2, await buffer(data));
26857
26902
  if (cfg.console.isLocal) {
@@ -27590,8 +27635,8 @@ var Other = class extends EventEmitter {
27590
27635
  * 根据索引获取Bot
27591
27636
  * @param index - Bot的索引id
27592
27637
  */
27593
- getBotByIndex(index6) {
27594
- return getBot(index6);
27638
+ getBotByIndex(index5) {
27639
+ return getBot(index5);
27595
27640
  }
27596
27641
  /**
27597
27642
  * 获取注册的Bot数量
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.11.2",
3
+ "version": "1.11.4",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",