napcat-sdk 0.1.0 → 0.1.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/src/onebot.ts DELETED
@@ -1,1381 +0,0 @@
1
- /**
2
- * 媒体消息的通用属性
3
- */
4
- export interface MediaProps {
5
- /** 媒体文件的 URL 地址 */
6
- url: string
7
- /** 媒体文件的本地路径 */
8
- path: string
9
- /** 媒体文件名或特殊标识 */
10
- file: (string & {}) | 'marketface'
11
- /** 媒体文件 ID */
12
- file_id: string
13
- /** 媒体文件大小(字节) */
14
- file_size: string
15
- /** 媒体文件唯一标识 */
16
- file_unique: string
17
- }
18
-
19
- // ==================== 接收消息段类型 ====================
20
-
21
- /** 接收的纯文本消息段 */
22
- export interface RecvTextElement {
23
- type: 'text'
24
- /** 文本内容 */
25
- text: string
26
- }
27
-
28
- /** 接收的 @ 消息段 */
29
- export interface RecvAtElement {
30
- type: 'at'
31
- /** 被 @ 的 QQ 号,'all' 表示 @全体成员 */
32
- qq: 'all' | (string & {})
33
- }
34
-
35
- /** 接收的回复消息段 */
36
- export interface RecvReplyElement {
37
- type: 'reply'
38
- /** 被回复的消息 ID */
39
- id: string
40
- }
41
-
42
- /** 接收的 QQ 表情消息段 */
43
- export interface RecvFaceElement {
44
- type: 'face'
45
- /** QQ 表情 ID */
46
- id: number
47
- }
48
-
49
- /** 接收的图片消息段 */
50
- export interface RecvImageElement extends MediaProps {
51
- type: 'image'
52
- /** 图片摘要/描述 */
53
- summary?: string
54
- /** 图片子类型 */
55
- sub_type?: string
56
- }
57
-
58
- /** 接收的语音消息段 */
59
- export interface RecvRecordElement extends MediaProps {
60
- type: 'record'
61
- }
62
-
63
- /** 接收的视频消息段 */
64
- export interface RecvVideoElement extends MediaProps {
65
- type: 'video'
66
- }
67
-
68
- /** 接收的猜拳消息段 */
69
- export interface RecvRpsElement {
70
- type: 'rps'
71
- /** 猜拳结果:1-石头, 2-剪刀, 3-布 */
72
- result: string
73
- }
74
-
75
- /** 接收的掷骰子消息段 */
76
- export interface RecvDiceElement {
77
- type: 'dice'
78
- /** 骰子点数:1-6 */
79
- result: string
80
- }
81
-
82
- /** 接收的窗口抖动消息段(戳一戳) */
83
- export interface RecvShakeElement {
84
- type: 'shake'
85
- }
86
-
87
- /** 接收的戳一戳消息段 */
88
- export interface RecvPokeElement {
89
- type: 'poke'
90
- }
91
-
92
- /** 接收的分享链接消息段 */
93
- export interface RecvShareElement {
94
- type: 'share'
95
- }
96
-
97
- /** 接收的位置消息段 */
98
- export interface RecvLocationElement {
99
- type: 'location'
100
- }
101
-
102
- /** 接收的合并转发消息段 */
103
- export interface RecvForwardElement {
104
- type: 'forward'
105
- /** 合并转发消息 ID */
106
- id: string
107
- /** 合并转发消息内容 */
108
- content: []
109
- }
110
-
111
- /** 接收的 JSON 消息段 */
112
- export interface RecvJsonElement {
113
- type: 'json'
114
- /** JSON 数据字符串 */
115
- data: string
116
- }
117
-
118
- /** 接收的文件消息段 */
119
- export interface RecvFileElement extends MediaProps {
120
- type: 'file'
121
- }
122
-
123
- /** 接收的 Markdown 消息段 */
124
- export interface RecvMarkdownElement {
125
- type: 'markdown'
126
- }
127
-
128
- /** 接收的小程序消息段 */
129
- export interface RecvLightAppElement {
130
- type: 'lightapp'
131
- }
132
-
133
- /**
134
- * 接收的消息段类型联合
135
- * @description 表示从 QQ 接收到的所有可能的消息段类型
136
- */
137
- export type RecvElement =
138
- | RecvTextElement
139
- | RecvAtElement
140
- | RecvReplyElement
141
- | RecvFaceElement
142
- | RecvImageElement
143
- | RecvRecordElement
144
- | RecvVideoElement
145
- | RecvRpsElement
146
- | RecvDiceElement
147
- | RecvShakeElement
148
- | RecvPokeElement
149
- | RecvShareElement
150
- | RecvLocationElement
151
- | RecvForwardElement
152
- | RecvJsonElement
153
- | RecvFileElement
154
- | RecvMarkdownElement
155
- | RecvLightAppElement
156
-
157
- // ==================== 发送消息段类型 ====================
158
-
159
- /** 发送的纯文本消息段 */
160
- export interface SendTextElement {
161
- type: 'text'
162
- /** 文本内容 */
163
- text: string
164
- }
165
-
166
- /** 发送的 @ 消息段 */
167
- export interface SendAtElement {
168
- type: 'at'
169
- /** 被 @ 的 QQ 号,'all' 表示 @全体成员 */
170
- qq: 'all' | (string & {}) | number
171
- }
172
-
173
- /** 发送的回复消息段 */
174
- export interface SendReplyElement {
175
- type: 'reply'
176
- /** 被回复的消息 ID */
177
- id: string
178
- }
179
-
180
- /** 发送的商城表情消息段 */
181
- export interface SendMfaceElement {
182
- type: 'mface'
183
- /** 表情 ID */
184
- id: number
185
- /** 表情 key */
186
- key: string
187
- /** emoji ID */
188
- emoji_id: string
189
- /** emoji 表情包 ID */
190
- emoji_package_id: string
191
- /** 表情描述/摘要 */
192
- summary?: string
193
- }
194
-
195
- /** 发送的 QQ 表情消息段 */
196
- export interface SendFaceElement {
197
- type: 'face'
198
- /** QQ 表情 ID */
199
- id: number
200
- }
201
-
202
- /** 发送的大表情消息段 */
203
- export interface SendBfaceElement {
204
- type: 'bface'
205
- /** 大表情 ID */
206
- id: number
207
- }
208
-
209
- /** 发送的图片消息段 */
210
- export interface SendImageElement {
211
- type: 'image'
212
- /** 图片文件,支持 file:// / http:// / base64:// 协议 */
213
- file: string
214
- /** 图片文件名 */
215
- name?: string
216
- /** 图片摘要/描述 */
217
- summary?: string
218
- /** 图片子类型 */
219
- sub_type?: string
220
- }
221
-
222
- /** 发送的视频消息段 */
223
- export interface SendVideoElement {
224
- type: 'video'
225
- /** 视频文件,支持 file:// / http:// / base64:// 协议 */
226
- file: string
227
- /** 视频文件名 */
228
- name?: string
229
- /** 视频封面图,支持 file:// / http:// / base64:// 协议 */
230
- thumb?: string
231
- }
232
-
233
- /** 发送的语音消息段 */
234
- export interface SendRecordElement {
235
- type: 'record'
236
- /** 语音文件,支持 file:// / http:// / base64:// 协议 */
237
- file: string
238
- /** 语音文件名 */
239
- name?: string
240
- }
241
-
242
- /** 发送的推荐好友/群消息段 */
243
- export interface SendContactElement {
244
- type: 'contact'
245
- /** 推荐类型:qq-好友, group-群 */
246
- sub_type: 'qq' | 'group'
247
- /** 被推荐的 QQ 号或群号 */
248
- id: string
249
- }
250
-
251
- /** 发送的戳一戳消息段 */
252
- export interface SendPokeElement {
253
- type: 'poke'
254
- }
255
-
256
- /** 发送的音乐分享消息段 - 平台音乐 */
257
- export interface SendPlatformMusicElement {
258
- type: 'music'
259
- /** 音乐平台 */
260
- platform: 'qq' | '163' | 'kugou' | 'migu' | 'kuwo'
261
- /** 音乐 ID */
262
- id: string
263
- }
264
-
265
- /** 发送的音乐分享消息段 - 自定义音乐 */
266
- export interface SendCustomMusicElement {
267
- type: 'music'
268
- /** 自定义音乐标识 */
269
- platform: 'custom'
270
- /** 跳转链接 URL */
271
- url: string
272
- /** 音频链接 URL */
273
- audio: string
274
- /** 音乐标题 */
275
- title: string
276
- /** 封面图片 URL */
277
- image?: string
278
- /** 歌手名称 */
279
- singer?: string
280
- }
281
-
282
- /** 发送的音乐分享消息段 */
283
- export type SendMusicElement = SendPlatformMusicElement | SendCustomMusicElement
284
-
285
- /** 发送的合并转发消息段 */
286
- export interface SendForwardElement {
287
- type: 'forward'
288
- /** 合并转发消息 ID */
289
- id: string
290
- }
291
-
292
- /** 发送的合并转发节点 - 引用已有消息 */
293
- export interface SendNodeRefElement {
294
- type: 'node'
295
- /** 发送者 QQ 号(可选) */
296
- user_id?: string
297
- /** 发送者昵称(可选) */
298
- nickname?: string
299
- /** 引用的消息 ID */
300
- id: string
301
- }
302
-
303
- /** 发送的合并转发节点 - 自定义内容 */
304
- export interface SendNodeContentElement {
305
- type: 'node'
306
- /** 发送者 QQ 号(可选) */
307
- user_id?: string
308
- /** 发送者昵称(可选) */
309
- nickname?: string
310
- /** 自定义消息内容 */
311
- content: Exclude<SendElement, { type: 'node' }>[]
312
- }
313
-
314
- /** 发送的合并转发节点消息段 */
315
- export type SendNodeElement = SendNodeRefElement | SendNodeContentElement
316
-
317
- /** 发送的 JSON 消息段 */
318
- export interface SendJsonElement {
319
- type: 'json'
320
- /** JSON 数据字符串 */
321
- data: string
322
- }
323
-
324
- /** 发送的文件消息段 */
325
- export interface SendFileElement {
326
- type: 'file'
327
- /** 文件,支持 file:// / http:// / base64:// 协议 */
328
- file: string
329
- /** 文件名 */
330
- name?: string
331
- }
332
-
333
- /** 发送的 Markdown 消息段 */
334
- export interface SendMarkdownElement {
335
- type: 'markdown'
336
- }
337
-
338
- /** 发送的小程序消息段 */
339
- export interface SendLightAppElement {
340
- type: 'lightapp'
341
- }
342
-
343
- /**
344
- * 发送的消息段类型联合
345
- * @description 表示可以发送给 QQ 的所有可能的消息段类型
346
- */
347
- export type SendElement =
348
- | SendTextElement
349
- | SendAtElement
350
- | SendReplyElement
351
- | SendMfaceElement
352
- | SendFaceElement
353
- | SendBfaceElement
354
- | SendImageElement
355
- | SendVideoElement
356
- | SendRecordElement
357
- | SendContactElement
358
- | SendPokeElement
359
- | SendMusicElement
360
- | SendForwardElement
361
- | SendNodeElement
362
- | SendJsonElement
363
- | SendFileElement
364
- | SendMarkdownElement
365
- | SendLightAppElement
366
-
367
- /**
368
- * 将消息段类型包装为 OneBot 标准格式
369
- * @description 将 { type, ...data } 转换为 { type, data: { ...data } } 格式
370
- */
371
- export type WrapData<T extends { type: string }> = { type: T['type']; data: Omit<T, 'type'> }
372
-
373
- /**
374
- * 将 OneBot 标准格式展开为扁平格式
375
- * @description 将 { type, data: { ...data } } 转换为 { type, ...data } 格式
376
- */
377
- export type FlattenData<T extends { type: string }> = T extends { data: infer U } ? U & { type: T['type'] } : never
378
-
379
- /** 标准化后的发送消息段(OneBot 标准格式) */
380
- export type NormalizedElementToSend = WrapData<SendElement>
381
-
382
- /** 可发送的消息类型,可以是字符串或消息段 */
383
- export type Sendable = string | SendElement
384
-
385
- // ==================== 事件类型定义 ====================
386
-
387
- /** 上报事件类型 */
388
- export type PostType = 'meta_event' | 'message' | 'message_sent' | 'notice' | 'request'
389
-
390
- /** 元事件类型 */
391
- export type MetaEventType = 'heartbeat' | 'lifecycle'
392
-
393
- /** 消息类型 */
394
- export type MessageType = 'private' | 'group'
395
-
396
- /** 通知类型 */
397
- export type NoticeType = 'friend' | 'group' | 'client'
398
-
399
- /** 通知子类型 */
400
- export type NoticeSubType =
401
- | 'increase'
402
- | 'decrease'
403
- | 'recall'
404
- | 'poke'
405
- | 'like'
406
- | 'input'
407
- | 'admin'
408
- | 'ban'
409
- | 'title'
410
- | 'card'
411
- | 'upload'
412
- | 'reaction'
413
- | 'essence'
414
-
415
- /**
416
- * 事件基础类型
417
- * @description 所有事件的基础结构,包含时间戳、机器人 QQ 号和事件类型
418
- */
419
- export type EventBase<T extends PostType, U extends object> = U & {
420
- /** 事件发生的 Unix 时间戳 */
421
- time: number
422
- /** 收到事件的机器人 QQ 号 */
423
- self_id: number
424
- /** 上报类型 */
425
- post_type: T
426
- }
427
-
428
- /**
429
- * 元事件基础类型
430
- * @description 元事件表示 OneBot 实现本身的状态变化
431
- */
432
- export type MetaEventBase<T extends MetaEventType, U extends object> = EventBase<
433
- 'meta_event',
434
- U & { meta_event_type: T }
435
- >
436
-
437
- /**
438
- * 心跳元事件
439
- * @description 定期发送的心跳事件,用于确认连接状态
440
- */
441
- export type HeartbeatMetaEvent = MetaEventBase<
442
- 'heartbeat',
443
- {
444
- /** 状态信息 */
445
- status: {
446
- /** 是否在线 */
447
- online: boolean
448
- /** 状态是否正常 */
449
- good: boolean
450
- }
451
- /** 心跳间隔(毫秒) */
452
- interval: number
453
- }
454
- >
455
-
456
- /**
457
- * 生命周期元事件
458
- * @description OneBot 实现的生命周期事件
459
- */
460
- export type LifecycleMetaEvent = MetaEventBase<
461
- 'lifecycle',
462
- {
463
- /** 生命周期子类型 */
464
- sub_type: 'connect'
465
- // sub_type: 'connect' | 'disable' | 'enable'
466
- }
467
- >
468
-
469
- /** 元事件联合类型 */
470
- export type MetaEvent = HeartbeatMetaEvent | LifecycleMetaEvent
471
-
472
- // ==================== 辅助函数类型 ====================
473
-
474
- /** 回复消息的函数类型 */
475
- type Reply = (sendable: Sendable | Sendable[], reply?: boolean) => Promise<{ message_id: number }>
476
-
477
- /** 发送消息的函数类型 */
478
- type SendMsg = (sendable: Sendable | Sendable[]) => Promise<{ message_id: number }>
479
-
480
- /** 消息表态操作的函数类型 */
481
- type ReactionAction = (id: string) => Promise<void>
482
-
483
- /** 撤回消息的函数类型 */
484
- type Recall = () => Promise<void>
485
-
486
- // ==================== 群和好友接口 ====================
487
-
488
- /**
489
- * 群信息接口
490
- * @description 包含群的基本信息和常用操作方法
491
- */
492
- export interface Group {
493
- /** 群号 */
494
- group_id: number
495
- /** 群名称 */
496
- group_name: string
497
- /** 群签到 */
498
- doSign: () => Promise<string>
499
- /** 获取群信息 */
500
- getInfo: () => Promise<{
501
- group_all_shut: number
502
- group_remark: string
503
- group_id: number
504
- group_name: string
505
- member_count: number
506
- max_member_count: number
507
- }>
508
- /** 获取群成员列表 */
509
- getMemberList: () => Promise<any>
510
- /** 获取群成员信息 */
511
- getMemberInfo: (user_id: number) => Promise<any>
512
- /** 设置群头衔 */
513
- setTitle: (title: string) => Promise<any>
514
- /** 设置群名片 */
515
- setCard: (user_id: number, card: string) => Promise<any>
516
- /** 添加群精华消息 */
517
- addEssence: (message_id: string) => Promise<any>
518
- /** 删除群精华消息 */
519
- delEssence: (message_id: string) => Promise<any>
520
- /** 撤回群消息 */
521
- recall: (message_id: number) => Promise<any>
522
- /** 禁言群成员 */
523
- banMember: (user_id: number, duration: number) => Promise<any>
524
- /** 发送群消息 */
525
- sendMsg: SendMsg
526
- }
527
-
528
- export type GroupWithInfo = Group & Awaited<ReturnType<Group['getInfo']>>
529
-
530
- /**
531
- * 好友信息接口
532
- * @description 包含好友的基本信息和常用操作方法
533
- */
534
- export interface Friend {
535
- /** 好友 QQ 号 */
536
- user_id: number
537
- /** 好友昵称 */
538
- nickname: string
539
- /** 发送私聊消息 */
540
- sendMsg: SendMsg
541
- /** 删除好友 */
542
- delete: (block?: boolean, both?: boolean) => Promise<any>
543
- /** 获取好友信息 */
544
- getInfo: () => Promise<{
545
- uid: string
546
- uin: string
547
- nick: string
548
- remark: string
549
- constellation: number
550
- shengXiao: number
551
- kBloodType: number
552
- homeTown: string
553
- makeFriendCareer: number
554
- pos: string
555
- college: string
556
- country: string
557
- province: string
558
- city: string
559
- postCode: string
560
- address: string
561
- regTime: number
562
- interest: string
563
- labels: string[]
564
- qqLevel: number
565
- qid: string
566
- longNick: string
567
- birthday_year: number
568
- birthday_month: number
569
- birthday_day: number
570
- age: number
571
- sex: string
572
- eMail: string
573
- phoneNum: string
574
- categoryId: number
575
- richTime: number
576
- richBuffer: {}
577
- topTime: string
578
- isBlock: boolean
579
- isMsgDisturb: boolean
580
- isSpecialCareOpen: boolean
581
- isSpecialCareZone: boolean
582
- ringId: string
583
- isBlocked: boolean
584
- recommendImgFlag: number
585
- disableEmojiShortCuts: number
586
- qidianMasterFlag: number
587
- qidianCrewFlag: number
588
- qidianCrewFlag2: number
589
- isHideQQLevel: number
590
- isHidePrivilegeIcon: number
591
- status: number
592
- extStatus: number
593
- batteryStatus: number
594
- termType: number
595
- netType: number
596
- iconType: number
597
- customStatus: null | string
598
- setTime: string
599
- specialFlag: number
600
- abiFlag: number
601
- eNetworkType: number
602
- showName: string
603
- termDesc: string
604
- musicInfo: {
605
- buf: {}
606
- }
607
- extOnlineBusinessInfo: {
608
- buf: {}
609
- customStatus: null
610
- videoBizInfo: {
611
- cid: string
612
- tvUrl: string
613
- synchType: string
614
- }
615
- videoInfo: {
616
- name: string
617
- }
618
- }
619
- user_id: number
620
- nickname: string
621
- long_nick: string
622
- reg_time: number
623
- is_vip: boolean
624
- is_years_vip: boolean
625
- vip_level: number
626
- login_days: number
627
- }>
628
- }
629
-
630
- export type FriendWithInfo = Friend & Awaited<ReturnType<Friend['getInfo']>>
631
-
632
- // ==================== 消息事件类型 ====================
633
-
634
- /**
635
- * 消息事件基础类型
636
- * @description 所有消息事件的基础结构
637
- */
638
- export type MessageEventBase<T extends MessageType, U extends object> = EventBase<
639
- 'message',
640
- U & {
641
- /** 消息 ID */
642
- message_id: number
643
- /** 消息类型 */
644
- message_type: T
645
- /** 消息序号 */
646
- message_seq: number
647
- /** 消息真实 ID */
648
- real_id: number
649
- /** 消息真实序号 */
650
- real_seq: number
651
- /** 原始消息内容(CQ 码格式) */
652
- raw_message: string
653
- /** 消息段数组 */
654
- message: RecvElement[]
655
- /** 回复消息的方法 */
656
- reply: Reply
657
- }
658
- >
659
-
660
- /**
661
- * 私聊消息事件
662
- * @description 包含好友私聊、群临时会话等私聊消息
663
- */
664
- export type PrivateMessageEvent = MessageEventBase<
665
- 'private',
666
- {
667
- /** 发送者 QQ 号 */
668
- user_id: number
669
- /** 私聊子类型:friend-好友, group-群临时会话, group_self-群中自己发送, other-其他 */
670
- sub_type: 'friend' | 'group' | 'group_self' | 'other'
671
- /** 接收者 QQ 号 */
672
- target_id: number
673
- /** 好友信息对象 */
674
- friend: Friend
675
- /** 发送者信息 */
676
- sender: {
677
- /** 发送者 QQ 号 */
678
- user_id: number
679
- /** 发送者昵称 */
680
- nickname: string
681
- }
682
- }
683
- >
684
-
685
- /**
686
- * 群消息事件
687
- * @description 群聊中的消息事件
688
- */
689
- export type GroupMessageEvent = MessageEventBase<
690
- 'group',
691
- {
692
- /** 群号 */
693
- group_id: number
694
- /** 群名称 */
695
- group_name: string
696
- /** 发送者 QQ 号 */
697
- user_id: number
698
- /** 群消息子类型:normal-普通消息, notice-通知消息 */
699
- sub_type: 'normal' | 'notice'
700
- /** 撤回该消息的方法 */
701
- recall: Recall
702
- /** 添加消息表态的方法 */
703
- addReaction: ReactionAction
704
- /** 删除消息表态的方法 */
705
- delReaction: ReactionAction
706
- /** 群信息对象 */
707
- group: Group
708
- /** 发送者信息 */
709
- sender: {
710
- /** 发送者 QQ 号 */
711
- user_id: number
712
- /** 发送者昵称 */
713
- nickname: string
714
- /** 发送者群名片 */
715
- card: string
716
- /** 发送者群角色:owner-群主, admin-管理员, member-普通成员 */
717
- role: 'owner' | 'admin' | 'member'
718
- }
719
- }
720
- >
721
-
722
- /** 消息事件联合类型 */
723
- export type MessageEvent = PrivateMessageEvent | GroupMessageEvent
724
-
725
- /**
726
- * 将消息事件转换为发送消息事件类型
727
- * @description 用于表示机器人自己发送的消息事件
728
- */
729
- type ToMessageSent<T extends MessageEvent> = Omit<T, 'post_type' | 'group' | 'friend' | 'reply'> & {
730
- post_type: 'message_sent'
731
- }
732
-
733
- // ==================== 通知事件类型 ====================
734
-
735
- /**
736
- * 通知事件基础类型
737
- * @description 所有通知事件的基础结构
738
- */
739
- export type NoticeEventBase<T extends NoticeType, U extends object> = EventBase<
740
- 'notice',
741
- U & {
742
- /** 通知类型 */
743
- notice_type: T
744
- /** 原始通知类型 */
745
- original_notice_type: string
746
- }
747
- >
748
-
749
- /**
750
- * 群通知事件基础类型
751
- * @description 所有群相关通知事件的基础结构
752
- */
753
- export type GroupNoticeEventBase<T extends NoticeSubType, U extends object> = NoticeEventBase<
754
- 'group',
755
- U & {
756
- /** 通知子类型 */
757
- sub_type: T
758
- /** 群号 */
759
- group_id: number
760
- /** 相关用户 QQ 号 */
761
- user_id: number
762
- /** 群信息对象 */
763
- group: Group
764
- }
765
- >
766
-
767
- /**
768
- * 好友通知事件基础类型
769
- * @description 所有好友相关通知事件的基础结构
770
- */
771
- export type FriendNoticeEventBase<T extends NoticeSubType, U extends object> = NoticeEventBase<
772
- 'friend',
773
- U & {
774
- /** 通知子类型 */
775
- sub_type: T
776
- /** 相关用户 QQ 号 */
777
- user_id: number
778
- /** 好友信息对象 */
779
- friend: Friend
780
- }
781
- >
782
-
783
- /** 好友增加通知事件 */
784
- export type FriendIncreaseNoticeEvent = FriendNoticeEventBase<'increase', {}>
785
-
786
- /** 好友减少通知事件 */
787
- export type FriendDecreaseNoticeEvent = FriendNoticeEventBase<'decrease', {}>
788
-
789
- /** 好友消息撤回通知事件 */
790
- export type FriendRecallNoticeEvent = FriendNoticeEventBase<
791
- 'recall',
792
- {
793
- /** 被撤回的消息 ID */
794
- message_id: number
795
- }
796
- >
797
-
798
- /** 好友戳一戳通知事件 */
799
- export type FriendPokeNoticeEvent = FriendNoticeEventBase<
800
- 'poke',
801
- {
802
- /** 被戳者 QQ 号 */
803
- target_id: number
804
- /** 发送者 QQ 号 */
805
- sender_qq: number
806
- /** 原始信息 */
807
- raw_info: any[]
808
- }
809
- >
810
-
811
- /** 好友点赞通知事件 */
812
- export type FriendLikeNoticeEvent = FriendNoticeEventBase<
813
- 'like',
814
- {
815
- /** 操作者 QQ 号 */
816
- operator_id: number
817
- /** 操作者昵称 */
818
- operator_nick: string
819
- /** 点赞次数 */
820
- times: number
821
- }
822
- >
823
-
824
- /** 好友输入状态通知事件 */
825
- export type FriendInputNoticeEvent = FriendNoticeEventBase<
826
- 'input',
827
- {
828
- /** 状态文本 */
829
- status_text: string
830
- /** 事件类型 */
831
- event_type: number
832
- }
833
- >
834
-
835
- /** 好友通知事件联合类型 */
836
- export type FriendNoticeEvent =
837
- | FriendIncreaseNoticeEvent
838
- | FriendDecreaseNoticeEvent
839
- | FriendRecallNoticeEvent
840
- | FriendPokeNoticeEvent
841
- | FriendLikeNoticeEvent
842
- | FriendInputNoticeEvent
843
-
844
- // ==================== 群通知事件 ====================
845
-
846
- /** 群成员增加通知事件 */
847
- export type GroupIncreaseNoticeEvent = GroupNoticeEventBase<
848
- 'increase',
849
- {
850
- /** 操作者 QQ 号(如邀请者) */
851
- operator_id: number
852
- /** 加入类型:invite-邀请, add-主动加群, approve-管理员审批 */
853
- actions_type: 'invite' | 'add' | 'approve'
854
- }
855
- >
856
-
857
- /** 群成员减少通知事件 */
858
- export type GroupDecreaseNoticeEvent = GroupNoticeEventBase<
859
- 'decrease',
860
- {
861
- /** 操作者 QQ 号 */
862
- operator_id: number
863
- /** 离开类型:kick-被踢, leave-主动退出 */
864
- actions_type: 'kick' | 'leave'
865
- }
866
- >
867
-
868
- /** 群管理员变动通知事件 */
869
- export type GroupAdminNoticeEvent = GroupNoticeEventBase<
870
- 'admin',
871
- {
872
- /** 操作类型:set-设置管理员, unset-取消管理员 */
873
- action_type: 'set' | 'unset'
874
- }
875
- >
876
-
877
- /** 群禁言通知事件 */
878
- export type GroupBanNoticeEvent = GroupNoticeEventBase<
879
- 'ban',
880
- {
881
- /** 禁言时长(秒),0 表示解除禁言 */
882
- duration: number
883
- /** 操作类型:ban-禁言, lift_ban-解除禁言 */
884
- action_type: 'ban' | 'lift_ban'
885
- /** 操作者 QQ 号 */
886
- operator_id: number
887
- }
888
- >
889
-
890
- /** 群名片变动通知事件 */
891
- export type GroupCardNoticeEvent = GroupNoticeEventBase<
892
- 'card',
893
- {
894
- /** 新名片 */
895
- card_new: string
896
- /** 旧名片 */
897
- card_old: string
898
- }
899
- >
900
-
901
- /** 群戳一戳通知事件 */
902
- export type GroupPokeNoticeEvent = GroupNoticeEventBase<
903
- 'poke',
904
- {
905
- /** 被戳者 QQ 号 */
906
- target_id: number
907
- /** 原始信息 */
908
- raw_info: any[]
909
- }
910
- >
911
-
912
- /** 群头衔变动通知事件 */
913
- export type GroupTitleNoticeEvent = GroupNoticeEventBase<
914
- 'title',
915
- {
916
- /** 新头衔 */
917
- title: string
918
- }
919
- >
920
-
921
- /** 群文件上传通知事件 */
922
- export type GroupUploadNoticeEvent = GroupNoticeEventBase<
923
- 'upload',
924
- {
925
- /** 上传的文件信息 */
926
- file: {
927
- /** 文件 ID */
928
- id: string
929
- /** 文件名 */
930
- name: string
931
- /** 文件大小(字节) */
932
- size: number
933
- /** 文件业务 ID */
934
- busid: number
935
- }
936
- }
937
- >
938
-
939
- /** 群消息表态变动通知事件 */
940
- export type GroupReactionNoticeEvent = GroupNoticeEventBase<
941
- 'reaction',
942
- {
943
- /** 相关消息 ID */
944
- message_id: number
945
- /** 表态列表 */
946
- likes: {
947
- /** 表情 ID */
948
- emoji_id: string
949
- /** 表态数量 */
950
- count: number
951
- }[]
952
- /** 是否为添加表态 */
953
- is_add: boolean
954
- }
955
- >
956
- /** 群精华消息变动通知事件 */
957
- export type GroupEssenceNoticeEvent = GroupNoticeEventBase<
958
- 'essence',
959
- {
960
- /** 原消息发送者 QQ 号 */
961
- sender_id: number
962
- /** 相关消息 ID */
963
- message_id: number
964
- /** 操作者 QQ 号 */
965
- operator_id: number
966
- /** 操作类型:add-添加精华, remove-移除精华 */
967
- action_type: 'add' | 'remove'
968
- }
969
- >
970
-
971
- /** 群消息撤回通知事件 */
972
- export type GroupRecallNoticeEvent = GroupNoticeEventBase<
973
- 'recall',
974
- {
975
- /** 被撤回的消息 ID */
976
- message_id: number
977
- /** 操作者 QQ 号 */
978
- operator_id: number
979
- }
980
- >
981
-
982
- /** 群通知事件联合类型 */
983
- export type GroupNoticeEvent =
984
- | GroupIncreaseNoticeEvent
985
- | GroupDecreaseNoticeEvent
986
- | GroupBanNoticeEvent
987
- | GroupCardNoticeEvent
988
- | GroupPokeNoticeEvent
989
- | GroupTitleNoticeEvent
990
- | GroupUploadNoticeEvent
991
- | GroupReactionNoticeEvent
992
- | GroupEssenceNoticeEvent
993
- | GroupRecallNoticeEvent
994
-
995
- /** 通知事件联合类型 */
996
- export type NoticeEvent = GroupNoticeEvent | FriendNoticeEvent
997
-
998
- // ==================== 请求事件类型 ====================
999
-
1000
- /**
1001
- * 请求事件基础类型
1002
- * @description 所有请求事件的基础结构
1003
- */
1004
- export type RequestEventBase<T extends string, U extends object> = EventBase<
1005
- 'request',
1006
- U & {
1007
- /** 请求类型 */
1008
- request_type: T
1009
- /** 请求者 QQ 号 */
1010
- user_id: number
1011
- /** 请求标识,用于处理请求 */
1012
- flag: string
1013
- /** 验证信息/备注 */
1014
- comment: string
1015
- }
1016
- >
1017
-
1018
- /** 好友添加请求事件 */
1019
- export type FriendRequestEvent = RequestEventBase<'friend', {}>
1020
-
1021
- /** 加群请求事件(他人申请加入群) */
1022
- export type GroupAddRequestEvent = RequestEventBase<
1023
- 'group',
1024
- {
1025
- /** 群号 */
1026
- group_id: number
1027
- /** 请求子类型:add-主动加群 */
1028
- sub_type: 'add'
1029
- }
1030
- >
1031
-
1032
- /** 邀请入群请求事件(他人邀请机器人入群) */
1033
- export type GroupInviteRequestEvent = RequestEventBase<
1034
- 'group',
1035
- {
1036
- /** 群号 */
1037
- group_id: number
1038
- /** 请求子类型:invite-被邀请 */
1039
- sub_type: 'invite'
1040
- }
1041
- >
1042
-
1043
- /** 群请求事件联合类型 */
1044
- export type GroupRequestEvent = GroupAddRequestEvent | GroupInviteRequestEvent
1045
-
1046
- /** 请求事件联合类型 */
1047
- export type RequestEvent = FriendRequestEvent | GroupRequestEvent
1048
-
1049
- // ==================== 事件映射 ====================
1050
-
1051
- /**
1052
- * OneBot 事件映射表
1053
- * @description 定义了所有事件名称与对应事件类型的映射关系
1054
- */
1055
- export interface OneBotEventMap {
1056
- /** 元事件,通常与 OneBot 服务端状态相关 */
1057
- meta_event: MetaEvent
1058
-
1059
- /** 元事件 - 心跳事件,确认服务端在线状态 */
1060
- 'meta_event.heartbeat': HeartbeatMetaEvent
1061
-
1062
- /** 元事件 - 生命周期,服务端状态变化 */
1063
- 'meta_event.lifecycle': LifecycleMetaEvent
1064
- /** 元事件 - 生命周期 - 连接成功 */
1065
- 'meta_event.lifecycle.connect': LifecycleMetaEvent
1066
- // 'meta_event.lifecycle.disable': LifecycleMetaEvent
1067
- // 'meta_event.lifecycle.enable': LifecycleMetaEvent
1068
-
1069
- /** 消息事件,包含私聊和群消息 */
1070
- message: MessageEvent
1071
-
1072
- /** 消息事件 - 私聊消息 */
1073
- 'message.private': PrivateMessageEvent
1074
- /** 消息事件 - 私聊消息 - 好友私聊 */
1075
- 'message.private.friend': PrivateMessageEvent
1076
- /** 消息事件 - 私聊消息 - 群临时会话 */
1077
- 'message.private.group': PrivateMessageEvent
1078
- // 'message.private.group_self': PrivateMessageEvent
1079
- // 'message.private.other': PrivateMessageEvent
1080
-
1081
- /** 消息事件 - 群消息 */
1082
- 'message.group': GroupMessageEvent
1083
- /** 消息事件 - 群消息 - 普通消息 */
1084
- 'message.group.normal': GroupMessageEvent
1085
- // 'message.group.notice': GroupMessageEvent
1086
-
1087
- message_sent: ToMessageSent<MessageEvent>
1088
-
1089
- /* 发送消息事件 - 私聊消息 */
1090
- 'message_sent.private': ToMessageSent<PrivateMessageEvent>
1091
- /* 发送消息事件 - 私聊消息 - 好友私聊 */
1092
- 'message_sent.private.friend': ToMessageSent<PrivateMessageEvent>
1093
- /* 发送消息事件 - 私聊消息 - 群临时会话 */
1094
- 'message_sent.private.group': ToMessageSent<PrivateMessageEvent>
1095
- // 'message_sent.private.group_self': MessageToMessageSent<PrivateMessageEvent>
1096
- // 'message_sent.private.other': MessageToMessageSent<PrivateMessageEvent>
1097
-
1098
- /* 发送消息事件 - 群消息 */
1099
- 'message_sent.group': ToMessageSent<GroupMessageEvent>
1100
- /* 发送消息事件 - 群消息 - 普通消息 */
1101
- 'message_sent.group.normal': ToMessageSent<GroupMessageEvent>
1102
- // 'message.group.notice': MessageToMessageSent<GroupMessageEvent>
1103
-
1104
- /** 请求事件 */
1105
- request: RequestEvent
1106
-
1107
- /** 请求事件 - 好友请求 */
1108
- 'request.friend': FriendRequestEvent
1109
-
1110
- /** 请求事件 - 群请求 */
1111
- 'request.group': GroupRequestEvent
1112
- /** 请求事件 - 他人加群请求,当机器人是群主或管理员时收到 */
1113
- 'request.group.add': GroupAddRequestEvent
1114
- /** 请求事件 - 邀请加群请求,他人邀请机器人加入群时收到 */
1115
- 'request.group.invite': GroupInviteRequestEvent
1116
-
1117
- /** 通知事件 */
1118
- notice: NoticeEvent
1119
-
1120
- /** 通知事件 - 好友相关通知 */
1121
- 'notice.friend': FriendNoticeEvent
1122
- /** 通知事件 - 好友增加 */
1123
- 'notice.friend.increase': FriendIncreaseNoticeEvent
1124
- /** 通知事件 - 好友减少 */
1125
- 'notice.friend.decrease': FriendDecreaseNoticeEvent
1126
- /** 通知事件 - 好友备注变更 */
1127
- 'notice.friend.recall': FriendRecallNoticeEvent
1128
- /** 通知事件 - 好友戳一戳 */
1129
- 'notice.friend.poke': FriendPokeNoticeEvent
1130
- /** 通知事件 - 好友点赞 */
1131
- 'notice.friend.like': FriendLikeNoticeEvent
1132
- /** 通知事件 - 好友输入状态 */
1133
- 'notice.friend.input': FriendInputNoticeEvent
1134
-
1135
- // 'notice.friend.offline_file': EventBase<'notice', any>
1136
- // 'notice.client.status': EventBase<'notice', any>
1137
-
1138
- /** 通知事件 - 群相关通知 */
1139
- 'notice.group': GroupNoticeEvent
1140
- /** 通知事件 - 群成员增加 */
1141
- 'notice.group.increase': GroupIncreaseNoticeEvent
1142
- /** 通知事件 - 群成员减少 */
1143
- 'notice.group.decrease': GroupDecreaseNoticeEvent
1144
- /** 通知事件 - 群管理员变更 */
1145
- 'notice.group.admin': GroupAdminNoticeEvent
1146
- /** 通知事件 - 群成员被禁言 */
1147
- 'notice.group.ban': GroupBanNoticeEvent
1148
- /** 通知事件 - 群戳一戳 */
1149
- 'notice.group.poke': GroupPokeNoticeEvent
1150
- /** 通知事件 - 群头衔变更 */
1151
- 'notice.group.title': GroupTitleNoticeEvent
1152
- /** 通知事件 - 群名片变更 */
1153
- 'notice.group.card': GroupCardNoticeEvent
1154
- /** 通知事件 - 群公告变更 */
1155
- 'notice.group.recall': GroupRecallNoticeEvent
1156
- /** 通知事件 - 群上传文件 */
1157
- 'notice.group.upload': GroupUploadNoticeEvent
1158
- /** 通知事件 - 给群消息添加反应 Reaction */
1159
- 'notice.group.reaction': GroupReactionNoticeEvent
1160
- /** 通知事件 - 群精华消息变更 */
1161
- 'notice.group.essence': GroupEssenceNoticeEvent
1162
- }
1163
-
1164
- // ==================== API 类型 ====================
1165
-
1166
- /**
1167
- * OneBot 11 标准 API
1168
- * @description OneBot 11 规范定义的标准 API 接口
1169
- */
1170
- export type OneBotAPI =
1171
- | 'delete_friend'
1172
- | 'delete_msg'
1173
- | 'get_forward_msg'
1174
- | 'get_friend_list'
1175
- | 'get_group_info'
1176
- | 'get_group_list'
1177
- | 'get_group_member_info'
1178
- | 'get_group_member_list'
1179
- | 'get_group_msg_history'
1180
- | 'get_login_info'
1181
- | 'get_msg'
1182
- | 'get_status'
1183
- | 'get_stranger_info'
1184
- | 'send_group_msg'
1185
- | 'send_private_msg'
1186
- | 'set_friend_add_request'
1187
- | 'set_group_add_request'
1188
- | 'set_group_admin'
1189
- | 'set_group_ban'
1190
- | 'set_group_card'
1191
- | 'set_group_kick'
1192
- | 'set_group_leave'
1193
- | 'set_group_name'
1194
- | 'set_group_portrait'
1195
- | 'set_group_special_title'
1196
- | 'set_qq_profile'
1197
-
1198
- /**
1199
- * NapCat 扩展 API
1200
- * @description NapCat 实现的额外扩展 API 接口
1201
- */
1202
- export type NapCatExtendAPI =
1203
- | '_del_group_notice'
1204
- | '_get_group_notice'
1205
- | '_get_model_show'
1206
- | '_mark_all_as_read'
1207
- | '_send_group_notice'
1208
- | '_set_model_show'
1209
- | '.handle_quick_operation'
1210
- | '.ocr_image'
1211
- | 'ArkShareGroup'
1212
- | 'ArkSharePeer'
1213
- | 'bot_exit'
1214
- | 'can_send_image'
1215
- | 'can_send_record'
1216
- | 'clean_cache'
1217
- | 'click_inline_keyboard_button'
1218
- | 'create_collection'
1219
- | 'create_group_file_folder'
1220
- | 'delete_essence_msg'
1221
- | 'delete_group_file'
1222
- | 'delete_group_folder'
1223
- | 'download_file'
1224
- | 'fetch_custom_face'
1225
- | 'fetch_emoji_like'
1226
- | 'forward_friend_single_msg'
1227
- | 'forward_group_single_msg'
1228
- | 'friend_poke'
1229
- | 'get_ai_characters'
1230
- | 'get_ai_record'
1231
- | 'get_clientkey'
1232
- | 'get_collection_list'
1233
- | 'get_cookies'
1234
- | 'get_credentials'
1235
- | 'get_csrf_token'
1236
- | 'get_doubt_friends_add_request'
1237
- | 'get_essence_msg_list'
1238
- | 'get_file'
1239
- | 'get_friend_msg_history'
1240
- | 'get_friends_with_category'
1241
- | 'get_group_at_all_remain'
1242
- | 'get_group_detail_info'
1243
- | 'get_group_file_system_info'
1244
- | 'get_group_file_url'
1245
- | 'get_group_files_by_folder'
1246
- | 'get_group_honor_info'
1247
- | 'get_group_ignored_notifies'
1248
- | 'get_group_info_ex'
1249
- | 'get_group_root_files'
1250
- | 'get_group_shut_list'
1251
- | 'get_group_system_msg'
1252
- | 'get_image'
1253
- | 'get_mini_app_ark'
1254
- | 'get_online_clients'
1255
- | 'get_private_file_url'
1256
- | 'get_profile_like'
1257
- | 'get_recent_contact'
1258
- | 'get_record'
1259
- | 'get_rkey_server'
1260
- | 'get_rkey'
1261
- | 'get_robot_uin_range'
1262
- | 'get_unidirectional_friend_list'
1263
- | 'get_version_info'
1264
- | 'group_poke'
1265
- | 'mark_group_msg_as_read'
1266
- | 'mark_msg_as_read'
1267
- | 'mark_private_msg_as_read'
1268
- | 'move_group_file'
1269
- | 'nc_get_packet_status'
1270
- | 'nc_get_rkey'
1271
- | 'nc_get_user_status'
1272
- | 'ocr_image'
1273
- | 'rename_group_file'
1274
- | 'send_forward_msg'
1275
- | 'send_group_ai_record'
1276
- | 'send_group_sign'
1277
- | 'send_like'
1278
- | 'send_packet'
1279
- | 'send_poke'
1280
- | 'set_diy_online_status'
1281
- | 'set_essence_msg'
1282
- | 'set_friend_remark'
1283
- | 'set_group_add_option'
1284
- | 'set_group_kick_members'
1285
- | 'set_group_remark'
1286
- | 'set_group_robot_add_option'
1287
- | 'set_group_search'
1288
- | 'set_group_sign'
1289
- | 'set_group_whole_ban'
1290
- | 'set_input_status'
1291
- | 'set_msg_emoji_like'
1292
- | 'set_online_status'
1293
- | 'set_qq_avatar'
1294
- | 'set_self_longnick'
1295
- | 'trans_group_file'
1296
- | 'translate_en2zh'
1297
- | 'upload_group_file'
1298
- | 'upload_private_file'
1299
-
1300
- /** 所有可用的 API 接口联合类型 */
1301
- export type API = OneBotAPI | NapCatExtendAPI
1302
-
1303
- // ==================== 通知事件映射 ====================
1304
-
1305
- /**
1306
- * NapCat 通知类型映射表(notify 类型)
1307
- * @description 将 NapCat 特有的通知类型映射到标准的 notice_type 和 sub_type
1308
- */
1309
- export const NAPCAT_NOTICE_NOTIFY_MAP: Record<string, { notice_type: string; sub_type: string }> = {
1310
- input_status: {
1311
- notice_type: 'friend',
1312
- sub_type: 'input',
1313
- },
1314
- profile_like: {
1315
- notice_type: 'friend',
1316
- sub_type: 'like',
1317
- },
1318
- title: {
1319
- notice_type: 'group',
1320
- sub_type: 'title',
1321
- },
1322
- }
1323
-
1324
- /**
1325
- * NapCat 通知事件映射表(notice 类型)
1326
- * @description 将 NapCat 的原始通知事件类型映射到标准的 notice_type 和 sub_type
1327
- */
1328
- export const NAPCAT_NOTICE_EVENT_MAP: Record<string, { notice_type: string; sub_type: string }> = {
1329
- friend_add: {
1330
- notice_type: 'friend',
1331
- sub_type: 'increase',
1332
- },
1333
- friend_recall: {
1334
- notice_type: 'friend',
1335
- sub_type: 'recall',
1336
- },
1337
- offline_file: {
1338
- notice_type: 'friend',
1339
- sub_type: 'offline_file',
1340
- },
1341
- client_status: {
1342
- notice_type: 'client',
1343
- sub_type: 'status',
1344
- },
1345
- group_admin: {
1346
- notice_type: 'group',
1347
- sub_type: 'admin',
1348
- },
1349
- group_ban: {
1350
- notice_type: 'group',
1351
- sub_type: 'ban',
1352
- },
1353
- group_card: {
1354
- notice_type: 'group',
1355
- sub_type: 'card',
1356
- },
1357
- group_upload: {
1358
- notice_type: 'group',
1359
- sub_type: 'upload',
1360
- },
1361
- group_decrease: {
1362
- notice_type: 'group',
1363
- sub_type: 'decrease',
1364
- },
1365
- group_increase: {
1366
- notice_type: 'group',
1367
- sub_type: 'increase',
1368
- },
1369
- group_msg_emoji_like: {
1370
- notice_type: 'group',
1371
- sub_type: 'reaction',
1372
- },
1373
- essence: {
1374
- notice_type: 'group',
1375
- sub_type: 'essence',
1376
- },
1377
- group_recall: {
1378
- notice_type: 'group',
1379
- sub_type: 'recall',
1380
- },
1381
- }