node-karin 0.3.9 → 0.5.0
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/config/defSet/config.yaml +11 -0
- package/lib/adapter/input/index.d.ts +63 -0
- package/lib/adapter/input/index.js +188 -0
- package/lib/adapter/onebot/onebot11.d.ts +12 -138
- package/lib/adapter/onebot/onebot11.js +70 -50
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +1 -0
- package/lib/core/karin.d.ts +45 -4
- package/lib/core/karin.js +52 -1
- package/lib/core/listener.js +6 -2
- package/lib/core/plugin.app.d.ts +4 -1
- package/lib/core/plugin.app.js +3 -3
- package/lib/core/plugin.d.ts +8 -2
- package/lib/core/plugin.loader.d.ts +7 -0
- package/lib/core/plugin.loader.js +49 -12
- package/lib/core/server.js +26 -0
- package/lib/db/index.d.ts +2 -4
- package/lib/db/index.js +2 -4
- package/lib/db/level.d.ts +1 -0
- package/lib/db/level.js +1 -0
- package/lib/db/redis.d.ts +2 -41
- package/lib/db/redis.js +2 -3
- package/lib/event/event.d.ts +7 -3
- package/lib/event/event.handler.d.ts +7 -6
- package/lib/event/event.handler.js +6 -1
- package/lib/event/event.js +6 -1
- package/lib/event/index.js +2 -2
- package/lib/event/message.handler.d.ts +3 -3
- package/lib/event/message.handler.js +8 -11
- package/lib/event/notice.d.ts +4 -4
- package/lib/event/notice.handler.d.ts +17 -0
- package/lib/event/notice.handler.js +203 -0
- package/lib/event/request.d.ts +4 -4
- package/lib/event/request.handler.d.ts +17 -0
- package/lib/event/request.handler.js +109 -0
- package/lib/event/request.js +1 -0
- package/lib/event/review.handler.js +12 -24
- package/lib/index.d.ts +2 -1
- package/lib/types/adapter.d.ts +3 -2
- package/lib/types/api.d.ts +295 -0
- package/lib/types/api.js +1 -0
- package/lib/types/config.d.ts +21 -0
- package/lib/types/event.d.ts +127 -241
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/plugin.d.ts +4 -4
- package/lib/utils/button.d.ts +2 -2
- package/lib/utils/common.d.ts +5 -6
- package/lib/utils/common.js +3 -4
- package/lib/utils/config.d.ts +5 -2
- package/lib/utils/config.js +43 -17
- package/lib/utils/handler.d.ts +5 -12
- package/lib/utils/handler.js +3 -1
- package/lib/utils/yamlEditor.d.ts +1 -1
- package/package.json +4 -3
- package/lib/utils/kritor-proto.d.ts +0 -1
package/lib/utils/config.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fs, yaml as Yaml, chokidar } from '../modules.js'
|
|
|
6
6
|
export const config = new (class Cfg {
|
|
7
7
|
dir
|
|
8
8
|
_path
|
|
9
|
-
|
|
9
|
+
npmCfgDir
|
|
10
10
|
change
|
|
11
11
|
watcher
|
|
12
12
|
review
|
|
@@ -14,7 +14,7 @@ export const config = new (class Cfg {
|
|
|
14
14
|
constructor () {
|
|
15
15
|
this.dir = karinDir
|
|
16
16
|
this._path = process.cwd() + '/config'
|
|
17
|
-
this.
|
|
17
|
+
this.npmCfgDir = this.dir + '/config/defSet'
|
|
18
18
|
/** 缓存 */
|
|
19
19
|
this.change = new Map()
|
|
20
20
|
/** 监听文件 */
|
|
@@ -26,18 +26,23 @@ export const config = new (class Cfg {
|
|
|
26
26
|
|
|
27
27
|
/** 初始化配置 */
|
|
28
28
|
async initCfg () {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
const list = [
|
|
30
|
+
this._path,
|
|
31
|
+
this._path + '/config',
|
|
32
|
+
process.cwd() + '/temp/input',
|
|
33
|
+
'./plugins',
|
|
34
|
+
'./plugins/karin-plugin-example',
|
|
35
|
+
]
|
|
36
|
+
list.forEach(path => this.checkPath(path))
|
|
37
|
+
if (this.npmCfgDir !== (this._path + '/defSet').replace(/\\/g, '/')) {
|
|
38
|
+
const files = fs.readdirSync(this.npmCfgDir).filter(file => file.endsWith('.yaml'))
|
|
39
|
+
files.forEach(file => {
|
|
40
|
+
const path = `${this._path}/config/${file}`
|
|
41
|
+
const pathDef = `${this.npmCfgDir}/${file}`
|
|
42
|
+
if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
|
|
43
|
+
})
|
|
37
44
|
}
|
|
38
45
|
// 创建插件文件夹文件夹
|
|
39
|
-
if (!fs.existsSync('./plugins')) { fs.mkdirSync('./plugins') }
|
|
40
|
-
if (!fs.existsSync('./plugins/karin-plugin-example')) { fs.mkdirSync('./plugins/karin-plugin-example') }
|
|
41
46
|
const plugins = this.getPlugins()
|
|
42
47
|
this.dirPath('data', plugins)
|
|
43
48
|
this.dirPath('temp', plugins)
|
|
@@ -52,15 +57,22 @@ export const config = new (class Cfg {
|
|
|
52
57
|
return files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-'))).map(dir => dir.name)
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
/**
|
|
61
|
+
* 检查路径是否存在 不存在则创建
|
|
62
|
+
*/
|
|
63
|
+
checkPath (path) {
|
|
64
|
+
if (!fs.existsSync(path)) { fs.mkdirSync(path) }
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
/**
|
|
56
68
|
* 为每一个插件建立对应的文件夹
|
|
57
69
|
*/
|
|
58
70
|
async dirPath (name, plugins) {
|
|
59
71
|
name = `./${name}`
|
|
60
|
-
|
|
72
|
+
this.checkPath(name)
|
|
61
73
|
for (const plugin of plugins) {
|
|
62
74
|
const path = `${name}/${plugin}`
|
|
63
|
-
|
|
75
|
+
this.checkPath(path)
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
|
|
@@ -90,7 +102,6 @@ export const config = new (class Cfg {
|
|
|
90
102
|
|
|
91
103
|
/**
|
|
92
104
|
* 主人列表
|
|
93
|
-
* @returns {string[]}
|
|
94
105
|
*/
|
|
95
106
|
get master () {
|
|
96
107
|
return this.Config.master || []
|
|
@@ -130,9 +141,24 @@ export const config = new (class Cfg {
|
|
|
130
141
|
const config = this.getYaml('config', 'config', true)
|
|
131
142
|
const defSet = this.getYaml('defSet', 'config', false)
|
|
132
143
|
const data = { ...defSet, ...config }
|
|
144
|
+
const Config = {
|
|
145
|
+
...data,
|
|
146
|
+
WhiteList: {
|
|
147
|
+
users: data.WhiteList.users.map((i) => String(i)),
|
|
148
|
+
groups: data.WhiteList.groups.map((i) => String(i)),
|
|
149
|
+
GroupMsgLog: data.WhiteList.GroupMsgLog.map((i) => String(i)),
|
|
150
|
+
},
|
|
151
|
+
BlackList: {
|
|
152
|
+
users: data.BlackList.users.map((i) => String(i)),
|
|
153
|
+
groups: data.BlackList.groups.map((i) => String(i)),
|
|
154
|
+
GroupMsgLog: data.BlackList.GroupMsgLog.map((i) => String(i)),
|
|
155
|
+
},
|
|
156
|
+
master: data.master.map((i) => String(i)),
|
|
157
|
+
admin: data.admin.map((i) => String(i)),
|
|
158
|
+
}
|
|
133
159
|
/** 缓存 */
|
|
134
|
-
this.change.set(key,
|
|
135
|
-
return
|
|
160
|
+
this.change.set(key, Config)
|
|
161
|
+
return Config
|
|
136
162
|
}
|
|
137
163
|
|
|
138
164
|
/**
|
package/lib/utils/handler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventType, PluginType } from '../types/index.js';
|
|
1
|
+
import { EventType, PluginType, PluginApps } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* 事件处理器类
|
|
4
4
|
*/
|
|
@@ -8,21 +8,14 @@ export declare const handler: {
|
|
|
8
8
|
* @param index 插件索引
|
|
9
9
|
* @param Class 插件类
|
|
10
10
|
*/
|
|
11
|
-
add(index: string, Class: PluginType): void;
|
|
11
|
+
add(index: string, Class: PluginType | PluginApps): void;
|
|
12
12
|
/**
|
|
13
13
|
* 删除事件处理器
|
|
14
14
|
* 如果不传参数则删除所有处理器
|
|
15
|
+
* @param index 插件索引
|
|
16
|
+
* @param key 事件键
|
|
15
17
|
*/
|
|
16
|
-
del(
|
|
17
|
-
/**
|
|
18
|
-
* 插件索引
|
|
19
|
-
*/
|
|
20
|
-
index: string | "";
|
|
21
|
-
/**
|
|
22
|
-
* 事件键
|
|
23
|
-
*/
|
|
24
|
-
key: string | "";
|
|
25
|
-
}): boolean;
|
|
18
|
+
del(index?: string, key?: string): boolean;
|
|
26
19
|
/**
|
|
27
20
|
* 调用事件处理器
|
|
28
21
|
* @param key 事件键
|
package/lib/utils/handler.js
CHANGED
|
@@ -24,8 +24,10 @@ export const handler = new (class EventHandler {
|
|
|
24
24
|
/**
|
|
25
25
|
* 删除事件处理器
|
|
26
26
|
* 如果不传参数则删除所有处理器
|
|
27
|
+
* @param index 插件索引
|
|
28
|
+
* @param key 事件键
|
|
27
29
|
*/
|
|
28
|
-
del (
|
|
30
|
+
del (index = '', key = '') {
|
|
29
31
|
/** 无参 */
|
|
30
32
|
if (!key && !index) {
|
|
31
33
|
loader.handlerIds = {}
|
|
@@ -14,7 +14,7 @@ export declare class YamlEditor {
|
|
|
14
14
|
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
15
15
|
* @param value - 要设置的值
|
|
16
16
|
*/
|
|
17
|
-
set(path: string | string[], value: string): null | undefined;
|
|
17
|
+
set(path: string | string[], value: string | boolean): null | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* 向指定路径添加新值
|
|
20
20
|
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "基于 Kritor 进行开发的nodejs机器人框架",
|
|
6
6
|
"homepage": "https://github.com/KarinJS/Karin",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"app": "node .",
|
|
41
41
|
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run fix && npm run cp",
|
|
42
|
-
"cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js
|
|
42
|
+
"cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js",
|
|
43
43
|
"delete": "pm2 delete ./config/config/pm2.yaml",
|
|
44
44
|
"dev": "tsx ./lib/index.js --dev",
|
|
45
45
|
"fix": "eslint lib/**/*.js --fix",
|
|
46
|
-
"fix:all": "eslint lib/**/*.js --fix && eslint
|
|
46
|
+
"fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.ts --fix",
|
|
47
47
|
"init": "node lib/tools/install.js",
|
|
48
48
|
"init:dev": "node lib/tools/install.js",
|
|
49
49
|
"init:pack": "node lib/tools/install.js",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@grpc/grpc-js": "1.10.10",
|
|
61
61
|
"@grpc/proto-loader": "0.7.13",
|
|
62
|
+
"@inquirer/prompts": "^5.0.7",
|
|
62
63
|
"art-template": "4.13.2",
|
|
63
64
|
"axios": "1.7.2",
|
|
64
65
|
"chalk": "5.3.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'kritor-proto'
|