node-karin 0.5.1 → 0.6.2

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.
@@ -129,6 +129,18 @@ export const common = new (class Common {
129
129
  }
130
130
  }
131
131
 
132
+ /**
133
+ * - 解析json文件
134
+ */
135
+ readJson (file) {
136
+ try {
137
+ return JSON.parse(fs.readFileSync(file, 'utf8'))
138
+ } catch (error) {
139
+ logger.error('读取json文件错误:' + error)
140
+ return null
141
+ }
142
+ }
143
+
132
144
  /**
133
145
  * 根据文件后缀名从指定路径下读取符合要求的文件
134
146
  * @param path - 路径
@@ -15,9 +15,10 @@ export declare const config: {
15
15
  initCfg(): Promise<void>;
16
16
  getPlugins(): string[];
17
17
  /**
18
- * 检查路径是否存在 不存在则创建
18
+ * 递归创建目录
19
+ * @param dirname - 要创建的文件夹路径
19
20
  */
20
- checkPath(path: string): void;
21
+ mkdir(dirname: string): boolean;
21
22
  /**
22
23
  * 为每一个插件建立对应的文件夹
23
24
  */
@@ -1,3 +1,4 @@
1
+ import path from 'path'
1
2
  import { karinDir } from '../core/dir.js'
2
3
  import { fs, yaml as Yaml, chokidar } from '../modules.js'
3
4
  /**
@@ -33,7 +34,7 @@ export const config = new (class Cfg {
33
34
  './plugins',
34
35
  './plugins/karin-plugin-example',
35
36
  ]
36
- list.forEach(path => this.checkPath(path))
37
+ list.forEach(path => this.mkdir(path))
37
38
  if (this.npmCfgDir !== (this._path + '/defSet').replace(/\\/g, '/')) {
38
39
  const files = fs.readdirSync(this.npmCfgDir).filter(file => file.endsWith('.yaml'))
39
40
  files.forEach(file => {
@@ -58,10 +59,14 @@ export const config = new (class Cfg {
58
59
  }
59
60
 
60
61
  /**
61
- * 检查路径是否存在 不存在则创建
62
+ * 递归创建目录
63
+ * @param dirname - 要创建的文件夹路径
62
64
  */
63
- checkPath (path) {
64
- if (!fs.existsSync(path)) { fs.mkdirSync(path) }
65
+ mkdir (dirname) {
66
+ if (fs.existsSync(dirname)) { return true }
67
+ /** 递归自调用 */
68
+ if (this.mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
69
+ return true
65
70
  }
66
71
 
67
72
  /**
@@ -69,10 +74,10 @@ export const config = new (class Cfg {
69
74
  */
70
75
  async dirPath (name, plugins) {
71
76
  name = `./${name}`
72
- this.checkPath(name)
77
+ this.mkdir(name)
73
78
  for (const plugin of plugins) {
74
79
  const path = `${name}/${plugin}`
75
- this.checkPath(path)
80
+ this.mkdir(path)
76
81
  }
77
82
  }
78
83
 
@@ -57,7 +57,7 @@ export declare const segment: {
57
57
  /**
58
58
  * - 图片子类型
59
59
  */
60
- sub_type?: number;
60
+ sub_type?: string;
61
61
  /**
62
62
  * - 图片宽度
63
63
  */
@@ -84,6 +84,7 @@ export declare const segment: {
84
84
  * @param md5 - 语音md5
85
85
  * @param name - 语音名称
86
86
  * @returns {VoiceElement} 语音元素
87
+ * @deprecated 即将废弃 请使用segment.record
87
88
  */
88
89
  voice(file: string, magic?: boolean, md5?: string, name?: string): VoiceElement;
89
90
  /**
@@ -129,7 +130,7 @@ export declare const segment: {
129
130
  * @param pic - 封面
130
131
  * @returns {CustomMusicElemen} 自定义音乐元素
131
132
  */
132
- customMusic(url: string, audio: string, title: string, author: string, pic: string): CustomMusicElemen;
133
+ customMusic(url: string, audio: string, title: string, author: string, pic: string, id: string): CustomMusicElemen;
133
134
  /**
134
135
  * 音乐
135
136
  * @param platform - 音乐平台
@@ -77,7 +77,7 @@ export const segment = new (class Segment {
77
77
  const file_type = options.file_type || 'original'
78
78
  const name = options.name || ''
79
79
  const md5 = options.md5 || ''
80
- const sub_type = options.sub_type || 0
80
+ const sub_type = options.sub_type || ''
81
81
  const width = options.width || 0
82
82
  const height = options.height || 0
83
83
  return {
@@ -118,6 +118,7 @@ export const segment = new (class Segment {
118
118
  * @param md5 - 语音md5
119
119
  * @param name - 语音名称
120
120
  * @returns {VoiceElement} 语音元素
121
+ * @deprecated 即将废弃 请使用segment.record
121
122
  */
122
123
  voice (file, magic = false, md5 = '', name = '') {
123
124
  return {
@@ -206,7 +207,7 @@ export const segment = new (class Segment {
206
207
  * @param pic - 封面
207
208
  * @returns {CustomMusicElemen} 自定义音乐元素
208
209
  */
209
- customMusic (url, audio, title, author, pic) {
210
+ customMusic (url, audio, title, author, pic, id) {
210
211
  return {
211
212
  type: 'music',
212
213
  platform: 'custom',
@@ -215,6 +216,7 @@ export const segment = new (class Segment {
215
216
  title,
216
217
  author,
217
218
  pic,
219
+ id,
218
220
  }
219
221
  }
220
222
 
package/modules.d.ts CHANGED
@@ -11,4 +11,5 @@ import { Level as level } from 'level';
11
11
  import schedule from 'node-schedule';
12
12
  import yaml from 'yaml';
13
13
  import log4js from 'log4js';
14
- export { fs, ws, path, axios, lodash, moment, express, chalk, chokidar, level, schedule, yaml, log4js, };
14
+ import art_template from 'art-template';
15
+ export { fs, ws, path, axios, lodash, moment, express, chalk, chokidar, level, schedule, yaml, log4js, art_template, };
package/modules.js CHANGED
@@ -11,4 +11,5 @@ import { Level as level } from 'level';
11
11
  import schedule from 'node-schedule';
12
12
  import yaml from 'yaml';
13
13
  import log4js from 'log4js';
14
- export { fs, ws, path, axios, lodash, moment, express, chalk, chokidar, level, schedule, yaml, log4js, };
14
+ import art_template from 'art-template';
15
+ export { fs, ws, path, axios, lodash, moment, express, chalk, chokidar, level, schedule, yaml, log4js, art_template, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.5.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -14,9 +14,6 @@
14
14
  "license": "GPL-3.0-only",
15
15
  "author": "Karin",
16
16
  "type": "module",
17
- "imports": {
18
- "#Karin": "./lib/index.js"
19
- },
20
17
  "main": "./lib/index.js",
21
18
  "types": "./lib/index.d.ts",
22
19
  "bin": {
@@ -42,6 +39,7 @@
42
39
  "cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js",
43
40
  "delete": "pm2 delete ./config/config/pm2.yaml",
44
41
  "dev": "tsx ./lib/index.js --dev",
42
+ "debug": "tsx watch ./lib/index.js --dev",
45
43
  "fix": "eslint lib/**/*.js --fix",
46
44
  "fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.ts --fix",
47
45
  "init": "node lib/tools/install.js",
@@ -65,7 +63,7 @@
65
63
  "chalk": "5.3.0",
66
64
  "chokidar": "3.6.0",
67
65
  "express": "4.19.2",
68
- "kritor-proto": "^1.0.1",
66
+ "kritor-proto": "^1.0.2",
69
67
  "level": "8.0.1",
70
68
  "lodash": "4.17.21",
71
69
  "log4js": "6.9.1",