node-karin 1.8.11 → 1.8.13

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,25 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.8.13](https://github.com/KarinJS/Karin/compare/core-v1.8.12...core-v1.8.13) (2025-05-09)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * clearCache ([#418](https://github.com/KarinJS/Karin/issues/418)) ([652b8fd](https://github.com/KarinJS/Karin/commit/652b8fdd65bf461fbbe85c3ba7b4dfc948cce915))
9
+ * restart ([#415](https://github.com/KarinJS/Karin/issues/415)) ([790ccdd](https://github.com/KarinJS/Karin/commit/790ccddf3c09ef1c91e5b344d3ff9afa7d116e8e))
10
+
11
+
12
+ ### 🎡 Continuous Integration
13
+
14
+ * ban publish-minimal-repro ([#417](https://github.com/KarinJS/Karin/issues/417)) ([6ddcf80](https://github.com/KarinJS/Karin/commit/6ddcf803c99bac68662dbd95902f02bc8b6078cd))
15
+
16
+ ## [1.8.12](https://github.com/KarinJS/Karin/compare/core-v1.8.11...core-v1.8.12) (2025-05-08)
17
+
18
+
19
+ ### 🐛 Bug Fixes
20
+
21
+ * 修复主进程退出时子进程未被正确终止的问题 修复场景唯一标识符缓存问题 ([#413](https://github.com/KarinJS/Karin/issues/413)) ([e971438](https://github.com/KarinJS/Karin/commit/e971438892fe5726466ddfc1fd408599d8af6457))
22
+
3
23
  ## [1.8.11](https://github.com/KarinJS/Karin/compare/core-v1.8.10...core-v1.8.11) (2025-05-08)
4
24
 
5
25
 
package/dist/index.d.ts CHANGED
@@ -12074,6 +12074,17 @@ declare namespace index$1 {
12074
12074
  * @param data 数据
12075
12075
  */
12076
12076
  declare const formatArray: (data: any[]) => string[];
12077
+ /**
12078
+ * 初始化count
12079
+ * @param count 计数器
12080
+ * @param key 键
12081
+ */
12082
+ declare const initCount: (count: Record<string, {
12083
+ /** 上一分钟调用次数 */
12084
+ start: number;
12085
+ /** 当前调用次数 */
12086
+ count: number;
12087
+ }>, key: string) => void;
12077
12088
  /**
12078
12089
  * @internal
12079
12090
  * 传入一个对象 将对象中的嵌套数组中所有元素为字符串
@@ -12104,8 +12115,11 @@ declare const createCount: () => Record<string, {
12104
12115
  declare const getCacheCfg: <T>(cache: Record<string, T>, count: ReturnType<typeof createCount>, keys: string[]) => T;
12105
12116
  /**
12106
12117
  * 定时清理缓存
12118
+ * @param data 数据
12119
+ * @param count 计数器
12120
+ * @param cache 缓存
12107
12121
  */
12108
- declare const clearCache: <T>(count: ReturnType<typeof createCount>, cache: Record<string, T>) => void;
12122
+ declare const clearCache: <T extends GroupsObjectValue | PrivatesObjectValue>(data: Record<string, T>, count: ReturnType<typeof createCount>, cache: Record<string, T>) => void;
12109
12123
 
12110
12124
  /**
12111
12125
  * @description 默认配置
@@ -12259,7 +12273,9 @@ declare const writeEnv: (data: {
12259
12273
  * @description 获取群聊、频道配置
12260
12274
  * @returns 群聊、频道配置
12261
12275
  */
12262
- declare const groups: () => Record<string, GroupsObjectValue>;
12276
+ declare const groups: () => {
12277
+ get: () => Record<string, GroupsObjectValue>;
12278
+ };
12263
12279
  /**
12264
12280
  * @public 公开Api
12265
12281
  * @description 获取指定群聊配置
@@ -12366,6 +12382,7 @@ declare const index_getYaml: typeof getYaml;
12366
12382
  declare const index_groups: typeof groups;
12367
12383
  declare const index_host: typeof host;
12368
12384
  declare const index_initConfigCache: typeof initConfigCache;
12385
+ declare const index_initCount: typeof initCount;
12369
12386
  declare const index_initPm2: typeof initPm2;
12370
12387
  declare const index_master: typeof master;
12371
12388
  declare const index_mergeDegAndCfg: typeof mergeDegAndCfg;
@@ -12381,7 +12398,7 @@ declare const index_updateLevel: typeof updateLevel;
12381
12398
  declare const index_webSocketServerToken: typeof webSocketServerToken;
12382
12399
  declare const index_writeEnv: typeof writeEnv;
12383
12400
  declare namespace index {
12384
- export { index_adapter as adapter, index_admin as admin, index_authKey as authKey, index_clearCache as clearCache, index_clearFiles as clearFiles, index_config as config, index_createCount as createCount, index_defaultConfig as defaultConfig, index_env as env, index_ffmpegPath as ffmpegPath, index_ffplayPath as ffplayPath, index_ffprobePath as ffprobePath, index_formatArray as formatArray, index_formatObject as formatObject, index_getCacheCfg as getCacheCfg, index_getDirectCfg as getDirectCfg, index_getEnv as getEnv, index_getFriendCfg as getFriendCfg, index_getGroupCfg as getGroupCfg, index_getGroupsFileData as getGroupsFileData, index_getGuildCfg as getGuildCfg, index_getPrivatesFileData as getPrivatesFileData, index_getRenderCfg as getRenderCfg, index_getYaml as getYaml, index_groups as groups, index_host as host, index_initConfigCache as initConfigCache, index_initPm2 as initPm2, index_master as master, index_mergeDegAndCfg as mergeDegAndCfg, index_pkg as pkg, index_pm2 as pm2, index_port as port, index_privates as privates, redis$1 as redis, render$1 as render, index_setConfig as setConfig, index_setEnv as setEnv, index_setYaml as setYaml, index_timeout as timeout, index_updateLevel as updateLevel, index_webSocketServerToken as webSocketServerToken, index_writeEnv as writeEnv };
12401
+ export { index_adapter as adapter, index_admin as admin, index_authKey as authKey, index_clearCache as clearCache, index_clearFiles as clearFiles, index_config as config, index_createCount as createCount, index_defaultConfig as defaultConfig, index_env as env, index_ffmpegPath as ffmpegPath, index_ffplayPath as ffplayPath, index_ffprobePath as ffprobePath, index_formatArray as formatArray, index_formatObject as formatObject, index_getCacheCfg as getCacheCfg, index_getDirectCfg as getDirectCfg, index_getEnv as getEnv, index_getFriendCfg as getFriendCfg, index_getGroupCfg as getGroupCfg, index_getGroupsFileData as getGroupsFileData, index_getGuildCfg as getGuildCfg, index_getPrivatesFileData as getPrivatesFileData, index_getRenderCfg as getRenderCfg, index_getYaml as getYaml, index_groups as groups, index_host as host, index_initConfigCache as initConfigCache, index_initCount as initCount, index_initPm2 as initPm2, index_master as master, index_mergeDegAndCfg as mergeDegAndCfg, index_pkg as pkg, index_pm2 as pm2, index_port as port, index_privates as privates, redis$1 as redis, render$1 as render, index_setConfig as setConfig, index_setEnv as setEnv, index_setYaml as setYaml, index_timeout as timeout, index_updateLevel as updateLevel, index_webSocketServerToken as webSocketServerToken, index_writeEnv as writeEnv };
12385
12402
  }
12386
12403
 
12387
12404
  /**
package/dist/index.mjs CHANGED
@@ -3174,7 +3174,7 @@ var init_exec = __esm({
3174
3174
  });
3175
3175
 
3176
3176
  // src/utils/config/tools.ts
3177
- var formatArray, formatObject, mergeDegAndCfg, createCount, getCacheCfg, clearCache;
3177
+ var formatArray, initCount, formatObject, mergeDegAndCfg, createCount, getCacheCfg, clearCache;
3178
3178
  var init_tools = __esm({
3179
3179
  "src/utils/config/tools.ts"() {
3180
3180
  formatArray = (data) => {
@@ -3184,6 +3184,13 @@ var init_tools = __esm({
3184
3184
  return [];
3185
3185
  }
3186
3186
  };
3187
+ initCount = (count3, key) => {
3188
+ if (!count3[key]) {
3189
+ count3[key] = { start: 0, count: 1 };
3190
+ } else {
3191
+ count3[key].count++;
3192
+ }
3193
+ };
3187
3194
  formatObject = (data) => {
3188
3195
  const list2 = {};
3189
3196
  Object.entries(data).forEach(([key, value]) => {
@@ -3219,30 +3226,35 @@ var init_tools = __esm({
3219
3226
  return {};
3220
3227
  };
3221
3228
  getCacheCfg = (cache12, count3, keys) => {
3222
- if (keys[0] in cache12) {
3223
- if (!count3[keys[0]]) {
3224
- count3[keys[0]] = { start: 0, count: 0 };
3225
- }
3226
- count3[keys[0]].count++;
3227
- return cache12[keys[0]];
3228
- }
3229
- for (const index6 in keys) {
3230
- if (keys[index6] in cache12) {
3231
- if (index6 === "0") {
3232
- count3[keys[index6]] = { start: 0, count: 1 };
3233
- } else {
3234
- count3[keys[0]] = { start: 0, count: 1 };
3235
- cache12[keys[0]] = cache12[keys[index6]];
3236
- }
3237
- return cache12[keys[index6]];
3238
- }
3239
- }
3229
+ const key = keys[0];
3230
+ if (cache12[key]) {
3231
+ initCount(count3, key);
3232
+ return cache12[key];
3233
+ }
3234
+ keys.forEach((v, index6) => {
3235
+ if (!cache12[v]) return;
3236
+ if (index6 === 0 && v === key) {
3237
+ initCount(count3, v);
3238
+ return cache12[v];
3239
+ }
3240
+ if (v === key) {
3241
+ initCount(count3, v);
3242
+ return cache12[v];
3243
+ }
3244
+ cache12[key] = cache12[v];
3245
+ initCount(count3, key);
3246
+ return cache12[key];
3247
+ });
3240
3248
  return cache12.default;
3241
3249
  };
3242
- clearCache = (count3, cache12) => {
3250
+ clearCache = (data, count3, cache12) => {
3243
3251
  setInterval(() => {
3244
3252
  Object.keys(count3).forEach((key) => {
3245
3253
  if (count3[key].count - count3[key].start < 10) {
3254
+ if (data[key]) {
3255
+ delete count3[key];
3256
+ return;
3257
+ }
3246
3258
  delete count3[key];
3247
3259
  delete cache12[key];
3248
3260
  } else {
@@ -11165,7 +11177,11 @@ var init_restart = __esm({
11165
11177
  const db2 = await createDB2();
11166
11178
  await db2.set(key, options);
11167
11179
  if (isFront && process.send) {
11168
- process.send("restart");
11180
+ process.send(JSON.stringify({
11181
+ type: "restart",
11182
+ port: process.env.HTTP_PORT,
11183
+ token: process.env.HTTP_AUTH_KEY
11184
+ }));
11169
11185
  return { status: "success", data: "\u5DF2\u53D1\u9001\u91CD\u542F\u4FE1\u53F7" };
11170
11186
  }
11171
11187
  if (process.env.PM2_RESTART === "true") process.exit();
@@ -16110,6 +16126,7 @@ __export(config_exports, {
16110
16126
  groups: () => groups,
16111
16127
  host: () => host,
16112
16128
  initConfigCache: () => initConfigCache,
16129
+ initCount: () => initCount,
16113
16130
  initPm2: () => initPm2,
16114
16131
  master: () => master,
16115
16132
  mergeDegAndCfg: () => mergeDegAndCfg,
@@ -16693,16 +16710,21 @@ var init_groups4 = __esm({
16693
16710
  const name = "groups.json";
16694
16711
  const file = `${dir2}/${name}`;
16695
16712
  const data = requireFileSync(file, { type: "json" });
16696
- cache8 = isOld(data) ? migrate(file, data) : format2(data);
16713
+ const DATA = isOld(data) ? migrate(file, data) : format2(data);
16714
+ cache8 = DATA;
16697
16715
  watch(file, async (old, data2) => {
16698
16716
  cache8 = format2(data2);
16699
16717
  const options = { file: name, old, data: cache8 };
16700
16718
  listeners.emit(FILE_CHANGE, options);
16701
16719
  listeners.emit(`${FILE_CHANGE}:${name}`, options);
16702
16720
  }, { type: "json" });
16703
- clearCache(count, cache8);
16721
+ clearCache(DATA, count, cache8);
16722
+ };
16723
+ groups = () => {
16724
+ return {
16725
+ get: () => cache8
16726
+ };
16704
16727
  };
16705
- groups = () => cache8;
16706
16728
  getGroupCfg = (groupId, selfId) => {
16707
16729
  const keys = [
16708
16730
  `Bot:${selfId}:${groupId}`,
@@ -16769,14 +16791,15 @@ var init_privates = __esm({
16769
16791
  const name = "privates.json";
16770
16792
  const file = `${dir2}/${name}`;
16771
16793
  const data = requireFileSync(file, { type: "json" });
16772
- cache9 = isOld2(data) ? migrate2(file, data) : format3(data);
16794
+ const DATA = isOld2(data) ? migrate2(file, data) : format3(data);
16795
+ cache9 = DATA;
16773
16796
  watch(file, async (old, data2) => {
16774
16797
  cache9 = format3(data2);
16775
16798
  const options = { file: name, old, data: cache9 };
16776
16799
  listeners.emit(FILE_CHANGE, options);
16777
16800
  listeners.emit(`${FILE_CHANGE}:${name}`, options);
16778
16801
  }, { type: "json" });
16779
- clearCache(count2, cache9);
16802
+ clearCache(DATA, count2, cache9);
16780
16803
  };
16781
16804
  privates = () => cache9;
16782
16805
  getFriendCfg = (userId, selfId) => {
@@ -17824,6 +17847,7 @@ var init_mock = __esm({
17824
17847
  init_key4();
17825
17848
  init_common();
17826
17849
  RedisClient = class extends EventEmitter {
17850
+ id;
17827
17851
  /** 键、类型、过期时间映射 */
17828
17852
  store = {};
17829
17853
  /** 键值对 */
@@ -17846,6 +17870,7 @@ var init_mock = __esm({
17846
17870
  #sqlite;
17847
17871
  constructor(sqlite) {
17848
17872
  super();
17873
+ this.id = "mock";
17849
17874
  this.store = {};
17850
17875
  this.#str = {};
17851
17876
  this.#num = {};
@@ -19102,18 +19127,21 @@ var init_exit = __esm({
19102
19127
  init_uptime();
19103
19128
  exitStatus = false;
19104
19129
  processExit = async (code) => {
19130
+ logger.debug("[child] \u5B50\u8FDB\u7A0B\u6536\u5230\u9000\u51FA\u7533\u8BF7:", code);
19105
19131
  try {
19106
19132
  if (exitStatus) return;
19107
19133
  exitStatus = true;
19134
+ logger.debug("[child] \u5F00\u59CB\u4FDD\u5B58redis\u6570\u636E");
19108
19135
  const { redis: redis3 } = await Promise.resolve().then(() => (init_redis3(), redis_exports));
19109
- await redis3.save();
19136
+ if (redis3.id === "mock") await redis3.save();
19137
+ logger.debug("[child] redis\u6570\u636E\u4FDD\u5B58\u5B8C\u6210");
19110
19138
  logger.mark(tips(`\u8FD0\u884C\u7ED3\u675F \u8FD0\u884C\u65F6\u95F4\uFF1A${uptime2()} \u9000\u51FA\u7801\uFF1A${code ?? "\u672A\u77E5"}`));
19111
19139
  if (process.env.pm_id) {
19112
- logger.mark(tips("pm2\u73AF\u5883 \u5220\u9664pm2\u8FDB\u7A0B"));
19140
+ logger.mark(tips("[child] pm2\u73AF\u5883 \u5220\u9664pm2\u8FDB\u7A0B"));
19113
19141
  await exec(`pm2 delete ${process.env.pm_id}`);
19114
19142
  }
19115
19143
  } catch (error) {
19116
- logger.error(new Error("\u9000\u51FA\u4E8B\u4EF6\u53D1\u751F\u9519\u8BEF:", { cause: error }));
19144
+ logger.error(new Error("[child] \u9000\u51FA\u4E8B\u4EF6\u53D1\u751F\u9519\u8BEF:", { cause: error }));
19117
19145
  } finally {
19118
19146
  setTimeout(() => {
19119
19147
  exitStatus = true;
@@ -95,8 +95,6 @@ var sendExit = async (port, token) => {
95
95
  }
96
96
  };
97
97
  process.on("exit", () => {
98
- if (child && !child.killed) {
99
- child.kill("SIGTERM");
100
- }
98
+ child.kill("SIGTERM");
101
99
  });
102
100
  start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.8.11",
3
+ "version": "1.8.13",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",