node-karin 1.9.3 → 1.9.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.9.4](https://github.com/KarinJS/Karin/compare/core-v1.9.3...core-v1.9.4) (2025-05-21)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * close [#436](https://github.com/KarinJS/Karin/issues/436) ([9ff2938](https://github.com/KarinJS/Karin/commit/9ff2938a386193c42cef91160205d254865e77c3))
9
+ * 升级版本后重启找不到入口文件 ([eadc52f](https://github.com/KarinJS/Karin/commit/eadc52f6e3206b9b5c399e689c64ab7c95f18c8a))
10
+
11
+
12
+ ### ⚡️ Performance
13
+
14
+ * 优化`raceRequest`函数 ([0455a3c](https://github.com/KarinJS/Karin/commit/0455a3c3e9cba1f19c7b6ed1862a16f072cd3599))
15
+ * 优化全局配置 添加对应配置项 ([f6c81d3](https://github.com/KarinJS/Karin/commit/f6c81d38d20397f9391ec44703126bafc3c52197))
16
+
3
17
  ## [1.9.3](https://github.com/KarinJS/Karin/compare/core-v1.9.2...core-v1.9.3) (2025-05-17)
4
18
 
5
19
 
package/dist/index.d.ts CHANGED
@@ -7488,6 +7488,8 @@ interface Package {
7488
7488
  interface GroupsObjectValue {
7489
7489
  /** 配置键: `Bot:selfId:groupId` */
7490
7490
  key: string;
7491
+ /** 是否继承全局配置 默认`true` */
7492
+ inherit: boolean;
7491
7493
  /** 群聊、频道中所有消息冷却时间,单位秒,0则无限制 */
7492
7494
  cd: number;
7493
7495
  /** 群聊、频道中 每个人的消息冷却时间,单位秒,0则无限制。注意,开启后所有消息都会进CD,无论是否触发插件。 */
@@ -7516,6 +7518,8 @@ type Groups = GroupsObjectValue[];
7516
7518
  interface PrivatesObjectValue {
7517
7519
  /** 配置键 `Bot:selfId:userId` */
7518
7520
  key: string;
7521
+ /** 是否继承全局配置 默认`true` */
7522
+ inherit: boolean;
7519
7523
  /** 好友消息冷却时间,单位秒,0则无限制 */
7520
7524
  cd: number;
7521
7525
  /** 机器人响应模式,0-所有 2-仅回应管理员 3-仅回应别名 5-管理员无限制,非管理员别名 6-仅回应主人 */
@@ -11752,10 +11756,14 @@ declare const makeMessage: (elements: SendMessage) => Array<Elements>;
11752
11756
  */
11753
11757
  declare const makeForward: (elements: SendMessage | Array<Elements[]>, fakeId?: string, fakeName?: string) => Array<CustomNodeElement>;
11754
11758
 
11759
+ interface RaceRequestConfig extends AxiosRequestConfig {
11760
+ /** 响应成功状态码 默认[200] */
11761
+ successCodes?: number[];
11762
+ }
11755
11763
  /**
11756
11764
  * 竞速请求 返回最先成功响应的数据
11757
11765
  * @param urls - 请求地址数组
11758
- * @param config - 请求配置 默认 { timeout: 10000, method: 'HEAD' }
11766
+ * @param config - 请求配置 默认 { timeout: 10000, method: 'HEAD', successCodes: [200] }
11759
11767
  * @returns 返回最先成功响应的数据
11760
11768
  * @example
11761
11769
  * const urls = ['https://api.github.com', 'https://api.gitee.com']
@@ -11766,11 +11774,13 @@ declare const makeForward: (elements: SendMessage | Array<Elements[]>, fakeId?:
11766
11774
  * const urls = ['https://api.github.com/post', 'https://api.gitee.com/post']
11767
11775
  * const data = await raceRequest(urls, {
11768
11776
  * method: 'post',
11769
- * data: { foo: 'bar' }
11777
+ * data: { foo: 'bar' },
11778
+ * timeout: 10000,
11779
+ * successCodes: [200, 201]
11770
11780
  * })
11771
11781
  * console.log(data)
11772
11782
  */
11773
- declare const raceRequest: <R = AxiosRequestConfig, T = any>(urls: string[], config?: AxiosRequestConfig) => Promise<AxiosResponse<T, R> | null>;
11783
+ declare const raceRequest: <R = AxiosRequestConfig, T = any>(urls: string[], config?: RaceRequestConfig) => Promise<AxiosResponse<T, R> | null>;
11774
11784
  /**
11775
11785
  * 测试网络请求
11776
11786
  * @template D - 请求数据类型
@@ -11984,6 +11994,95 @@ declare const average: (numbers: number[]) => number;
11984
11994
  * round(1.235, 2) // 返回 1.24
11985
11995
  */
11986
11996
  declare const round: (num: number, decimals?: number) => number;
11997
+ /**
11998
+ * 判断是否为数字 处理NaN的情况
11999
+ * @param num 需要判断的数字
12000
+ * @param defaultValue 默认值 如果非数字 返回默认值
12001
+ * @returns 处理后的数字
12002
+ * @example isNumber(NaN) // 返回 0
12003
+ * isNumber(123) // 返回 123
12004
+ * isNumber('abc', 123) // 返回 123
12005
+ */
12006
+ declare const isNumber: (num: unknown, defaultValue?: number) => number;
12007
+ /**
12008
+ * 判断数组中的元素是否为数字
12009
+ * @description 从索引0开始寻找,如果找到数字则返回数字,否则返回默认值
12010
+ * @param arr 需要判断的数组
12011
+ * @param defaultValue 默认值 如果非数字 返回默认值
12012
+ * @returns 数字或默认值
12013
+ * @example isNumberInArray([1, '2', 3], 0) // 返回 1
12014
+ * isNumberInArray(['1', '2', '3'], 0) // 返回 0
12015
+ */
12016
+ declare const isNumberInArray: <T = number>(arr: unknown[], defaultValue?: number) => T;
12017
+
12018
+ /**
12019
+ * 字符串工具
12020
+ */
12021
+ declare const strToBool: {
12022
+ /**
12023
+ * 将数组中的所有元素转换为字符串 使用`String`转换
12024
+ * @param arr 需要转换的数组
12025
+ * @returns 转换后的字符串
12026
+ * @example strToBool.array([1, '2']) // ['1', '2']
12027
+ * strToBool.array(['3', null, undefined, NaN, '']) // ['3']
12028
+ */
12029
+ array: (arr: unknown[]) => string[];
12030
+ /**
12031
+ * 排除数组中所有非字符串的元素
12032
+ * @param arr 需要转换的数组
12033
+ * @returns 转换后的字符串
12034
+ * @example strToBool.arrayExcludeNonString(['1', '2', '3']) // ['1', '2', '3']
12035
+ * strToBool.arrayExcludeNonString(['1', '2', '3', null, undefined, NaN, '']) // ['1', '2', '3']
12036
+ */
12037
+ arrayExcludeNonString: (arr: unknown[]) => string[];
12038
+ /**
12039
+ * 将字符串转换为布尔值
12040
+ * @param str 需要转换的字符串
12041
+ * @returns 转换后的布尔值
12042
+ * @example strToBool.string('true') // true
12043
+ * strToBool.string('1') // true
12044
+ * strToBool.string('yes') // true
12045
+ * strToBool.string('on') // true
12046
+ * strToBool.string('false') // false
12047
+ * strToBool.string('0') // false
12048
+ * strToBool.string('no') // false
12049
+ */
12050
+ string: (str: string) => boolean;
12051
+ /**
12052
+ * 将字符串转换为数字
12053
+ * @param str 需要转换的字符串
12054
+ * @param defaultValue 默认值 如果非数字 返回默认值
12055
+ * @returns 转换后的数字
12056
+ * @example strToBool.number('1') // 1
12057
+ * strToBool.number('2') // 2
12058
+ * strToBool.number('3') // 3
12059
+ * strToBool.number('abc', 123) // 123
12060
+ */
12061
+ number: (str: string, defaultValue?: number) => number;
12062
+ /**
12063
+ * 将字符串数组转换为数字数组
12064
+ * @param arr 需要转换的数组
12065
+ * @returns 转换后的数字数组
12066
+ * @example strToBool.arrayNumber(['1', '2', '3']) // [1, 2, 3]
12067
+ */
12068
+ arrayNumber: (arr: string[]) => number[];
12069
+ /**
12070
+ * 传入一个数组 按照索引返回数组 并且将这个数组转换为字符串数组 去掉重复、非字符串的元素
12071
+ * @param arr 需要转换的数组
12072
+ * @param index 需要返回的索引
12073
+ * @returns 转换后的字符串数组
12074
+ * @example strToBool.arrayString(['1', '2', '3'], 0) // ['1']
12075
+ */
12076
+ arrayString: (arr: unknown[]) => string[];
12077
+ /**
12078
+ * 合并多个数组为一个并去重 如果不是数组将会跳过
12079
+ * @param arr 需要合并的数组
12080
+ * @returns 合并后的数组
12081
+ * @example strToBool.mergeArray(['1', '2', '3'], ['4', '5', '6']) // ['1', '2', '3', '4', '5', '6']
12082
+ * strToBool.mergeArray(['4', '5', '6'], ['4', '5', '6']) // ['4', '5', '6']
12083
+ */
12084
+ mergeArray: <T>(...arr: unknown[]) => T[];
12085
+ };
11987
12086
 
11988
12087
  /**
11989
12088
  * 休眠函数
@@ -12131,6 +12230,8 @@ declare const index$1_getNpmPlugins: typeof getNpmPlugins;
12131
12230
  declare const index$1_getRelPath: typeof getRelPath;
12132
12231
  declare const index$1_isDir: typeof isDir;
12133
12232
  declare const index$1_isEven: typeof isEven;
12233
+ declare const index$1_isNumber: typeof isNumber;
12234
+ declare const index$1_isNumberInArray: typeof isNumberInArray;
12134
12235
  declare const index$1_isPlugin: typeof isPlugin;
12135
12236
  declare const index$1_karinToQQBot: typeof karinToQQBot;
12136
12237
  declare const index$1_makeForward: typeof makeForward;
@@ -12142,12 +12243,13 @@ declare const index$1_random: typeof random;
12142
12243
  declare const index$1_round: typeof round;
12143
12244
  declare const index$1_sleep: typeof sleep;
12144
12245
  declare const index$1_splitPath: typeof splitPath;
12246
+ declare const index$1_strToBool: typeof strToBool;
12145
12247
  declare const index$1_stream: typeof stream;
12146
12248
  declare const index$1_updateYaml: typeof updateYaml;
12147
12249
  declare const index$1_uptime: typeof uptime;
12148
12250
  declare const index$1_urlToPath: typeof urlToPath;
12149
12251
  declare namespace index$1 {
12150
- 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_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_stream as stream, index$1_updateYaml as updateYaml, index$1_uptime as uptime, index$1_urlToPath as urlToPath, writeJsonSync as writeJson, write as writeYaml };
12252
+ 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 };
12151
12253
  }
12152
12254
 
12153
12255
  /**
@@ -12173,13 +12275,6 @@ declare const initCount: (count: Record<string, {
12173
12275
  * @returns 统一后的数据
12174
12276
  */
12175
12277
  declare const formatObject: <T extends Record<string, any>>(data: T) => T;
12176
- /**
12177
- * 合并对象 专属privates、groups
12178
- * @param def 默认配置
12179
- * @param cfg 配置
12180
- * @returns 合并后的配置
12181
- */
12182
- declare const mergeDegAndCfg: <T extends Record<string, any>>(def: T, cfg: T) => T;
12183
12278
  /**
12184
12279
  * @internal
12185
12280
  * @description 创建缓存对象
@@ -12466,7 +12561,6 @@ declare const index_initConfigCache: typeof initConfigCache;
12466
12561
  declare const index_initCount: typeof initCount;
12467
12562
  declare const index_initPm2: typeof initPm2;
12468
12563
  declare const index_master: typeof master;
12469
- declare const index_mergeDegAndCfg: typeof mergeDegAndCfg;
12470
12564
  declare const index_pkg: typeof pkg;
12471
12565
  declare const index_pm2: typeof pm2;
12472
12566
  declare const index_port: typeof port;
@@ -12479,7 +12573,7 @@ declare const index_updateLevel: typeof updateLevel;
12479
12573
  declare const index_webSocketServerToken: typeof webSocketServerToken;
12480
12574
  declare const index_writeEnv: typeof writeEnv;
12481
12575
  declare namespace index {
12482
- 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 };
12576
+ 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_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 };
12483
12577
  }
12484
12578
 
12485
12579
  /**
package/dist/index.mjs CHANGED
@@ -1576,6 +1576,19 @@ var init_default = __esm({
1576
1576
  groups: [
1577
1577
  {
1578
1578
  key: "default",
1579
+ inherit: true,
1580
+ cd: 0,
1581
+ userCD: 0,
1582
+ mode: 0,
1583
+ alias: [],
1584
+ enable: [],
1585
+ disable: [],
1586
+ member_enable: [],
1587
+ member_disable: []
1588
+ },
1589
+ {
1590
+ key: "global",
1591
+ inherit: true,
1579
1592
  cd: 0,
1580
1593
  userCD: 0,
1581
1594
  mode: 0,
@@ -1587,6 +1600,7 @@ var init_default = __esm({
1587
1600
  },
1588
1601
  {
1589
1602
  key: "Bot:selfId",
1603
+ inherit: true,
1590
1604
  cd: 0,
1591
1605
  userCD: 0,
1592
1606
  mode: 0,
@@ -1598,6 +1612,7 @@ var init_default = __esm({
1598
1612
  },
1599
1613
  {
1600
1614
  key: "Bot:selfId:groupId",
1615
+ inherit: true,
1601
1616
  cd: 0,
1602
1617
  userCD: 0,
1603
1618
  mode: 0,
@@ -1609,6 +1624,7 @@ var init_default = __esm({
1609
1624
  },
1610
1625
  {
1611
1626
  key: "Bot:selfId:guildId",
1627
+ inherit: true,
1612
1628
  cd: 0,
1613
1629
  userCD: 0,
1614
1630
  mode: 0,
@@ -1620,6 +1636,7 @@ var init_default = __esm({
1620
1636
  },
1621
1637
  {
1622
1638
  key: "Bot:selfId:guildId:channelId",
1639
+ inherit: true,
1623
1640
  cd: 0,
1624
1641
  userCD: 0,
1625
1642
  mode: 0,
@@ -1649,6 +1666,16 @@ var init_default = __esm({
1649
1666
  privates: [
1650
1667
  {
1651
1668
  key: "default",
1669
+ inherit: true,
1670
+ cd: 0,
1671
+ mode: 0,
1672
+ alias: [],
1673
+ enable: [],
1674
+ disable: []
1675
+ },
1676
+ {
1677
+ key: "global",
1678
+ inherit: true,
1652
1679
  cd: 0,
1653
1680
  mode: 0,
1654
1681
  alias: [],
@@ -1657,6 +1684,7 @@ var init_default = __esm({
1657
1684
  },
1658
1685
  {
1659
1686
  key: "Bot:selfId",
1687
+ inherit: true,
1660
1688
  cd: 0,
1661
1689
  mode: 0,
1662
1690
  alias: [],
@@ -1665,6 +1693,7 @@ var init_default = __esm({
1665
1693
  },
1666
1694
  {
1667
1695
  key: "Bot:selfId:userId",
1696
+ inherit: true,
1668
1697
  cd: 0,
1669
1698
  mode: 0,
1670
1699
  alias: [],
@@ -3040,7 +3069,7 @@ var init_fs2 = __esm({
3040
3069
  init_fs();
3041
3070
  }
3042
3071
  });
3043
- var diffArray, diffSimpleArray, clamp, random, formatNumber, percentage, formatUnit, isEven, average, round;
3072
+ var diffArray, diffSimpleArray, clamp, random, formatNumber, percentage, formatUnit, isEven, average, round, isNumber, isNumberInArray;
3044
3073
  var init_number = __esm({
3045
3074
  "src/utils/common/number.ts"() {
3046
3075
  diffArray = (old, data) => {
@@ -3089,6 +3118,17 @@ var init_number = __esm({
3089
3118
  round = (num, decimals = 0) => {
3090
3119
  return Number(Math.round(Number(num + "e" + decimals)) + "e-" + decimals);
3091
3120
  };
3121
+ isNumber = (num, defaultValue = 0) => {
3122
+ if (typeof num === "number") return num;
3123
+ return defaultValue;
3124
+ };
3125
+ isNumberInArray = (arr, defaultValue = 0) => {
3126
+ for (let i = 0; i < arr.length; i++) {
3127
+ const item = arr[i];
3128
+ if (typeof item === "number") return item;
3129
+ }
3130
+ return defaultValue;
3131
+ };
3092
3132
  }
3093
3133
  });
3094
3134
  var TypedListeners, listeners;
@@ -3469,7 +3509,7 @@ var init_exec = __esm({
3469
3509
  });
3470
3510
 
3471
3511
  // src/utils/config/tools.ts
3472
- var formatArray, initCount, formatObject, mergeDegAndCfg, createCount, getCacheCfg, clearCache;
3512
+ var formatArray, initCount, formatObject, createCount, getCacheCfg, clearCache;
3473
3513
  var init_tools = __esm({
3474
3514
  "src/utils/config/tools.ts"() {
3475
3515
  formatArray = (data) => {
@@ -3501,22 +3541,6 @@ var init_tools = __esm({
3501
3541
  });
3502
3542
  return list2;
3503
3543
  };
3504
- mergeDegAndCfg = (def, cfg) => {
3505
- const list2 = {};
3506
- Object.entries(cfg).forEach(([key, value]) => {
3507
- if (Array.isArray(value)) {
3508
- list2[key] = formatArray(value || def[key]);
3509
- return;
3510
- }
3511
- if (typeof value === "number") {
3512
- value = Number(value);
3513
- list2[key] = isNaN(value) ? def[key] : value;
3514
- return;
3515
- }
3516
- list2[key] = value || def[key];
3517
- });
3518
- return list2;
3519
- };
3520
3544
  createCount = () => {
3521
3545
  return {};
3522
3546
  };
@@ -11565,18 +11589,27 @@ var init_race = __esm({
11565
11589
  "src/utils/request/race.ts"() {
11566
11590
  raceRequest = async (urls, config3 = {
11567
11591
  method: "HEAD",
11568
- timeout: 2e3
11592
+ timeout: 2e3,
11593
+ successCodes: [200]
11569
11594
  }) => {
11570
- const requests = urls.map(async (url) => {
11571
- try {
11572
- const response = await axios9.request({ ...config3, url, timeout: config3.timeout || 2e3 });
11573
- return response;
11574
- } catch {
11575
- return null;
11576
- }
11577
- });
11578
- const results = await Promise.race(requests);
11579
- return results;
11595
+ const successCodes = Array.isArray(config3.successCodes) && config3.successCodes.length > 0 ? config3.successCodes : [200];
11596
+ const requests = urls.map(
11597
+ (url) => new Promise((resolve, reject) => {
11598
+ axios9.request({ ...config3, url, timeout: config3.timeout || 2e3 }).then((response) => {
11599
+ if (successCodes.includes(response.status)) {
11600
+ resolve(response);
11601
+ } else {
11602
+ reject(new Error(`\u54CD\u5E94\u72B6\u6001\u7801 ${response.status} \u4E0D\u5728 successCodes \u8303\u56F4\u5185`));
11603
+ }
11604
+ }).catch(reject);
11605
+ })
11606
+ );
11607
+ try {
11608
+ const result = await Promise.any(requests);
11609
+ return result;
11610
+ } catch {
11611
+ return null;
11612
+ }
11580
11613
  };
11581
11614
  pingRequest = async (urls, config3 = {
11582
11615
  timeout: 2e3,
@@ -15442,10 +15475,10 @@ function requireLodash_isnumber() {
15442
15475
  function isObjectLike(value) {
15443
15476
  return !!value && typeof value == "object";
15444
15477
  }
15445
- function isNumber(value) {
15478
+ function isNumber2(value) {
15446
15479
  return typeof value == "number" || isObjectLike(value) && objectToString.call(value) == numberTag;
15447
15480
  }
15448
- lodash_isnumber = isNumber;
15481
+ lodash_isnumber = isNumber2;
15449
15482
  return lodash_isnumber;
15450
15483
  }
15451
15484
  function requireLodash_isplainobject() {
@@ -15594,7 +15627,7 @@ function requireSign() {
15594
15627
  const includes = requireLodash_includes();
15595
15628
  const isBoolean = requireLodash_isboolean();
15596
15629
  const isInteger = requireLodash_isinteger();
15597
- const isNumber = requireLodash_isnumber();
15630
+ const isNumber2 = requireLodash_isnumber();
15598
15631
  const isPlainObject = requireLodash_isplainobject();
15599
15632
  const isString = requireLodash_isstring();
15600
15633
  const once = requireLodash_once();
@@ -15626,9 +15659,9 @@ function requireSign() {
15626
15659
  allowInvalidAsymmetricKeyTypes: { isValid: isBoolean, message: '"allowInvalidAsymmetricKeyTypes" must be a boolean' }
15627
15660
  };
15628
15661
  const registered_claims_schema = {
15629
- iat: { isValid: isNumber, message: '"iat" should be a number of seconds' },
15630
- exp: { isValid: isNumber, message: '"exp" should be a number of seconds' },
15631
- nbf: { isValid: isNumber, message: '"nbf" should be a number of seconds' }
15662
+ iat: { isValid: isNumber2, message: '"iat" should be a number of seconds' },
15663
+ exp: { isValid: isNumber2, message: '"exp" should be a number of seconds' },
15664
+ nbf: { isValid: isNumber2, message: '"nbf" should be a number of seconds' }
15632
15665
  };
15633
15666
  function validate(schema, allowUnknown, object, parameterName) {
15634
15667
  if (!isPlainObject(object)) {
@@ -16221,7 +16254,6 @@ __export(config_exports, {
16221
16254
  initCount: () => initCount,
16222
16255
  initPm2: () => initPm2,
16223
16256
  master: () => master,
16224
- mergeDegAndCfg: () => mergeDegAndCfg,
16225
16257
  pkg: () => pkg,
16226
16258
  pm2: () => pm2,
16227
16259
  port: () => port,
@@ -16284,6 +16316,102 @@ var init_ffmpeg = __esm({
16284
16316
  }
16285
16317
  });
16286
16318
 
16319
+ // src/utils/common/string.ts
16320
+ var strToBool;
16321
+ var init_string = __esm({
16322
+ "src/utils/common/string.ts"() {
16323
+ strToBool = {
16324
+ /**
16325
+ * 将数组中的所有元素转换为字符串 使用`String`转换
16326
+ * @param arr 需要转换的数组
16327
+ * @returns 转换后的字符串
16328
+ * @example strToBool.array([1, '2']) // ['1', '2']
16329
+ * strToBool.array(['3', null, undefined, NaN, '']) // ['3']
16330
+ */
16331
+ array: (arr) => arr.map(String).filter((item) => item.length > 0),
16332
+ /**
16333
+ * 排除数组中所有非字符串的元素
16334
+ * @param arr 需要转换的数组
16335
+ * @returns 转换后的字符串
16336
+ * @example strToBool.arrayExcludeNonString(['1', '2', '3']) // ['1', '2', '3']
16337
+ * strToBool.arrayExcludeNonString(['1', '2', '3', null, undefined, NaN, '']) // ['1', '2', '3']
16338
+ */
16339
+ arrayExcludeNonString: (arr) => arr.filter((item) => typeof item === "string" && item.length > 0),
16340
+ /**
16341
+ * 将字符串转换为布尔值
16342
+ * @param str 需要转换的字符串
16343
+ * @returns 转换后的布尔值
16344
+ * @example strToBool.string('true') // true
16345
+ * strToBool.string('1') // true
16346
+ * strToBool.string('yes') // true
16347
+ * strToBool.string('on') // true
16348
+ * strToBool.string('false') // false
16349
+ * strToBool.string('0') // false
16350
+ * strToBool.string('no') // false
16351
+ */
16352
+ string: (str) => str === "true" || str === "1" || str === "yes" || str === "on",
16353
+ /**
16354
+ * 将字符串转换为数字
16355
+ * @param str 需要转换的字符串
16356
+ * @param defaultValue 默认值 如果非数字 返回默认值
16357
+ * @returns 转换后的数字
16358
+ * @example strToBool.number('1') // 1
16359
+ * strToBool.number('2') // 2
16360
+ * strToBool.number('3') // 3
16361
+ * strToBool.number('abc', 123) // 123
16362
+ */
16363
+ number: (str, defaultValue = 0) => {
16364
+ const num = Number(str);
16365
+ if (typeof num === "number") return num;
16366
+ return defaultValue;
16367
+ },
16368
+ /**
16369
+ * 将字符串数组转换为数字数组
16370
+ * @param arr 需要转换的数组
16371
+ * @returns 转换后的数字数组
16372
+ * @example strToBool.arrayNumber(['1', '2', '3']) // [1, 2, 3]
16373
+ */
16374
+ arrayNumber: (arr) => {
16375
+ const list2 = [];
16376
+ for (const str of arr) {
16377
+ const num = Number(str);
16378
+ if (typeof num === "number") list2.push(num);
16379
+ }
16380
+ return list2;
16381
+ },
16382
+ /**
16383
+ * 传入一个数组 按照索引返回数组 并且将这个数组转换为字符串数组 去掉重复、非字符串的元素
16384
+ * @param arr 需要转换的数组
16385
+ * @param index 需要返回的索引
16386
+ * @returns 转换后的字符串数组
16387
+ * @example strToBool.arrayString(['1', '2', '3'], 0) // ['1']
16388
+ */
16389
+ arrayString: (arr) => {
16390
+ for (const item of arr) {
16391
+ if (!Array.isArray(item)) continue;
16392
+ return strToBool.arrayExcludeNonString(item);
16393
+ }
16394
+ return [];
16395
+ },
16396
+ /**
16397
+ * 合并多个数组为一个并去重 如果不是数组将会跳过
16398
+ * @param arr 需要合并的数组
16399
+ * @returns 合并后的数组
16400
+ * @example strToBool.mergeArray(['1', '2', '3'], ['4', '5', '6']) // ['1', '2', '3', '4', '5', '6']
16401
+ * strToBool.mergeArray(['4', '5', '6'], ['4', '5', '6']) // ['4', '5', '6']
16402
+ */
16403
+ mergeArray: (...arr) => {
16404
+ const list2 = [];
16405
+ for (const item of arr) {
16406
+ if (!Array.isArray(item)) continue;
16407
+ list2.push(...item);
16408
+ }
16409
+ return [...new Set(list2)];
16410
+ }
16411
+ };
16412
+ }
16413
+ });
16414
+
16287
16415
  // src/utils/common/sleep.ts
16288
16416
  var sleep;
16289
16417
  var init_sleep = __esm({
@@ -16333,6 +16461,8 @@ __export(common_exports, {
16333
16461
  getRelPath: () => getRelPath,
16334
16462
  isDir: () => isDir,
16335
16463
  isEven: () => isEven,
16464
+ isNumber: () => isNumber,
16465
+ isNumberInArray: () => isNumberInArray,
16336
16466
  isPlugin: () => isPlugin,
16337
16467
  karinToQQBot: () => karinToQQBot,
16338
16468
  makeForward: () => makeForward,
@@ -16350,6 +16480,7 @@ __export(common_exports, {
16350
16480
  round: () => round,
16351
16481
  sleep: () => sleep,
16352
16482
  splitPath: () => splitPath,
16483
+ strToBool: () => strToBool,
16353
16484
  stream: () => stream,
16354
16485
  updateYaml: () => updateYaml,
16355
16486
  uptime: () => uptime2,
@@ -16366,6 +16497,7 @@ var init_common = __esm({
16366
16497
  init_list();
16367
16498
  init_time();
16368
16499
  init_number();
16500
+ init_string();
16369
16501
  init_sleep();
16370
16502
  init_uptime();
16371
16503
  init_file2();
@@ -16773,6 +16905,7 @@ var init_groups4 = __esm({
16773
16905
  init_fs2();
16774
16906
  init_listeners();
16775
16907
  init_default();
16908
+ init_common();
16776
16909
  init_tools();
16777
16910
  count = createCount();
16778
16911
  getCfg = (keys) => getCacheCfg(dynamicCache, count, keys);
@@ -16790,11 +16923,47 @@ var init_groups4 = __esm({
16790
16923
  return format2(list2);
16791
16924
  };
16792
16925
  format2 = (data) => {
16926
+ const defaultGlobal = defaultConfig.groups[1];
16927
+ const defaultGroup = defaultConfig.groups[0];
16928
+ const userGlobal = data.find((item) => item.key === "global") || defaultGlobal;
16929
+ const userGroup = data.find((item) => item.key === "default") || defaultGroup;
16930
+ const merge = (key, inherit, ...args) => {
16931
+ if (typeof inherit !== "boolean") {
16932
+ inherit = true;
16933
+ }
16934
+ let alias = args.map((item) => item.alias);
16935
+ let enable = args.map((item) => item.enable);
16936
+ let disable = args.map((item) => item.disable);
16937
+ let memberEnable = args.map((item) => item.member_enable);
16938
+ let memberDisable = args.map((item) => item.member_disable);
16939
+ if (inherit && args.length === 3) {
16940
+ alias = [strToBool.mergeArray(alias[0], alias[1]), alias[2]];
16941
+ enable = [strToBool.mergeArray(enable[0], enable[1]), enable[2]];
16942
+ disable = [strToBool.mergeArray(disable[0], disable[1]), disable[2]];
16943
+ memberEnable = [strToBool.mergeArray(memberEnable[0], memberEnable[1]), memberEnable[2]];
16944
+ memberDisable = [strToBool.mergeArray(memberDisable[0], memberDisable[1]), memberDisable[2]];
16945
+ }
16946
+ return {
16947
+ key,
16948
+ inherit,
16949
+ cd: isNumberInArray(args.map((item) => item.cd), 0),
16950
+ userCD: isNumberInArray(args.map((item) => item.userCD), 0),
16951
+ mode: isNumberInArray(args.map((item) => item.mode), 0),
16952
+ alias: strToBool.arrayString(alias),
16953
+ enable: strToBool.arrayString(enable),
16954
+ disable: strToBool.arrayString(disable),
16955
+ member_enable: strToBool.arrayString(memberEnable),
16956
+ member_disable: strToBool.arrayString(memberDisable)
16957
+ };
16958
+ };
16959
+ const global2 = merge("global", true, userGlobal, defaultGlobal);
16960
+ const def = merge("default", true, userGroup, defaultGroup);
16793
16961
  const kv = {
16794
- default: defaultConfig.groups[0]
16962
+ global: global2,
16963
+ default: def
16795
16964
  };
16796
- data.forEach((value) => {
16797
- kv[value.key] = mergeDegAndCfg(kv.default, value);
16965
+ data.forEach((item) => {
16966
+ kv[item.key] = merge(item.key, item.inherit, item, kv.global, kv.default);
16798
16967
  });
16799
16968
  return kv;
16800
16969
  };
@@ -16823,6 +16992,7 @@ var init_groups4 = __esm({
16823
16992
  `Bot:${selfId}:${groupId}`,
16824
16993
  `Bot:${selfId}`,
16825
16994
  groupId,
16995
+ "global",
16826
16996
  "default"
16827
16997
  ];
16828
16998
  return getCfg(keys);
@@ -16834,6 +17004,7 @@ var init_groups4 = __esm({
16834
17004
  `Bot:${selfId}`,
16835
17005
  guildId,
16836
17006
  channelId,
17007
+ "global",
16837
17008
  "default"
16838
17009
  ];
16839
17010
  return getCfg(keys);
@@ -16855,6 +17026,7 @@ var init_privates = __esm({
16855
17026
  init_fs2();
16856
17027
  init_listeners();
16857
17028
  init_default();
17029
+ init_common();
16858
17030
  init_tools();
16859
17031
  count2 = createCount();
16860
17032
  getCfg2 = (keys) => getCacheCfg(dynamicCache2, count2, keys);
@@ -16872,11 +17044,40 @@ var init_privates = __esm({
16872
17044
  return format3(list2);
16873
17045
  };
16874
17046
  format3 = (data) => {
17047
+ const defaultGlobal = defaultConfig.privates[1];
17048
+ const defaultPrivates = defaultConfig.privates[0];
17049
+ const userGlobal = data.find((item) => item.key === "global") || defaultGlobal;
17050
+ const userPrivates = data.find((item) => item.key === "default") || defaultPrivates;
17051
+ const merge = (key, inherit, ...args) => {
17052
+ if (typeof inherit !== "boolean") {
17053
+ inherit = true;
17054
+ }
17055
+ let alias = args.map((item) => item.alias);
17056
+ let enable = args.map((item) => item.enable);
17057
+ let disable = args.map((item) => item.disable);
17058
+ if (inherit && args.length === 3) {
17059
+ alias = [strToBool.mergeArray(alias[0], alias[1]), alias[2]];
17060
+ enable = [strToBool.mergeArray(enable[0], enable[1]), enable[2]];
17061
+ disable = [strToBool.mergeArray(disable[0], disable[1]), disable[2]];
17062
+ }
17063
+ return {
17064
+ key,
17065
+ inherit,
17066
+ cd: isNumberInArray(args.map((item) => item.cd), 0),
17067
+ mode: isNumberInArray(args.map((item) => item.mode), 0),
17068
+ alias: strToBool.arrayString(alias),
17069
+ enable: strToBool.arrayString(enable),
17070
+ disable: strToBool.arrayString(disable)
17071
+ };
17072
+ };
17073
+ const global2 = merge("global", true, userGlobal, defaultGlobal);
17074
+ const def = merge("default", true, userPrivates, defaultPrivates);
16875
17075
  const kv = {
16876
- default: defaultConfig.privates[0]
17076
+ global: global2,
17077
+ default: def
16877
17078
  };
16878
17079
  data.forEach((value) => {
16879
- kv[value.key] = mergeDegAndCfg(kv.default, value);
17080
+ kv[value.key] = merge(value.key, value.inherit, value, kv.global, kv.default);
16880
17081
  });
16881
17082
  return kv;
16882
17083
  };
@@ -16897,11 +17098,11 @@ var init_privates = __esm({
16897
17098
  };
16898
17099
  privates = () => dynamicCache2;
16899
17100
  getFriendCfg = (userId, selfId) => {
16900
- const keys = [`Bot:${selfId}:${userId}`, `Bot:${selfId}`, userId, "default"];
17101
+ const keys = [`Bot:${selfId}:${userId}`, `Bot:${selfId}`, userId, "global", "default"];
16901
17102
  return getCfg2(keys);
16902
17103
  };
16903
17104
  getDirectCfg = (userId, selfId) => {
16904
- const keys = [`Bot:${selfId}:${userId}`, `Bot:${selfId}`, userId, "default"];
17105
+ const keys = [`Bot:${selfId}:${userId}`, `Bot:${selfId}`, userId, "global", "default"];
16905
17106
  return getCfg2(keys);
16906
17107
  };
16907
17108
  getPrivatesFileData = (dir2) => {
@@ -1,3 +1,4 @@
1
+ import fs from 'node:fs';
1
2
  import net from 'node:net';
2
3
  import path from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
@@ -11,7 +12,13 @@ var isClosing = false;
11
12
  var minRestartInterval = 5e3;
12
13
  var _filename = fileURLToPath(import.meta.url);
13
14
  var _dirname = path.dirname(_filename);
14
- var indexPath = path.join(_dirname, import.meta.url.includes(".mjs") ? "app.mjs" : "app.ts");
15
+ var getMainPath = () => {
16
+ const filePath = path.join(_dirname, import.meta.url.includes(".mjs") ? "app.mjs" : "app.ts");
17
+ if (fs.existsSync(filePath)) {
18
+ return filePath;
19
+ }
20
+ return path.join(process.cwd(), "node_modules", "node-karin", "dist", "start", "app.mjs");
21
+ };
15
22
  var start = () => {
16
23
  if (isStart) {
17
24
  console.log("\u5B50\u8FDB\u7A0B\u5DF2\u5728\u8FD0\u884C\u4E2D\uFF0CPID:", child.pid);
@@ -19,7 +26,7 @@ var start = () => {
19
26
  }
20
27
  isStart = true;
21
28
  lastStartTime = Date.now();
22
- child = fork(indexPath);
29
+ child = fork(getMainPath());
23
30
  child.on("message", (message) => {
24
31
  const { port, type, token } = JSON.parse(message) || {};
25
32
  if (type === "restart") {
@@ -0,0 +1 @@
1
+ import{j as t}from"./vendor-react-Hg1DVPZt.js";import{P as r}from"./components-CdSkN0A-.js";import"./vendor-others-B6NXaB-r.js";import"./vendor-editor-B8hjWfkw.js";import"./vendor-ui-utils-5rYIvRjL.js";import"./vendor-heroui-DQJWydu5.js";import"./page-dashboard-aHcz3vqD.js";import"./hooks-DosuTLqt.js";import"./utils-Bla5NKbq.js";import"./vendor-visual-mzxhMYK3.js";const x=()=>t.jsx("div",{className:"min-h-screen flex items-center justify-center",children:t.jsx(r,{})});export{x as default};
@@ -1,2 +1,2 @@
1
- import{V as p}from"./vendor-react-Hg1DVPZt.js";import{a5 as g}from"./components-AQsFMN7-.js";const k=async(t,n,e,r)=>{const{setIsLogModalOpen:i,setTaskId:c,setTaskLogs:o,setTaskName:f}=n;f("更新插件");const a=["开始创建更新任务...",`options: ${JSON.stringify(t)}`];o(a);try{const s=await g(t);if(s.success&&s.taskId)c(s.taskId),o([...a,`
1
+ import{V as p}from"./vendor-react-Hg1DVPZt.js";import{a5 as g}from"./components-CdSkN0A-.js";const k=async(t,n,e,r)=>{const{setIsLogModalOpen:i,setTaskId:c,setTaskLogs:o,setTaskName:f}=n;f("更新插件");const a=["开始创建更新任务...",`options: ${JSON.stringify(t)}`];o(a);try{const s=await g(t);if(s.success&&s.taskId)c(s.taskId),o([...a,`
2
2
  任务创建成功!`,`任务ID: ${s.taskId}`,"正在连接任务执行日志..."]),i(!0),typeof e=="function"&&e(),typeof r=="function"&&r();else throw new Error(s.message||"未知错误")}catch(s){console.error("更新失败:",s),p.error(`更新失败: ${s.message}`)}};export{k as c};
@@ -14,17 +14,17 @@
14
14
  content="viewport-fit=cover, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
15
15
  name="viewport" />
16
16
  <link href="/web/assets/ico/favicon-BoqZd694.ico" rel="icon" />
17
- <script type="module" crossorigin src="/web/assets/js/entry-UpjOQl3S.js"></script>
17
+ <script type="module" crossorigin src="/web/assets/js/entry-Dj9BegRo.js"></script>
18
18
  <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-editor-B8hjWfkw.js">
19
19
  <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-others-B6NXaB-r.js">
20
20
  <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-ui-utils-5rYIvRjL.js">
21
21
  <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-react-Hg1DVPZt.js">
22
- <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-heroui-BYc15sbq.js">
23
- <link rel="modulepreload" crossorigin href="/web/assets/js/hooks-C1liScQm.js">
22
+ <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-heroui-DQJWydu5.js">
23
+ <link rel="modulepreload" crossorigin href="/web/assets/js/hooks-DosuTLqt.js">
24
24
  <link rel="modulepreload" crossorigin href="/web/assets/js/vendor-visual-mzxhMYK3.js">
25
- <link rel="modulepreload" crossorigin href="/web/assets/js/components-AQsFMN7-.js">
26
- <link rel="modulepreload" crossorigin href="/web/assets/js/utils-C1_eVtU6.js">
27
- <link rel="modulepreload" crossorigin href="/web/assets/js/page-dashboard-BMR0KJUA.js">
25
+ <link rel="modulepreload" crossorigin href="/web/assets/js/components-CdSkN0A-.js">
26
+ <link rel="modulepreload" crossorigin href="/web/assets/js/utils-Bla5NKbq.js">
27
+ <link rel="modulepreload" crossorigin href="/web/assets/js/page-dashboard-aHcz3vqD.js">
28
28
  <link rel="stylesheet" crossorigin href="/web/assets/css/vendor-editor-CFbL2ovg.css">
29
29
  <link rel="stylesheet" crossorigin href="/web/assets/css/vendor-others-ZgkIHsf0.css">
30
30
  <link rel="stylesheet" crossorigin href="/web/assets/css/components-ep7vm38G.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",
@@ -1 +0,0 @@
1
- import{j as t}from"./vendor-react-Hg1DVPZt.js";import{P as r}from"./components-AQsFMN7-.js";import"./vendor-others-B6NXaB-r.js";import"./vendor-editor-B8hjWfkw.js";import"./vendor-ui-utils-5rYIvRjL.js";import"./vendor-heroui-BYc15sbq.js";import"./page-dashboard-BMR0KJUA.js";import"./hooks-C1liScQm.js";import"./utils-C1_eVtU6.js";import"./vendor-visual-mzxhMYK3.js";const x=()=>t.jsx("div",{className:"min-h-screen flex items-center justify-center",children:t.jsx(r,{})});export{x as default};