node-karin 1.9.2 → 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,26 @@
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
+
17
+ ## [1.9.3](https://github.com/KarinJS/Karin/compare/core-v1.9.2...core-v1.9.3) (2025-05-17)
18
+
19
+
20
+ ### 🐛 Bug Fixes
21
+
22
+ * close [#439](https://github.com/KarinJS/Karin/issues/439) close [#438](https://github.com/KarinJS/Karin/issues/438) ([ea5db12](https://github.com/KarinJS/Karin/commit/ea5db1280a8468a37075dbc94b24fa14ac6757fa))
23
+
3
24
  ## [1.9.2](https://github.com/KarinJS/Karin/compare/core-v1.9.1...core-v1.9.2) (2025-05-12)
4
25
 
5
26
 
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from 'events';
2
2
  import * as events from 'events';
3
3
  import chalk__default from 'chalk';
4
- import { L as Logger } from './types-BJk0oTwW.js';
4
+ import { L as Logger } from './types-GyuTZPId.js';
5
5
 
6
6
  /**
7
7
  * 创建调试函数
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import EventEmitter from 'events';
2
2
  import * as chalk from 'chalk';
3
3
  export { basePath, commentPath, configPath, consolePath, dataPath, dbPath, defaultConfigPath, defaultViewPath, htmlPath, isPackaged, isPkg, karinDir, karinMain, karinPathBase, karinPathComment, karinPathConfig, karinPathConsole, karinPathData, karinPathDb, karinPathDefaultConfig, karinPathDefaultView, karinPathHtml, karinPathKv, karinPathLogs, karinPathMain, karinPathPlugins, karinPathPm2Config, karinPathRedisSqlite3, karinPathResource, karinPathRoot, karinPathSandboxData, karinPathSandboxTemp, karinPathTaskDb, karinPathTemp, kvPath, logsPath, pluginDir, pm2Path, redisSqlite3Path, resourcePath, sandboxDataPath, sandboxTempPath, tempPath } from './root.js';
4
- import { a as LogMethodNames, b as LoggerLevel, L as Logger } from './types-BJk0oTwW.js';
5
- export { D as DEFAULT_LOGGER_CONFIG, F as FileLogConfig, c as LogMethodsOnly, f as LogWriter, d as LoggerConfig, e as LoggerLevelPriority } from './types-BJk0oTwW.js';
4
+ import { a as LogMethodNames, b as LoggerLevel, L as Logger } from './types-GyuTZPId.js';
5
+ export { D as DEFAULT_LOGGER_CONFIG, F as FileLogConfig, c as LogMethodsOnly, f as LogWriter, d as LoggerConfig, e as LoggerLevelPriority } from './types-GyuTZPId.js';
6
6
  import sqlite3, { Database } from 'sqlite3';
7
7
  import schedule from 'node-schedule';
8
8
  import fs$1, { WriteStream } from 'node:fs';
@@ -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
  /**