node-karin 0.12.13 → 0.12.15

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.
Files changed (59) hide show
  1. package/lib/adapter/input/index.d.ts +1 -1
  2. package/lib/adapter/input/index.js +1 -1
  3. package/lib/adapter/onebot/11/event.js +90 -84
  4. package/lib/adapter/onebot/11/index.d.ts +89 -127
  5. package/lib/adapter/onebot/11/index.js +192 -254
  6. package/lib/cli/index.js +2 -2
  7. package/lib/core/init/config.js +1 -1
  8. package/lib/core/karin/karin.d.ts +21 -30
  9. package/lib/core/karin/karin.js +7 -9
  10. package/lib/core/listener/listener.js +11 -11
  11. package/lib/core/plugin/base.d.ts +7 -21
  12. package/lib/core/plugin/base.js +2 -6
  13. package/lib/core/plugin/loader.d.ts +5 -15
  14. package/lib/core/plugin/loader.js +5 -15
  15. package/lib/core/server/server.js +4 -4
  16. package/lib/event/handler/base.d.ts +1 -3
  17. package/lib/event/handler/base.js +1 -3
  18. package/lib/event/handler/message.js +9 -3
  19. package/lib/event/handler/notice.js +38 -32
  20. package/lib/event/handler/request.js +6 -6
  21. package/lib/index.d.ts +6 -0
  22. package/lib/index.js +6 -0
  23. package/lib/modules.d.ts +2 -2
  24. package/lib/modules.js +3 -2
  25. package/lib/types/adapter/accept.d.ts +24 -0
  26. package/lib/types/adapter/accept.js +1 -0
  27. package/lib/types/adapter/api.d.ts +88 -264
  28. package/lib/types/adapter/base.d.ts +3 -3
  29. package/lib/types/config/config.d.ts +4 -12
  30. package/lib/types/element/element.d.ts +119 -349
  31. package/lib/types/element/qqbot.d.ts +4 -12
  32. package/lib/types/event/contact.d.ts +6 -12
  33. package/lib/types/event/event.d.ts +59 -163
  34. package/lib/types/event/message.d.ts +11 -31
  35. package/lib/types/event/message.js +10 -12
  36. package/lib/types/event/notice.d.ts +118 -325
  37. package/lib/types/event/notice.js +8 -10
  38. package/lib/types/event/request.d.ts +29 -66
  39. package/lib/types/event/request.js +8 -10
  40. package/lib/types/event/sender.d.ts +7 -21
  41. package/lib/types/index.d.ts +1 -0
  42. package/lib/types/index.js +1 -0
  43. package/lib/types/onebot11/api.d.ts +49 -49
  44. package/lib/types/onebot11/event.d.ts +131 -347
  45. package/lib/types/onebot11/params.d.ts +184 -456
  46. package/lib/types/onebot11/response.d.ts +159 -381
  47. package/lib/types/onebot11/segment.d.ts +25 -75
  48. package/lib/types/onebot11/sender.d.ts +13 -39
  49. package/lib/types/plugin/app.d.ts +7 -11
  50. package/lib/types/plugin/plugin.d.ts +55 -165
  51. package/lib/types/render/render.d.ts +16 -48
  52. package/lib/utils/common/common.js +4 -2
  53. package/lib/utils/config/config.js +1 -1
  54. package/lib/utils/core/logger.js +3 -3
  55. package/lib/utils/core/segment.d.ts +28 -59
  56. package/lib/utils/core/segment.js +26 -30
  57. package/lib/utils/tools/restart.d.ts +3 -3
  58. package/lib/utils/tools/restart.js +5 -5
  59. package/package.json +1 -2
@@ -3,71 +3,39 @@ import chokidar from 'chokidar';
3
3
  * 渲染标准方法传参
4
4
  */
5
5
  export interface KarinRenderType {
6
- /**
7
- * - 渲染文件路径或HTTP地址 与vue二选一
8
- */
6
+ /** 渲染文件路径或HTTP地址 与vue二选一 */
9
7
  file: string;
10
- /**
11
- * - vue文件路径 与file二选一
12
- */
8
+ /** vue文件路径 与file二选一 */
13
9
  vue?: boolean;
14
10
  props?: any;
15
- /**
16
- * - 模板名称
17
- */
11
+ /** 模板名称 */
18
12
  name?: string;
19
- /**
20
- * - art-template后的文件名
21
- */
13
+ /** art-template后的文件名 */
22
14
  fileID?: string;
23
- /**
24
- * - 传递给模板的数据 template.render(data)
25
- */
15
+ /** 传递给模板的数据 template.render(data) */
26
16
  data?: object;
27
- /**
28
- * - 截图类型 默认'webp'
29
- */
17
+ /** 截图类型 默认'webp' */
30
18
  type?: 'png' | 'jpeg' | 'webp';
31
- /**
32
- * - 截图质量 默认90 1-100
33
- */
19
+ /** 截图质量 默认90 1-100 */
34
20
  quality?: number;
35
- /**
36
- * - 是否隐藏背景 默认false
37
- */
21
+ /** 是否隐藏背景 默认false */
38
22
  omitBackground?: boolean;
39
- /**
40
- * - 设置视窗大小和设备像素比 默认1920*1080、1
41
- */
23
+ /** 设置视窗大小和设备像素比 默认1920*1080、1 */
42
24
  setViewport?: {
43
- /**
44
- * - 视窗宽度
45
- */
25
+ /** 视窗宽度 */
46
26
  width?: number;
47
- /**
48
- * - 视窗高度
49
- */
27
+ /** 视窗高度 */
50
28
  height?: number;
51
- /**
52
- * - 设备像素比
53
- */
29
+ /** 设备像素比 */
54
30
  deviceScaleFactor?: number;
55
31
  };
56
- /**
57
- * - 分页截图 传递数字则视为视窗高度 返回数组
58
- */
32
+ /** 分页截图 传递数字则视为视窗高度 返回数组 */
59
33
  multiPage?: number | boolean;
60
- /**
61
- * - 页面goto时的参数
62
- */
34
+ /** 页面goto时的参数 */
63
35
  pageGotoParams?: {
64
- /**
65
- * - 页面加载超时时间
66
- */
36
+ /** 页面加载超时时间 */
67
37
  timeout?: number;
68
- /**
69
- * - 页面加载状态
70
- */
38
+ /** 页面加载状态 */
71
39
  waitUntil?: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
72
40
  [key: string]: any;
73
41
  };
@@ -464,8 +464,7 @@ export class Common {
464
464
  const hour = Math.floor((time % 86400) / 3600);
465
465
  const min = Math.floor((time % 3600) / 60);
466
466
  const sec = Math.floor(time % 60);
467
- const parts = [day ? `${day}天` : '', hour ? `${hour}小时` : '', min ? `${min}分钟` : '', !day && sec ? `${sec}秒` : ''];
468
- return parts.filter(Boolean).join('');
467
+ return `${day}天${hour}小时${min}分钟${sec}秒`.replace(/0[天时分秒]/g, '');
469
468
  }
470
469
  /**
471
470
  * 构建消息体日志
@@ -558,6 +557,9 @@ export class Common {
558
557
  case 'long_msg':
559
558
  logs.push(`[long_msg: ${val.id}]`);
560
559
  break;
560
+ case 'pasmsg':
561
+ logs.push(`[pasmsg: ${val.id}]`);
562
+ break;
561
563
  default:
562
564
  logs.push(`[未知: ${JSON.stringify(val)}]`);
563
565
  }
@@ -318,7 +318,7 @@ export const config = new (class Cfg {
318
318
  await this.#review();
319
319
  }
320
320
  async #review() {
321
- // 应该改成事件监听
321
+ // todo: 应该改成事件监听
322
322
  if (this.review)
323
323
  return;
324
324
  this.review = true;
@@ -5,9 +5,9 @@ import { config } from '../config/config.js';
5
5
  const logsDir = './logs';
6
6
  if (!fs.existsSync(logsDir))
7
7
  fs.mkdirSync(logsDir);
8
- const { log_level, log_days_Keep, log4jsCfg } = config.Config;
9
- const level = log_level || log4jsCfg.level || 'info';
10
- const daysToKeep = log_days_Keep || log4jsCfg.daysToKeep || 7;
8
+ const { log_level: logLevel, log_days_Keep: logDaysKeep, log4jsCfg } = config.Config;
9
+ const level = logLevel || log4jsCfg.level || 'info';
10
+ const daysToKeep = logDaysKeep || log4jsCfg.daysToKeep || 7;
11
11
  const { overall, fragments, maxLogSize } = log4jsCfg;
12
12
  const defaultOptions = { appenders: ['console'], level, enableCallStack: process.env.karin_app_mode === 'dev' };
13
13
  const options = {
@@ -1,4 +1,4 @@
1
- import { TextElement, AtElement, ImageElement, FaceElement, BubbleFaceElement, ReplyElement, VideoElement, BasketballElement, DiceElement, RpsElement, PokeElement, MusicElement, WeatherElement, LocationElement, ShareElement, GiftElement, MarketFaceElement, ForwardElement, ContactElement, JsonElement, XmlElement, FileElement, ButtonElement, CustomMusicElemen, TplMarkdownElement, RawMarkdownElement, NodeElement, KarinElement, LongMsgElement, RecordElement, KeyBoardElement, Button, RawElement } from '../../types/index.js';
1
+ import { TextElement, AtElement, ImageElement, FaceElement, BubbleFaceElement, ReplyElement, VideoElement, BasketballElement, DiceElement, RpsElement, PokeElement, MusicElement, WeatherElement, LocationElement, ShareElement, GiftElement, MarketFaceElement, ForwardElement, ContactElement, JsonElement, XmlElement, FileElement, ButtonElement, CustomMusicElemen, TplMarkdownElement, RawMarkdownElement, NodeElement, KarinElement, LongMsgElement, RecordElement, KeyBoardElement, Button, RawElement, PasmsgElement } from '../../types/index.js';
2
2
  export declare const segment: {
3
3
  /**
4
4
  * 纯文本
@@ -18,10 +18,10 @@ export declare const segment: {
18
18
  /**
19
19
  * 表情
20
20
  * @param id - 表情ID
21
- * @param is_big - 是否大表情,默认不是
21
+ * @param isBig - 是否大表情,默认不是
22
22
  * @returns {FaceElement} 表情元素
23
23
  */
24
- face(id: number, is_big?: boolean): FaceElement;
24
+ face(id: number, isBig?: boolean): FaceElement;
25
25
  /**
26
26
  * 弹射表情
27
27
  * @param id - 表情ID
@@ -31,10 +31,10 @@ export declare const segment: {
31
31
  bubble_face(id: number, count?: number): BubbleFaceElement;
32
32
  /**
33
33
  * 引用回复
34
- * @param message_id - 消息ID
34
+ * @param messageId - 消息ID
35
35
  * @returns {ReplyElement} 引用回复元素
36
36
  */
37
- reply(message_id: string): ReplyElement;
37
+ reply(messageId: string): ReplyElement;
38
38
  /**
39
39
  * 图片
40
40
  * - 一般情况提供一个file参数即可,其他参数一般为收到的消息中的参数
@@ -43,29 +43,17 @@ export declare const segment: {
43
43
  * @returns {ImageElement} 图片元素
44
44
  */
45
45
  image(file: string, options?: {
46
- /**
47
- * - 图片类型,show: 展示图片,flash: 闪照,original: 原图
48
- */
46
+ /** 图片类型,show: 展示图片,flash: 闪照,original: 原图 */
49
47
  file_type?: "show" | "flash" | "original";
50
- /**
51
- * - 图片名称
52
- */
48
+ /** 图片名称 */
53
49
  name?: string;
54
- /**
55
- * - 图片MD5
56
- */
50
+ /** 图片MD5 */
57
51
  md5?: string;
58
- /**
59
- * - 图片子类型
60
- */
52
+ /** 图片子类型 */
61
53
  sub_type?: string;
62
- /**
63
- * - 图片宽度
64
- */
54
+ /** 图片宽度 */
65
55
  width?: number;
66
- /**
67
- * - 图片高度
68
- */
56
+ /** 图片高度 */
69
57
  height?: number;
70
58
  }): ImageElement;
71
59
  /**
@@ -113,11 +101,11 @@ export declare const segment: {
113
101
  /**
114
102
  * 戳一戳
115
103
  * @param id - 戳一戳ID
116
- * @param poke_type - 戳一戳类型
104
+ * @param pokeType - 戳一戳类型
117
105
  * @param strength - 戳一戳强度(1-5 默认1)
118
106
  * @returns {PokeElement} 戳一戳元素
119
107
  */
120
- poke(id: number, poke_type: number, strength?: number): PokeElement;
108
+ poke(id: number, pokeType: number, strength?: number): PokeElement;
121
109
  /**
122
110
  * 自定义音乐
123
111
  * @param url - 跳转链接
@@ -175,13 +163,13 @@ export declare const segment: {
175
163
  marketFace(id: string): MarketFaceElement;
176
164
  /**
177
165
  * 转发
178
- * @param res_id - 资源ID
166
+ * @param resId - 资源ID
179
167
  * @param uniseq - 序列号(可能不对?)
180
168
  * @param summary - 摘要
181
169
  * @param description - 描述
182
170
  * @returns {ForwardElement} 转发元素
183
171
  */
184
- forward(res_id: string, uniseq?: string, summary?: string, description?: string): ForwardElement;
172
+ forward(resId: string, uniseq?: string, summary?: string, description?: string): ForwardElement;
185
173
  /**
186
174
  * 分享名片
187
175
  * @param scene - 分享类型
@@ -205,37 +193,21 @@ export declare const segment: {
205
193
  * 文件
206
194
  */
207
195
  file(options: {
208
- /**
209
- * - 文件URL
210
- */
196
+ /** 文件URL */
211
197
  url: string;
212
- /**
213
- * - 文件名称
214
- */
198
+ /** 文件名称 */
215
199
  name?: string;
216
- /**
217
- * - 文件大小
218
- */
200
+ /** 文件大小 */
219
201
  size?: number;
220
- /**
221
- * - 文件过期时间
222
- */
202
+ /** 文件过期时间 */
223
203
  expire_time?: number;
224
- /**
225
- * - 文件ID
226
- */
204
+ /** 文件ID */
227
205
  id?: string;
228
- /**
229
- * - 未知
230
- */
206
+ /** 未知 */
231
207
  biz?: number;
232
- /**
233
- * - 文件子ID
234
- */
208
+ /** 文件子ID */
235
209
  sub_id?: string;
236
- /**
237
- * - 文件MD5
238
- */
210
+ /** 文件MD5 */
239
211
  md5?: string;
240
212
  }): FileElement;
241
213
  /**
@@ -251,10 +223,10 @@ export declare const segment: {
251
223
  markdown(content: RawMarkdownElement["content"], config?: RawMarkdownElement["config"]): RawMarkdownElement;
252
224
  /**
253
225
  * 构建模板Markdown
254
- * @param custom_template_id - 模板ID
226
+ * @param customTemplateId - 模板ID
255
227
  * @param params - 模板markdown参数
256
228
  */
257
- markdown_tpl(custom_template_id: TplMarkdownElement["custom_template_id"], params: TplMarkdownElement["params"]): TplMarkdownElement;
229
+ markdown_tpl(customTemplateId: TplMarkdownElement["custom_template_id"], params: TplMarkdownElement["params"]): TplMarkdownElement;
258
230
  /**
259
231
  * 按钮 构建单行单个(obj)、多个按钮(obj[])
260
232
  * @param data - 按钮数据
@@ -268,11 +240,11 @@ export declare const segment: {
268
240
  keyboard(data: Array<Button> | Array<Array<Button>>): KeyBoardElement;
269
241
  /**
270
242
  * 转发自定义节点
271
- * @param user_id - 用户ID
243
+ * @param userId - 用户ID
272
244
  * @param nickname - 用户昵称
273
245
  * @param content - 节点内容
274
246
  */
275
- node(user_id: string, nickname: string, content: KarinElement | Array<KarinElement>): NodeElement;
247
+ node(userId: string, nickname: string, content: KarinElement | Array<KarinElement>): NodeElement;
276
248
  /**
277
249
  * 发送原生格式给予适配器处理
278
250
  * @param data - 原生数据
@@ -281,8 +253,5 @@ export declare const segment: {
281
253
  /**
282
254
  * 回复被动消息
283
255
  */
284
- passive_reply(id: string): {
285
- type: "passive_reply";
286
- id: string;
287
- };
256
+ pasmsg(id: string): PasmsgElement;
288
257
  };
@@ -29,14 +29,14 @@ export const segment = new (class Segment {
29
29
  /**
30
30
  * 表情
31
31
  * @param id - 表情ID
32
- * @param is_big - 是否大表情,默认不是
32
+ * @param isBig - 是否大表情,默认不是
33
33
  * @returns {FaceElement} 表情元素
34
34
  */
35
- face(id, is_big = false) {
35
+ face(id, isBig = false) {
36
36
  return {
37
37
  type: 'face',
38
38
  id: Number(id),
39
- is_big,
39
+ is_big: isBig,
40
40
  };
41
41
  }
42
42
  /**
@@ -54,13 +54,13 @@ export const segment = new (class Segment {
54
54
  }
55
55
  /**
56
56
  * 引用回复
57
- * @param message_id - 消息ID
57
+ * @param messageId - 消息ID
58
58
  * @returns {ReplyElement} 引用回复元素
59
59
  */
60
- reply(message_id) {
60
+ reply(messageId) {
61
61
  return {
62
62
  type: 'reply',
63
- message_id: message_id + '',
63
+ message_id: messageId + '',
64
64
  };
65
65
  }
66
66
  /**
@@ -71,19 +71,19 @@ export const segment = new (class Segment {
71
71
  * @returns {ImageElement} 图片元素
72
72
  */
73
73
  image(file, options = {}) {
74
- const file_type = options.file_type || 'original';
74
+ const fileType = options.file_type || 'original';
75
75
  const name = options.name || '';
76
76
  const md5 = options.md5 || '';
77
- const sub_type = options.sub_type || '';
77
+ const subType = options.sub_type || '';
78
78
  const width = options.width || 0;
79
79
  const height = options.height || 0;
80
80
  return {
81
81
  type: 'image',
82
82
  file,
83
- file_type,
83
+ file_type: fileType,
84
84
  name,
85
85
  md5,
86
- sub_type,
86
+ sub_type: subType,
87
87
  width,
88
88
  height,
89
89
  };
@@ -171,15 +171,15 @@ export const segment = new (class Segment {
171
171
  /**
172
172
  * 戳一戳
173
173
  * @param id - 戳一戳ID
174
- * @param poke_type - 戳一戳类型
174
+ * @param pokeType - 戳一戳类型
175
175
  * @param strength - 戳一戳强度(1-5 默认1)
176
176
  * @returns {PokeElement} 戳一戳元素
177
177
  */
178
- poke(id, poke_type, strength = 1) {
178
+ poke(id, pokeType, strength = 1) {
179
179
  return {
180
180
  type: 'poke',
181
181
  id,
182
- poke_type,
182
+ poke_type: pokeType,
183
183
  strength,
184
184
  };
185
185
  }
@@ -290,16 +290,16 @@ export const segment = new (class Segment {
290
290
  }
291
291
  /**
292
292
  * 转发
293
- * @param res_id - 资源ID
293
+ * @param resId - 资源ID
294
294
  * @param uniseq - 序列号(可能不对?)
295
295
  * @param summary - 摘要
296
296
  * @param description - 描述
297
297
  * @returns {ForwardElement} 转发元素
298
298
  */
299
- forward(res_id, uniseq, summary, description) {
299
+ forward(resId, uniseq, summary, description) {
300
300
  return {
301
301
  type: 'forward',
302
- res_id,
302
+ res_id: resId,
303
303
  uniseq: uniseq || '',
304
304
  summary: summary || '',
305
305
  description: description || '',
@@ -381,21 +381,17 @@ export const segment = new (class Segment {
381
381
  }
382
382
  /**
383
383
  * 构建模板Markdown
384
- * @param custom_template_id - 模板ID
384
+ * @param customTemplateId - 模板ID
385
385
  * @param params - 模板markdown参数
386
386
  */
387
387
  markdown_tpl(
388
- /**
389
- * - 模板ID
390
- */
391
- custom_template_id,
392
- /**
393
- * - 模板markdown参数
394
- */
388
+ /** 模板ID */
389
+ customTemplateId,
390
+ /** 模板markdown参数 */
395
391
  params) {
396
392
  return {
397
393
  type: 'markdown_tpl',
398
- custom_template_id,
394
+ custom_template_id: customTemplateId,
399
395
  params,
400
396
  };
401
397
  }
@@ -436,14 +432,14 @@ export const segment = new (class Segment {
436
432
  }
437
433
  /**
438
434
  * 转发自定义节点
439
- * @param user_id - 用户ID
435
+ * @param userId - 用户ID
440
436
  * @param nickname - 用户昵称
441
437
  * @param content - 节点内容
442
438
  */
443
- node(user_id, nickname, content) {
439
+ node(userId, nickname, content) {
444
440
  return {
445
441
  type: 'node',
446
- user_id,
442
+ user_id: userId,
447
443
  nickname,
448
444
  content,
449
445
  };
@@ -461,9 +457,9 @@ export const segment = new (class Segment {
461
457
  /**
462
458
  * 回复被动消息
463
459
  */
464
- passive_reply(id) {
460
+ pasmsg(id) {
465
461
  return {
466
- type: 'passive_reply',
462
+ type: 'pasmsg',
467
463
  id,
468
464
  };
469
465
  }
@@ -1,12 +1,12 @@
1
1
  import { Contact } from '../../types/index.js';
2
2
  /**
3
3
  * 重启Bot
4
- * @param self_id - 机器人的id 传e.self_id
4
+ * @param selfId - 机器人的id 传e.self_id
5
5
  * @param contact - 事件联系人信息 也就是从哪来的这条消息 传e.contact即可
6
- * @param message_id - 消息id 传e.message_id
6
+ * @param messageId - 消息id 传e.message_id
7
7
  * @param isFront - 是否为前台重启 默认是
8
8
  */
9
- export declare const restart: (self_id: string, contact: Contact, message_id: string, isFront?: boolean) => Promise<{
9
+ export declare const restart: (selfId: string, contact: Contact, messageId: string, isFront?: boolean) => Promise<{
10
10
  status: string;
11
11
  data: string;
12
12
  } | {
@@ -3,16 +3,16 @@ import { level } from '../../db/index.js';
3
3
  import { config } from '../config/config.js';
4
4
  /**
5
5
  * 重启Bot
6
- * @param self_id - 机器人的id 传e.self_id
6
+ * @param selfId - 机器人的id 传e.self_id
7
7
  * @param contact - 事件联系人信息 也就是从哪来的这条消息 传e.contact即可
8
- * @param message_id - 消息id 传e.message_id
8
+ * @param messageId - 消息id 传e.message_id
9
9
  * @param isFront - 是否为前台重启 默认是
10
10
  */
11
- export const restart = async (self_id, contact, message_id, isFront = true) => {
11
+ export const restart = async (selfId, contact, messageId, isFront = true) => {
12
12
  const options = {
13
- id: self_id,
13
+ id: selfId,
14
14
  contact,
15
- message_id,
15
+ message_id: messageId,
16
16
  time: Date.now(),
17
17
  };
18
18
  const key = `karin:restart:${options.id}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.13",
3
+ "version": "0.12.15",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -124,7 +124,6 @@
124
124
  "fix": "eslint lib/**/*.js --fix",
125
125
  "fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.d.ts --fix",
126
126
  "init": "node lib/cli/init.js",
127
- "postinstall": "npm run init",
128
127
  "pub": "npm publish --access public",
129
128
  "sort": "npx sort-package-json && sort-json tsconfig.json",
130
129
  "start": "node lib/cli/start.js start"