node-karin 0.11.11 → 0.11.12

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.
@@ -34,3 +34,4 @@ export default class LevelDB extends Level {
34
34
  }
35
35
  }
36
36
  export const level = new LevelDB();
37
+ level.open();
@@ -1,5 +1,6 @@
1
1
  export default class RedisLevel {
2
2
  #private;
3
+ /** 唯一标识符 用于区分不同的数据库 */
3
4
  id: string;
4
5
  constructor();
5
6
  /**
@@ -1,23 +1,16 @@
1
1
  import { Level } from 'level';
2
2
  export default class RedisLevel {
3
3
  #level;
4
+ /** 过期时间映射表 */
4
5
  #expireMap;
6
+ /** 唯一标识符 用于区分不同的数据库 */
5
7
  id;
6
8
  constructor() {
7
9
  const path = process.cwd() + '/data/db/RedisLevel';
8
10
  this.#level = new Level(path, { valueEncoding: 'json' });
9
- /**
10
- * @type {'RedisLevel'} 唯一标识符 用于区分不同的数据库
11
- */
11
+ this.#level.open();
12
12
  this.id = 'RedisLevel';
13
- /**
14
- * 过期时间映射表
15
- * @type {Map<string, number>} 键: 值 (过期时间)
16
- */
17
13
  this.#expireMap = new Map();
18
- /**
19
- * 开启过期时间处理
20
- */
21
14
  this.#expireHandle();
22
15
  }
23
16
  /**
@@ -11,7 +11,7 @@ export interface NpmInfo {
11
11
  /**
12
12
  * 常用方法
13
13
  */
14
- declare class Common {
14
+ export declare class Common {
15
15
  streamPipeline: (stream1: Readable, stream2: fs.WriteStream) => Promise<void>;
16
16
  constructor();
17
17
  /**
@@ -187,6 +187,16 @@ declare class Common {
187
187
  * 获取运行时间
188
188
  */
189
189
  uptime(): string;
190
+ /**
191
+ * 传入一个时间戳
192
+ * 返回距今已过去的时间
193
+ * @param time - 时间戳
194
+ *
195
+ * @example
196
+ * common.formatTime(1620000000)
197
+ * // -> '18天'
198
+ */
199
+ formatTime(time: number): string;
190
200
  /**
191
201
  * 构建消息体日志
192
202
  * @param - 消息体
@@ -217,4 +227,3 @@ declare class Common {
217
227
  * 常用方法
218
228
  */
219
229
  export declare const common: Common;
220
- export {};
@@ -11,7 +11,7 @@ import { logger, segment, YamlEditor } from '../../utils/index.js';
11
11
  /**
12
12
  * 常用方法
13
13
  */
14
- class Common {
14
+ export class Common {
15
15
  streamPipeline;
16
16
  constructor() {
17
17
  this.streamPipeline = promisify(pipeline);
@@ -489,6 +489,27 @@ class Common {
489
489
  const parts = [day ? `${day}天` : '', hour ? `${hour}小时` : '', min ? `${min}分钟` : '', !day && sec ? `${sec}秒` : ''];
490
490
  return parts.filter(Boolean).join('');
491
491
  }
492
+ /**
493
+ * 传入一个时间戳
494
+ * 返回距今已过去的时间
495
+ * @param time - 时间戳
496
+ *
497
+ * @example
498
+ * common.formatTime(1620000000)
499
+ * // -> '18天'
500
+ */
501
+ formatTime(time) {
502
+ /** 判断是几位时间戳 进行对应处理 */
503
+ time = time.toString().length === 10 ? time * 1000 : time;
504
+ /** 减去当前时间 */
505
+ time = Math.floor((Date.now() - time) / 1000);
506
+ const day = Math.floor(time / 86400);
507
+ const hour = Math.floor((time % 86400) / 3600);
508
+ const min = Math.floor((time % 3600) / 60);
509
+ const sec = Math.floor(time % 60);
510
+ const parts = [day ? `${day}天` : '', hour ? `${hour}小时` : '', min ? `${min}分钟` : '', !day && sec ? `${sec}秒` : ''];
511
+ return parts.filter(Boolean).join('');
512
+ }
492
513
  /**
493
514
  * 构建消息体日志
494
515
  * @param - 消息体
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.11.11",
3
+ "version": "0.11.12",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",