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.
- package/lib/adapter/index.d.ts +4 -0
- package/lib/adapter/index.js +4 -0
- package/lib/adapter/input/index.d.ts +2 -2
- package/lib/adapter/input/index.js +3 -2
- package/lib/adapter/kritor/grpc.d.ts +33 -0
- package/lib/adapter/kritor/grpc.js +981 -0
- package/lib/adapter/kritor/index.d.ts +391 -0
- package/lib/adapter/kritor/index.js +1164 -0
- package/lib/adapter/onebot/onebot11.d.ts +7 -9
- package/lib/adapter/onebot/onebot11.js +22 -23
- package/lib/core/dir.d.ts +3 -0
- package/lib/core/dir.js +3 -0
- package/lib/core/plugin.loader.js +13 -1
- package/lib/core/server.js +2 -2
- package/lib/event/index.d.ts +2 -0
- package/lib/event/index.js +2 -2
- package/lib/event/message.d.ts +5 -1
- package/lib/event/message.js +2 -2
- package/lib/event/notice.handler.js +8 -8
- package/lib/event/request.handler.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/modules.d.ts +2 -1
- package/lib/modules.js +2 -1
- package/lib/tools/init.js +8 -10
- package/lib/types/adapter.d.ts +3 -4
- package/lib/types/element.d.ts +3 -1
- package/lib/types/event.d.ts +17 -21
- package/lib/utils/common.d.ts +4 -0
- package/lib/utils/common.js +12 -0
- package/lib/utils/config.d.ts +3 -2
- package/lib/utils/config.js +11 -6
- package/lib/utils/segment.d.ts +3 -2
- package/lib/utils/segment.js +4 -2
- package/modules.d.ts +2 -1
- package/modules.js +2 -1
- package/package.json +3 -5
package/lib/utils/common.js
CHANGED
|
@@ -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 - 路径
|
package/lib/utils/config.d.ts
CHANGED
|
@@ -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
|
-
|
|
21
|
+
mkdir(dirname: string): boolean;
|
|
21
22
|
/**
|
|
22
23
|
* 为每一个插件建立对应的文件夹
|
|
23
24
|
*/
|
package/lib/utils/config.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
64
|
-
if (
|
|
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.
|
|
77
|
+
this.mkdir(name)
|
|
73
78
|
for (const plugin of plugins) {
|
|
74
79
|
const path = `${name}/${plugin}`
|
|
75
|
-
this.
|
|
80
|
+
this.mkdir(path)
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
package/lib/utils/segment.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export declare const segment: {
|
|
|
57
57
|
/**
|
|
58
58
|
* - 图片子类型
|
|
59
59
|
*/
|
|
60
|
-
sub_type?:
|
|
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 - 音乐平台
|
package/lib/utils/segment.js
CHANGED
|
@@ -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 ||
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
66
|
+
"kritor-proto": "^1.0.2",
|
|
69
67
|
"level": "8.0.1",
|
|
70
68
|
"lodash": "4.17.21",
|
|
71
69
|
"log4js": "6.9.1",
|