node-karin 0.6.23 → 0.6.25

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/README.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  基于 [Kritor](https://github.com/KarinJS/kritor-kotlin) 标准进行开发的 [nodejs](https://nodejs.org/en) 机器人框架
6
6
 
7
- > 本项目正在开发中,不建议用于生产环境
7
+ > 本项目正在开发中,现阶段我并不能为你解决任何问题,谨慎使用。
8
+ > 此项目不想成为、代替任何项目,也没有这个能力,请别造谣。
9
+ > ~~不欢迎某些人,勿扰谢谢(ps: )~~
8
10
 
9
11
  ---
10
12
 
@@ -19,21 +21,18 @@
19
21
  - [x] 支持被动ws
20
22
  - [ ] 支持onebot HTTP
21
23
  - [x] 支持[onebots](https://github.com/lc-cn/onebots)
22
- - [x] ~~puppeteer渲染图片~~
23
24
  - [x] 外置[puppeteer](https://github.com/KarinJS/karin-plugin-puppeteer)
24
- - [ ] 降低对`redis`的依赖
25
- - [ ] 支持 package.karin
26
- - [ ] 支持db通用接口
27
- - [ ] 支持动态加载插件
25
+ - [x] 降低对`redis`的依赖,开始逐渐抛弃redis
26
+ - [x] 支持 package.karin
27
+ - [ ] ~~支持db通用接口~~
28
+ - [ ] ~~支持动态加载插件~~
28
29
  - [x] 支持`redis`集群
29
30
 
30
- > 关于`puppeteer`,由于内置的chrome过于臃肿,将会移除内置的pupppeteer,分开搭建或使用远程、作为插件等方式使用puppeteer。
31
- > [karin-puppeteer](https://github.com/KarinJS/karin-puppeteer)
32
-
33
31
  ### 感谢
34
32
 
35
33
  Karin的开发离不开以下项目的帮助:
36
34
 
35
+ - [icqqjs](https://github.com/icqqjs)
37
36
  - [Kritor](https://github.com/KarinJS/kritor) Kritor标准
38
37
  - [OpenShamrock](https://github.com/whitechi73/OpenShamrock) Kritor标准Kotlin的实现
39
38
  - [onebots](https://github.com/lc-cn/onebots) onebots适配器
@@ -47,7 +46,6 @@ QQGroup: 967068507
47
46
 
48
47
  Discord: [☘Karin的喵趴~](https://discord.com/channels/1251552521957408878/1251552521957408881)
49
48
 
50
-
51
49
  ### 贡献者
52
50
 
53
51
  > 🌟星光闪烁,你们的智慧如同璀璨的夜空。感谢所有为**Karin**做出贡献的人!
@@ -99,7 +99,7 @@ export class OB11Event {
99
99
  role: "unknown" /* Role.Unknown */,
100
100
  };
101
101
  const contact = {
102
- scene: ('group_id' in data ? 'group' : 'friend'),
102
+ scene: 'group_id' in data ? "group" /* Scene.Group */ : "friend" /* Scene.Private */,
103
103
  peer: 'group_id' in data ? data.group_id : data.user_id,
104
104
  sub_peer: '',
105
105
  };
@@ -324,6 +324,8 @@ export class OB11Event {
324
324
  // todo kritor没有这个事件
325
325
  this.adapter.logger('info', `[群荣誉变更]:${JSON.stringify(data)}`);
326
326
  break;
327
+ default:
328
+ return this.adapter.logger('error', '未知通知事件:', JSON.stringify(data));
327
329
  }
328
330
  break;
329
331
  case 'group_msg_emoji_like': {
@@ -353,6 +355,11 @@ export class OB11Event {
353
355
  return this.adapter.logger('error', '未知通知事件:', JSON.stringify(data));
354
356
  }
355
357
  }
358
+ notice.bot = this.adapter;
359
+ /**
360
+ * 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
361
+ */
362
+ notice.replyCallback = async (elements) => await this.adapter.SendMessage(notice.contact, elements);
356
363
  listener.emit('notice', notice);
357
364
  }
358
365
  /** 请求事件 */
@@ -383,6 +390,11 @@ export class OB11Event {
383
390
  message: data.comment,
384
391
  },
385
392
  });
393
+ request.bot = this.adapter;
394
+ /**
395
+ * 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
396
+ */
397
+ request.replyCallback = async (elements) => await this.adapter.SendMessage(request.contact, elements);
386
398
  listener.emit('request', request);
387
399
  return;
388
400
  }
@@ -414,6 +426,11 @@ export class OB11Event {
414
426
  message: data.comment,
415
427
  },
416
428
  });
429
+ request.bot = this.adapter;
430
+ /**
431
+ * 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
432
+ */
433
+ request.replyCallback = async (elements) => await this.adapter.SendMessage(request.contact, elements);
417
434
  listener.emit('request', request);
418
435
  return;
419
436
  }
@@ -85,7 +85,7 @@ declare class PluginLoader {
85
85
  /**
86
86
  * 获取所有插件
87
87
  */
88
- getPlugins(): `karin-plugin-${string}`[];
88
+ getPlugins(): Promise<string[]>;
89
89
  /**
90
90
  * 获取指定文件夹下的所有插件
91
91
  * @param dir - 插件包名称
@@ -102,8 +102,9 @@ declare class PluginLoader {
102
102
  * @param dir - 插件包路径
103
103
  * @param name - 插件名称
104
104
  * @param isOrderBy - 是否为动态导入 默认为静态导入
105
+ * @param isNpm - 是否为npm包
105
106
  */
106
- createdApp(dir: dirName, name: fileName, isOrderBy?: boolean): Promise<boolean>;
107
+ createdApp(dir: dirName, name: fileName, isOrderBy?: boolean, isNpm?: boolean): Promise<boolean>;
107
108
  /**
108
109
  * 新增rule
109
110
  */
@@ -84,7 +84,7 @@ class PluginLoader {
84
84
  * 插件初始化
85
85
  */
86
86
  async load () {
87
- this.getPlugins()
87
+ await this.getPlugins()
88
88
  listener.once('plugin.watch', () => {
89
89
  for (const v of this.watchList) {
90
90
  v.name ? this.watch(v.dir, v.name) : this.watchDir(v.dir)
@@ -95,6 +95,10 @@ class PluginLoader {
95
95
  logger.info('加载插件中..')
96
96
  /** 载入插件 */
97
97
  const promises = this.FileList.map(async ({ dir, name }) => await this.createdApp(dir, name, false))
98
+ /** 获取npm插件 */
99
+ const npm = await common.getNpmPlugins(true)
100
+ /** 载入npm插件 */
101
+ promises.push(...npm.map(async ({ dir, name }) => await this.createdApp(dir, name, false, true)))
98
102
  /** 等待所有插件加载完成 */
99
103
  await Promise.all(promises)
100
104
  /** 释放缓存 */
@@ -108,7 +112,7 @@ class PluginLoader {
108
112
  /**
109
113
  * 获取所有插件
110
114
  */
111
- getPlugins () {
115
+ async getPlugins () {
112
116
  /** 获取所有插件包 */
113
117
  const plugins = common.getPlugins()
114
118
  for (const dir of plugins) {
@@ -247,11 +251,12 @@ class PluginLoader {
247
251
  * @param dir - 插件包路径
248
252
  * @param name - 插件名称
249
253
  * @param isOrderBy - 是否为动态导入 默认为静态导入
254
+ * @param isNpm - 是否为npm包
250
255
  */
251
- async createdApp (dir, name, isOrderBy = false) {
256
+ async createdApp (dir, name, isOrderBy = false, isNpm = false) {
252
257
  try {
253
258
  const list = []
254
- let path = `${this.dirPath}plugins/${dir}/${name}`
259
+ let path = `${this.dirPath}${isNpm ? 'node_modules ' : 'plugins'}/${dir}/${name}`
255
260
  if (isOrderBy) { path = path + `?${Date.now()}` }
256
261
  const tmp = await import(path)
257
262
  lodash.forEach(tmp, (App) => {
package/lib/index.js CHANGED
@@ -1,8 +1,3 @@
1
- /// <reference types="@types/express" />
2
- /// <reference types="@types/lodash" />
3
- /// <reference types="@types/node" />
4
- /// <reference types="@types/node-schedule" />
5
- /// <reference types="@types/ws" />
6
1
  // 基本模块
7
2
  export * from 'kritor-proto';
8
3
  export * from './core/index.js';
@@ -6,8 +6,10 @@ import { KarinNoticeType, KarinRequestType, AllListenEvent, KarinEventTypes, Kar
6
6
  * - 插件根目录名称
7
7
  * - 例如: karin-plugin-example
8
8
  * - 例如: karin-plugin-example/apps
9
+ * - ### npm包类型: `string`
10
+ * - ### git插件类型: `karin-plugin-${string}`
9
11
  */
10
- export type dirName = `karin-plugin-${string}`;
12
+ export type dirName = `karin-plugin-${string}` | string;
11
13
  /**
12
14
  * - 插件名称
13
15
  * - 例如: index.js index.ts
@@ -1,7 +1,7 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { Readable } from 'stream';
3
3
  import { fs } from '../modules.js';
4
- import { dirName, KarinElement, NodeElement } from '../types/index.js';
4
+ import { dirName, fileName, KarinElement, NodeElement } from '../types/index.js';
5
5
  /**
6
6
  * 常用方法
7
7
  */
@@ -131,15 +131,24 @@ export declare const common: {
131
131
  /**
132
132
  * 制作简单转发,返回segment.node[]。仅简单包装node,也可以自己组装
133
133
  * @param elements
134
- * @param fakeUin 用户id
135
- * @param fakeNick 用户昵称
134
+ * @param fakeUin 转发用户的QQ号 必填
135
+ * @param fakeNick 转发用户显示的昵称 必填
136
136
  */
137
137
  makeForward(elements: KarinElement | KarinElement[], fakeUin: string, fakeNick: string): Array<NodeElement>;
138
138
  /**
139
- * 获取所有插件列表
139
+ * 获取git插件列表
140
140
  * @param isPack - 是否屏蔽不带package.json的插件,默认为false
141
141
  */
142
142
  getPlugins(isPack?: boolean): Array<dirName>;
143
+ /**
144
+ * 获取npm插件列表
145
+ * @param showDetails - 是否返回详细信息,默认为false
146
+ * 默认只返回插件npm包名,为true时返回详细的{dir, name}[]
147
+ */
148
+ getNpmPlugins<T extends boolean>(showDetails: T): Promise<T extends true ? {
149
+ dir: string;
150
+ name: fileName;
151
+ }[] : string[]>;
143
152
  /**
144
153
  * 获取运行时间
145
154
  */
@@ -352,8 +352,8 @@ export const common = new (class Common {
352
352
  /**
353
353
  * 制作简单转发,返回segment.node[]。仅简单包装node,也可以自己组装
354
354
  * @param elements
355
- * @param fakeUin 用户id
356
- * @param fakeNick 用户昵称
355
+ * @param fakeUin 转发用户的QQ号 必填
356
+ * @param fakeNick 转发用户显示的昵称 必填
357
357
  */
358
358
  makeForward (elements, fakeUin, fakeNick) {
359
359
  if (!Array.isArray(elements)) { elements = [elements] }
@@ -364,7 +364,7 @@ export const common = new (class Common {
364
364
  }
365
365
 
366
366
  /**
367
- * 获取所有插件列表
367
+ * 获取git插件列表
368
368
  * @param isPack - 是否屏蔽不带package.json的插件,默认为false
369
369
  */
370
370
  getPlugins (isPack = false) {
@@ -378,6 +378,57 @@ export const common = new (class Common {
378
378
  return arr
379
379
  }
380
380
 
381
+ /**
382
+ * 获取npm插件列表
383
+ * @param showDetails - 是否返回详细信息,默认为false
384
+ * 默认只返回插件npm包名,为true时返回详细的{dir, name}[]
385
+ */
386
+ async getNpmPlugins (showDetails) {
387
+ /** 屏蔽的依赖包列表 */
388
+ const pkgdependencies = [
389
+ '@grpc/grpc-js',
390
+ '@grpc/proto-loader',
391
+ 'art-template',
392
+ 'axios',
393
+ 'chalk',
394
+ 'chokidar',
395
+ 'express',
396
+ 'kritor-proto',
397
+ 'level',
398
+ 'lodash',
399
+ 'log4js',
400
+ 'moment',
401
+ 'node-schedule',
402
+ 'redis',
403
+ 'ws',
404
+ 'yaml',
405
+ ]
406
+ const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
407
+ const dependencies = Object.keys(pkg.dependencies).filter((name) => !pkgdependencies.includes(name))
408
+ if (!showDetails) {
409
+ return dependencies
410
+ } else {
411
+ const list = []
412
+ const readPackageJson = async (name) => {
413
+ try {
414
+ const pkgPath = path.join(process.cwd(), 'node_modules', name, 'package.json')
415
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
416
+ if (pkg?.karin && pkg?.karin?.apps?.length) {
417
+ pkg.karin.apps.forEach((app) => {
418
+ fs.readdirSync(`./node_modules/${name}/${app}`).forEach((dir) => {
419
+ /** 忽略非js */
420
+ if (!dir.endsWith('.js')) { return }
421
+ list.push({ dir, name })
422
+ })
423
+ })
424
+ }
425
+ } catch { }
426
+ }
427
+ await Promise.all(dependencies.map(readPackageJson))
428
+ return list
429
+ }
430
+ }
431
+
381
432
  /**
382
433
  * 获取运行时间
383
434
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.6.23",
3
+ "version": "0.6.25",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -49,9 +49,8 @@
49
49
  "sort": "npx sort-package-json"
50
50
  },
51
51
  "dependencies": {
52
- "@grpc/grpc-js": "1.10.10",
52
+ "@grpc/grpc-js": "1.10.11",
53
53
  "@grpc/proto-loader": "0.7.13",
54
- "@inquirer/prompts": "5.1.2",
55
54
  "art-template": "4.13.2",
56
55
  "axios": "1.7.2",
57
56
  "chalk": "5.3.0",
@@ -64,8 +63,8 @@
64
63
  "moment": "2.30.1",
65
64
  "node-schedule": "2.1.1",
66
65
  "redis": "4.6.14",
67
- "ws": "8.16.0",
68
- "yaml": "2.4.1"
66
+ "ws": "8.18.0",
67
+ "yaml": "2.4.5"
69
68
  },
70
69
  "devDependencies": {
71
70
  "@types/express": "latest",