@karinjs/adapter-qqbot 1.2.10 → 2.0.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.
Files changed (65) hide show
  1. package/README.md +326 -85
  2. package/dist/apps/login.d.ts +20 -0
  3. package/dist/apps/login.js +57 -0
  4. package/dist/config-H7LrvlNU.js +197 -0
  5. package/dist/index.d.ts +670 -0
  6. package/dist/index.js +2847 -0
  7. package/dist/onboard-BX8g8Wik.js +249 -0
  8. package/dist/utils-DO4gEkVN.js +3 -0
  9. package/dist/web.config.d.ts +22 -0
  10. package/dist/web.config.js +173 -0
  11. package/package.json +34 -21
  12. package/config/comment/config.json +0 -3
  13. package/config/config/config.yaml +0 -53
  14. package/lib/cli/pr.d.ts +0 -2
  15. package/lib/cli/pr.js +0 -73
  16. package/lib/core/adapter/adapter.d.ts +0 -91
  17. package/lib/core/adapter/adapter.js +0 -144
  18. package/lib/core/adapter/handler.d.ts +0 -49
  19. package/lib/core/adapter/handler.js +0 -140
  20. package/lib/core/adapter/markdown.d.ts +0 -38
  21. package/lib/core/adapter/markdown.js +0 -220
  22. package/lib/core/adapter/normal.d.ts +0 -30
  23. package/lib/core/adapter/normal.js +0 -263
  24. package/lib/core/api/index.d.ts +0 -167
  25. package/lib/core/api/index.js +0 -180
  26. package/lib/core/api/sign.d.ts +0 -22
  27. package/lib/core/api/sign.js +0 -40
  28. package/lib/core/api/types.d.ts +0 -236
  29. package/lib/core/api/types.js +0 -1
  30. package/lib/core/event/conver.d.ts +0 -10
  31. package/lib/core/event/conver.js +0 -57
  32. package/lib/core/event/index.d.ts +0 -9
  33. package/lib/core/event/index.js +0 -98
  34. package/lib/core/event/message.d.ts +0 -27
  35. package/lib/core/event/message.js +0 -95
  36. package/lib/core/event/notice.d.ts +0 -50
  37. package/lib/core/event/notice.js +0 -133
  38. package/lib/core/event/types.d.ts +0 -473
  39. package/lib/core/event/types.js +0 -1
  40. package/lib/core/internal/axios.d.ts +0 -25
  41. package/lib/core/internal/axios.js +0 -46
  42. package/lib/core/internal/sign.d.ts +0 -22
  43. package/lib/core/internal/sign.js +0 -40
  44. package/lib/core/webhook/c2c.d.ts +0 -2
  45. package/lib/core/webhook/c2c.js +0 -14
  46. package/lib/core/webhook/http.d.ts +0 -2
  47. package/lib/core/webhook/http.js +0 -35
  48. package/lib/core/webhook/index.d.ts +0 -17
  49. package/lib/core/webhook/index.js +0 -87
  50. package/lib/core/webhook/ws.d.ts +0 -2
  51. package/lib/core/webhook/ws.js +0 -79
  52. package/lib/index.d.ts +0 -1
  53. package/lib/index.js +0 -5
  54. package/lib/root.d.ts +0 -5
  55. package/lib/root.js +0 -9
  56. package/lib/types/config.d.ts +0 -53
  57. package/lib/types/config.js +0 -1
  58. package/lib/utils/common.d.ts +0 -80
  59. package/lib/utils/common.js +0 -198
  60. package/lib/utils/config.d.ts +0 -9
  61. package/lib/utils/config.js +0 -54
  62. package/lib/utils/dir.d.ts +0 -1
  63. package/lib/utils/dir.js +0 -1
  64. package/lib/utils/index.d.ts +0 -4
  65. package/lib/utils/index.js +0 -4
@@ -1,133 +0,0 @@
1
- import { karin, segment, createGroupMemberAddNotice, createGroupMemberDelNotice, createFriendIncreaseNotice, createFriendDecreaseNotice } from 'node-karin';
2
- /**
3
- * 机器人加入群聊事件
4
- * @param client 机器人实例
5
- * @param event 事件
6
- */
7
- export const onGroupAddRobot = (client, event) => {
8
- const selfId = client.selfId;
9
- const userId = event.d.op_member_openid;
10
- const groupId = event.d.group_openid;
11
- const contact = karin.contactGroup(groupId);
12
- const sender = karin.groupSender(userId, 'unknown');
13
- const eventId = event.id;
14
- const srcReply = (elements) => client.sendMsg(contact, [...elements, segment.pasmsg(eventId, 'event')]);
15
- createGroupMemberAddNotice({
16
- contact,
17
- eventId,
18
- sender,
19
- srcReply,
20
- bot: client,
21
- rawEvent: event,
22
- time: event.d.timestamp,
23
- content: { operatorId: userId, targetId: selfId, type: 'invite' }
24
- });
25
- };
26
- /**
27
- * 机器人退出群聊事件
28
- * @param client 机器人实例
29
- * @param event 事件
30
- */
31
- export const onGroupDelRobot = (client, event) => {
32
- const selfId = client.selfId;
33
- const userId = event.d.op_member_openid;
34
- const groupId = event.d.group_openid;
35
- const contact = karin.contactGroup(groupId);
36
- const sender = karin.groupSender(userId, 'unknown');
37
- const eventId = event.id;
38
- const srcReply = (elements) => client.sendMsg(contact, [...elements, segment.pasmsg(eventId, 'event')]);
39
- createGroupMemberDelNotice({
40
- contact,
41
- eventId,
42
- sender,
43
- srcReply,
44
- bot: client,
45
- rawEvent: event,
46
- time: event.d.timestamp,
47
- content: { operatorId: userId, targetId: selfId, type: 'kick' }
48
- });
49
- };
50
- /**
51
- * 群聊接受机器人主动消息
52
- * @param client 机器人实例
53
- * @param event 事件
54
- */
55
- export const onGroupMsgReceive = (client, event) => {
56
- const groupId = event.d.group_openid;
57
- const userId = event.d.op_member_openid;
58
- client.logger('mark', `群聊 ${groupId} 已允许机器人主动发送消息 操作人: ${userId}`);
59
- };
60
- /**
61
- * 群聊拒绝机器人主动消息
62
- * @param client 机器人实例
63
- * @param event 事件
64
- */
65
- export const onGroupMsgReject = (client, event) => {
66
- const groupId = event.d.group_openid;
67
- const userId = event.d.op_member_openid;
68
- client.logger('mark', `群聊 ${groupId} 已拒绝机器人主动发送消息 操作人: ${userId}`);
69
- };
70
- /**
71
- * 好友添加事件
72
- * @param client 机器人实例
73
- * @param event 事件
74
- */
75
- export const onFriendAdd = (client, event) => {
76
- const selfId = client.selfId;
77
- const userId = event.d.openid;
78
- const contact = karin.contactFriend(userId);
79
- const sender = karin.friendSender(userId, '');
80
- const eventId = event.id;
81
- const srcReply = (elements) => client.sendMsg(contact, [...elements, segment.pasmsg(eventId, 'event')]);
82
- createFriendIncreaseNotice({
83
- contact,
84
- eventId,
85
- sender,
86
- srcReply,
87
- bot: client,
88
- rawEvent: event,
89
- time: event.d.timestamp,
90
- content: { targetId: selfId }
91
- });
92
- };
93
- /**
94
- * 好友删除事件
95
- * @param client 机器人实例
96
- * @param event 事件
97
- */
98
- export const onFriendDel = (client, event) => {
99
- const selfId = client.selfId;
100
- const userId = event.d.openid;
101
- const contact = karin.contactFriend(userId);
102
- const sender = karin.friendSender(userId, '');
103
- const eventId = event.id;
104
- const srcReply = (elements) => client.sendMsg(contact, [...elements, segment.pasmsg(eventId, 'event')]);
105
- createFriendDecreaseNotice({
106
- contact,
107
- eventId,
108
- sender,
109
- srcReply,
110
- bot: client,
111
- rawEvent: event,
112
- time: event.d.timestamp,
113
- content: { targetId: selfId }
114
- });
115
- };
116
- /**
117
- * 好友接受机器人主动消息
118
- * @param client 机器人实例
119
- * @param event 事件
120
- */
121
- export const onC2CMsgReceive = (client, event) => {
122
- const userId = event.d.openid;
123
- client.logger('mark', `好友 ${userId} 已允许机器人主动发送消息`);
124
- };
125
- /**
126
- * 好友拒绝机器人主动消息
127
- * @param client 机器人实例
128
- * @param event 事件
129
- */
130
- export const onC2CMsgReject = (client, event) => {
131
- const userId = event.d.openid;
132
- client.logger('mark', `好友 ${userId} 已拒绝机器人主动发送消息`);
133
- };
@@ -1,473 +0,0 @@
1
- /**
2
- * 需要注意 目前只有私聊可以收到file类型的消息
3
- */
4
- export type Content_type = 'image/gif' | 'image/jpeg' | 'image/png' | 'file';
5
- /**
6
- * 富媒体基类
7
- */
8
- export interface Attachment {
9
- /** 类型 */
10
- content_type: Content_type;
11
- /** 未知作用 */
12
- content?: string;
13
- /** 文件名 */
14
- filename: string;
15
- /** 图片高度 */
16
- height?: number;
17
- /** 图片宽度 */
18
- width?: number;
19
- /** 文件大小 */
20
- size: number;
21
- /** 文件url */
22
- url: string;
23
- }
24
- /**
25
- * opcode
26
- * 客户端操作含义如下:
27
- * Receive 客户端接收到服务端 push 的消息
28
- * Send 客户端发送消息
29
- * Reply 客户端接收到服务端发送的消息之后的回包(HTTP 回调模式)
30
- */
31
- export declare const enum Opcode {
32
- /** Dispatch [Receive] 服务端进行消息推送 */
33
- Dispatch = 0,
34
- /** Heartbeat [Send/Receive] 客户端或服务端发送心跳 */
35
- Heartbeat = 1,
36
- /** Identify [Send] 客户端发送鉴权 */
37
- Identify = 2,
38
- /** Resume [Send] 客户端恢复连接 */
39
- Resume = 6,
40
- /** Reconnect [Receive] 服务端通知客户端重新连接 */
41
- Reconnect = 7,
42
- /** Invalid Session [Receive] 当identify或resume的时候,如果参数有错,服务端会返回该消息 */
43
- InvalidSession = 9,
44
- /** Hello [Receive] 当客户端与网关建立ws连接之后,网关下发的第一条消息 */
45
- Hello = 10,
46
- /** Heartbeat ACK [Receive/Reply] 当发送心跳成功之后,就会收到该消息 */
47
- HeartbeatACK = 11,
48
- /** HTTP Callback ACK [Reply] 仅用于 http 回调模式的回包,代表机器人收到了平台推送的数据 */
49
- HTTPCallbackACK = 12
50
- }
51
- /**
52
- * 心跳生命周期事件
53
- */
54
- export interface HeartbeatEvent {
55
- /** opcode */
56
- op: Opcode.Hello;
57
- /** 事件内容 */
58
- d: {
59
- /** 心跳声明周期 */
60
- heartbeat_interval: number;
61
- };
62
- }
63
- /**
64
- * 心跳回包事件
65
- */
66
- export interface HeartbeatACKEvent {
67
- /** opcode */
68
- op: Opcode.HeartbeatACK;
69
- }
70
- /**
71
- * 子事件类型
72
- */
73
- export declare const enum EventEnum {
74
- /** 在鉴权成功后下发 代表建立连接成功 */
75
- READY = "READY",
76
- /** 恢复登录状态后 不发遗漏事件完毕下发 */
77
- RESUMED = "RESUMED",
78
- /** 当机器人加入新的guild时 */
79
- GUILD_CREATE = "GUILD_CREATE",
80
- /** 当guild资料发生变更时 */
81
- GUILD_UPDATE = "GUILD_UPDATE",
82
- /** 当机器人退出guild时 */
83
- GUILD_DELETE = "GUILD_DELETE",
84
- /** 当channel被创建时 */
85
- CHANNEL_CREATE = "CHANNEL_CREATE",
86
- /** 当channel被更新时 */
87
- CHANNEL_UPDATE = "CHANNEL_UPDATE",
88
- /** 当channel被删除时 */
89
- CHANNEL_DELETE = "CHANNEL_DELETE",
90
- /** 当成员加入时 */
91
- GUILD_MEMBER_ADD = "GUILD_MEMBER_ADD",
92
- /** 当成员资料变更时 */
93
- GUILD_MEMBER_UPDATE = "GUILD_MEMBER_UPDATE",
94
- /** 当成员被移除时 */
95
- GUILD_MEMBER_REMOVE = "GUILD_MEMBER_REMOVE",
96
- /** 发送消息事件,代表频道内的全部消息,而不只是 at 机器人的消息。内容与 AT_MESSAGE_CREATE 相同 */
97
- MESSAGE_CREATE = "MESSAGE_CREATE",
98
- /** 删除(撤回)消息事件 */
99
- MESSAGE_DELETE = "MESSAGE_DELETE",
100
- /** 为消息添加表情表态 */
101
- MESSAGE_REACTION_ADD = "MESSAGE_REACTION_ADD",
102
- /** 为消息删除表情表态 */
103
- MESSAGE_REACTION_REMOVE = "MESSAGE_REACTION_REMOVE",
104
- /** 当收到用户发给机器人的私信消息时 */
105
- DIRECT_MESSAGE_CREATE = "DIRECT_MESSAGE_CREATE",
106
- /** 删除(撤回)消息事件 */
107
- DIRECT_MESSAGE_DELETE = "DIRECT_MESSAGE_DELETE",
108
- /** 用户单聊发消息给机器人时候 */
109
- C2C_MESSAGE_CREATE = "C2C_MESSAGE_CREATE",
110
- /** 用户添加使用机器人 */
111
- FRIEND_ADD = "FRIEND_ADD",
112
- /** 用户删除机器人 */
113
- FRIEND_DEL = "FRIEND_DEL",
114
- /** 用户在机器人资料卡手动关闭"主动消息"推送 */
115
- C2C_MSG_REJECT = "C2C_MSG_REJECT",
116
- /** 用户在机器人资料卡手动开启"主动消息"推送开关 */
117
- C2C_MSG_RECEIVE = "C2C_MSG_RECEIVE",
118
- /** 用户在群里@机器人时收到的消息 */
119
- GROUP_AT_MESSAGE_CREATE = "GROUP_AT_MESSAGE_CREATE",
120
- /** 机器人被添加到群聊 */
121
- GROUP_ADD_ROBOT = "GROUP_ADD_ROBOT",
122
- /** 机器人被移出群聊 */
123
- GROUP_DEL_ROBOT = "GROUP_DEL_ROBOT",
124
- /** 群管理员主动在机器人资料页操作关闭通知 */
125
- GROUP_MSG_REJECT = "GROUP_MSG_REJECT",
126
- /** 群管理员主动在机器人资料页操作开启通知 */
127
- GROUP_MSG_RECEIVE = "GROUP_MSG_RECEIVE",
128
- /** 互动事件创建时 */
129
- INTERACTION_CREATE = "INTERACTION_CREATE",
130
- /** 消息审核通过 */
131
- MESSAGE_AUDIT_PASS = "MESSAGE_AUDIT_PASS",
132
- /** 消息审核不通过 */
133
- MESSAGE_AUDIT_REJECT = "MESSAGE_AUDIT_REJECT",
134
- /** 当用户创建主题时 */
135
- FORUM_THREAD_CREATE = "FORUM_THREAD_CREATE",
136
- /** 当用户更新主题时 */
137
- FORUM_THREAD_UPDATE = "FORUM_THREAD_UPDATE",
138
- /** 当用户删除主题时 */
139
- FORUM_THREAD_DELETE = "FORUM_THREAD_DELETE",
140
- /** 当用户创建帖子时 */
141
- FORUM_POST_CREATE = "FORUM_POST_CREATE",
142
- /** 当用户删除帖子时 */
143
- FORUM_POST_DELETE = "FORUM_POST_DELETE",
144
- /** 当用户回复评论时 */
145
- FORUM_REPLY_CREATE = "FORUM_REPLY_CREATE",
146
- /** 当用户回复评论时 */
147
- FORUM_REPLY_DELETE = "FORUM_REPLY_DELETE",
148
- /** 当用户发表审核通过时 */
149
- FORUM_PUBLISH_AUDIT_RESULT = "FORUM_PUBLISH_AUDIT_RESULT",
150
- /** 音频开始播放时 */
151
- AUDIO_START = "AUDIO_START",
152
- /** 音频播放结束时 */
153
- AUDIO_FINISH = "AUDIO_FINISH",
154
- /** 上麦时 */
155
- AUDIO_ON_MIC = "AUDIO_ON_MIC",
156
- /** 下麦时 */
157
- AUDIO_OFF_MIC = "AUDIO_OFF_MIC",
158
- /** 当收到@机器人的消息时 */
159
- AT_MESSAGE_CREATE = "AT_MESSAGE_CREATE",
160
- /** 当频道的消息被删除时 */
161
- PUBLIC_MESSAGE_DELETE = "PUBLIC_MESSAGE_DELETE"
162
- }
163
- /**
164
- * 子事件基类
165
- */
166
- export interface BaseEvent {
167
- /** opcode */
168
- op: Opcode.Dispatch;
169
- /** 序列号 */
170
- s: number;
171
- /** 事件类型 */
172
- t: EventEnum;
173
- }
174
- /**
175
- * READY子事件
176
- */
177
- export interface ReadyEvent extends BaseEvent {
178
- /** 事件类型 */
179
- t: EventEnum.READY;
180
- /** 事件内容 */
181
- d: {
182
- version: number;
183
- session_id: string;
184
- user: {
185
- /** 机器人的user_id */
186
- id: string;
187
- /** 机器人的nickname */
188
- username: string;
189
- bot: boolean;
190
- status: number;
191
- };
192
- shard: Number[];
193
- };
194
- }
195
- /**
196
- * C2C_MESSAGE_CREATE子事件
197
- */
198
- export interface C2CMsgEvent extends BaseEvent {
199
- /** 事件类型 */
200
- t: EventEnum.C2C_MESSAGE_CREATE;
201
- /** 平台方事件ID 格式: C2C_MESSAGE_CREATE:abc... */
202
- id: string;
203
- d: {
204
- /** 富媒体消息 */
205
- attachments?: Array<Attachment>;
206
- /** 发送者信息 */
207
- author: {
208
- /** 发送者的id 目前版本和user_openid一致 */
209
- id: string;
210
- /** 发送者的user_openid */
211
- user_openid: string;
212
- };
213
- /** 消息内容 */
214
- content: string;
215
- /** 消息ID message_id */
216
- id: string;
217
- /** 消息发送时间 */
218
- timestamp: string;
219
- };
220
- }
221
- /**
222
- * GROUP_AT_MESSAGE_CREATE子事件
223
- */
224
- export interface GroupMsgEvent extends BaseEvent {
225
- /** 事件类型 */
226
- t: EventEnum.GROUP_AT_MESSAGE_CREATE;
227
- /** 平台方事件ID 格式: GROUP_AT_MESSAGE_CREATE:abc... */
228
- id: string;
229
- d: {
230
- /** 富媒体消息 */
231
- attachments?: Array<Attachment>;
232
- /** 发送者信息 */
233
- author: {
234
- /** 发送者的id 目前版本和user_openid一致 */
235
- id: string;
236
- /** 发送者的user_openid */
237
- member_openid: string;
238
- };
239
- /** 消息内容 */
240
- content: string;
241
- /** 群ID group_id 目前版本和group_openid一致 */
242
- group_id: string;
243
- /** 消息ID group_openid */
244
- group_openid: string;
245
- /** 消息ID message_id */
246
- id: string;
247
- /** 消息发送时间 */
248
- timestamp: string;
249
- };
250
- }
251
- /**
252
- * 频道的user信息
253
- */
254
- export interface GuildUser {
255
- /** 发送者的头像url */
256
- avatar: string;
257
- /** 发送者是否为bot */
258
- bot: boolean;
259
- /** 发送者的id */
260
- id: string;
261
- /** 发送者的nickname */
262
- username: string;
263
- }
264
- /** 基础消息事件 */
265
- export interface BaseMessageEvent {
266
- /** 消息ID message_id */
267
- id: string;
268
- /** 消息内容 */
269
- content: string;
270
- /** 富媒体消息 */
271
- attachments?: Array<Attachment>;
272
- /** 消息发送时间 */
273
- timestamp: string;
274
- }
275
- /** Guild 消息的通用结构 */
276
- export interface GuildMemberInfo {
277
- /** 用户加入频道的时间 ISO8601 timestamp */
278
- joined_at: string;
279
- /** 用户在频道内的昵称 */
280
- nick: string;
281
- /** 用户在频道内的身份组ID */
282
- roles: string[];
283
- }
284
- /** Guild 事件的公共部分 */
285
- export interface GuildBaseEvent extends BaseMessageEvent {
286
- /** 发送者信息 */
287
- author: GuildUser;
288
- /** 子频道id */
289
- channel_id: string;
290
- /** 频道id */
291
- guild_id: string;
292
- /** 用于消息间的排序 */
293
- seq: number;
294
- /** 子频道消息 seq */
295
- seq_in_channel: number;
296
- /** 消息创建者的member信息 */
297
- member: GuildMemberInfo;
298
- /** 引用消息对象 */
299
- message_reference?: {
300
- /** 引用回复的消息 id */
301
- message_id: string;
302
- /** 是否忽略获取引用消息详情错误,默认否 */
303
- ignore_get_message_error: boolean;
304
- };
305
- /** 附件 */
306
- attachments?: Attachment[];
307
- }
308
- /**
309
- * 频道文字子频道消息
310
- */
311
- export interface GuildMsgEvent extends BaseEvent {
312
- /** 事件类型 */
313
- t: EventEnum.MESSAGE_CREATE | EventEnum.AT_MESSAGE_CREATE;
314
- /** 平台方事件ID */
315
- id: string;
316
- /** 事件内容 */
317
- d: GuildBaseEvent & {
318
- /** 消息中at的人 */
319
- mentions: [GuildUser];
320
- /** 是否at all */
321
- mention_everyone?: boolean;
322
- };
323
- }
324
- /**
325
- * 频道私信消息
326
- */
327
- export interface DirectMsgEvent extends BaseEvent {
328
- /** 事件类型 */
329
- t: EventEnum.DIRECT_MESSAGE_CREATE;
330
- /** 平台方事件ID */
331
- id: string;
332
- /** 事件内容 */
333
- d: GuildBaseEvent & {
334
- /** 是否为私信 */
335
- direct_message: boolean;
336
- /** 消息来源的频道id */
337
- src_guild_id: string;
338
- /** 未知字段 */
339
- seq_in_channel: string;
340
- };
341
- }
342
- /**
343
- * 机器人加入群聊事件
344
- */
345
- export interface GroupAddRobotEvent extends BaseEvent {
346
- t: EventEnum.GROUP_ADD_ROBOT;
347
- op: 0;
348
- /** 平台方消息ID */
349
- id: string;
350
- d: {
351
- /** 加入的时间戳 */
352
- timestamp: number;
353
- /** 加入群的群openid */
354
- group_openid: string;
355
- /** 操作添加机器人进群的群成员openid */
356
- op_member_openid: '0337369D1F67F72EA9EEB6287B600488';
357
- };
358
- }
359
- /**
360
- * 机器人被移出群聊事件
361
- */
362
- export interface GroupDelRobotEvent extends BaseEvent {
363
- t: EventEnum.GROUP_DEL_ROBOT;
364
- op: 0;
365
- /** 平台方消息ID */
366
- id: string;
367
- d: {
368
- /** 移出的时间戳 */
369
- timestamp: number;
370
- /** 移出群的群openid */
371
- group_openid: string;
372
- /** 操作移出机器人的群成员openid */
373
- op_member_openid: '0337369D1F67F72EA9EEB6287B600488';
374
- };
375
- }
376
- /**
377
- * 群聊拒绝机器人主动消息
378
- */
379
- export interface GroupMsgRejectEvent extends BaseEvent {
380
- t: EventEnum.GROUP_MSG_REJECT;
381
- op: 0;
382
- /** 平台方消息ID */
383
- id: string;
384
- d: {
385
- /** 操作时间戳 */
386
- timestamp: number;
387
- /** 操作群的群openid */
388
- group_openid: string;
389
- /** 操作拒绝机器人主动消息的群成员openid */
390
- op_member_openid: '0337369D1F67F72EA9EEB6287B600488';
391
- };
392
- }
393
- /**
394
- * 群聊接受机器人主动消息
395
- */
396
- export interface GroupMsgReceiveEvent extends BaseEvent {
397
- t: EventEnum.GROUP_MSG_RECEIVE;
398
- op: 0;
399
- /** 平台方消息ID */
400
- id: string;
401
- d: {
402
- /** 操作时间戳 */
403
- timestamp: number;
404
- /** 操作群的群openid */
405
- group_openid: string;
406
- /** 操作接受机器人主动消息的群成员openid */
407
- op_member_openid: '0337369D1F67F72EA9EEB6287B600488';
408
- };
409
- }
410
- /**
411
- * 用户添加机器人事件
412
- */
413
- export interface FriendAddEvent extends BaseEvent {
414
- t: EventEnum.FRIEND_ADD;
415
- op: 0;
416
- /** 平台方消息ID */
417
- id: string;
418
- d: {
419
- /** 添加时间戳 */
420
- timestamp: number;
421
- /** 添加机器人的用户openid */
422
- openid: string;
423
- };
424
- }
425
- /**
426
- * 用户删除机器人事件
427
- */
428
- export interface FriendDelEvent extends BaseEvent {
429
- t: EventEnum.FRIEND_DEL;
430
- op: 0;
431
- /** 平台方消息ID */
432
- id: string;
433
- d: {
434
- /** 删除时间戳 */
435
- timestamp: number;
436
- /** 删除机器人的用户openid */
437
- openid: string;
438
- };
439
- }
440
- /**
441
- * 用户在机器人资料卡手动关闭"主动消息"推送
442
- */
443
- export interface C2CMsgRejectEvent extends BaseEvent {
444
- t: EventEnum.C2C_MSG_REJECT;
445
- op: 0;
446
- /** 平台方消息ID */
447
- id: string;
448
- d: {
449
- /** 操作时间戳 */
450
- timestamp: number;
451
- /** 操作关闭主动消息推送的用户openid */
452
- openid: string;
453
- };
454
- }
455
- /**
456
- * 用户在机器人资料卡手动开启"主动消息"推送开关
457
- */
458
- export interface C2CMsgReceiveEvent extends BaseEvent {
459
- t: EventEnum.C2C_MSG_RECEIVE;
460
- op: 0;
461
- /** 平台方消息ID */
462
- id: string;
463
- d: {
464
- /** 操作时间戳 */
465
- timestamp: number;
466
- /** 操作开启主动消息推送的用户openid */
467
- openid: string;
468
- };
469
- }
470
- /**
471
- * 所有事件
472
- */
473
- export type Event = ReadyEvent | C2CMsgEvent | GroupMsgEvent | GuildMsgEvent | DirectMsgEvent | GroupAddRobotEvent | GroupDelRobotEvent | GroupMsgRejectEvent | GroupMsgReceiveEvent | FriendAddEvent | FriendDelEvent | C2CMsgRejectEvent | C2CMsgReceiveEvent;
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- /** 获取调用凭证返回类型 */
2
- export interface AccessTokenResponse {
3
- /** 获取到的凭证 */
4
- accessToken: string;
5
- /** 凭证有效时间,单位:秒。目前是7200秒之内的值。 */
6
- expiresIn: number;
7
- }
8
- /**
9
- * @description 获取调用凭证
10
- * @param url 请求地址
11
- * @param appId 机器人ID
12
- * @param secret 机器人密钥
13
- * @returns 获取到的凭证
14
- * @throws 获取调用凭证失败
15
- */
16
- export declare const getAccessToken: (url: string, appId: string, secret: string) => Promise<{
17
- accessToken: any;
18
- expiresIn: any;
19
- }>;
20
- /**
21
- * @description 创建axios实例
22
- * @param url 请求地址
23
- * @param appId 机器人ID
24
- */
25
- export declare const createAxiosInstance: (url: string, appId: string) => import("axios").AxiosInstance;
@@ -1,46 +0,0 @@
1
- import axios from 'node-karin/axios';
2
- /** 存储Bot对应的鉴权凭证 */
3
- const BotMap = new Map();
4
- /**
5
- * @description 获取调用凭证
6
- * @param url 请求地址
7
- * @param appId 机器人ID
8
- * @param secret 机器人密钥
9
- * @returns 获取到的凭证
10
- * @throws 获取调用凭证失败
11
- */
12
- export const getAccessToken = async (url, appId, secret) => {
13
- const response = await axios.post(url, {
14
- appId: String(appId),
15
- clientSecret: secret,
16
- });
17
- const { access_token: accessToken, expires_in: expiresIn } = response.data;
18
- if (!accessToken || !expiresIn) {
19
- throw new Error(`获取调用凭证失败: ${JSON.stringify(response.data)}`);
20
- }
21
- BotMap.set(appId, accessToken);
22
- /** 剩下1分钟开始刷新 */
23
- setTimeout(() => {
24
- getAccessToken(url, appId, secret);
25
- }, Number(expiresIn) * 1000 - 50000);
26
- return { accessToken, expiresIn };
27
- };
28
- /**
29
- * @description 创建axios实例
30
- * @param url 请求地址
31
- * @param appId 机器人ID
32
- */
33
- export const createAxiosInstance = (url, appId) => {
34
- const instance = axios.create({
35
- baseURL: url,
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- },
39
- timeout: 5500,
40
- });
41
- instance.interceptors.request.use((config) => {
42
- config.headers.Authorization = `QQBot ${BotMap.get(appId)}`;
43
- return config;
44
- });
45
- return instance;
46
- };
@@ -1,22 +0,0 @@
1
- import nacl from 'tweetnacl';
2
- /**
3
- * 从提供的种子生成密钥对
4
- * @param seed 用于生成密钥的种子
5
- */
6
- export declare const generateKeyPair: (seed: string) => nacl.SignKeyPair;
7
- /**
8
- * 使用提供的私钥、事件时间戳和明文令牌对消息进行签名
9
- * @param privateKey 用于签名的私钥
10
- * @param eventTs 计算签名使用时间戳
11
- * @param plainToken 需要计算签名的字符串
12
- * @returns 生成的十六进制格式的签名
13
- */
14
- export declare const signMessage: (privateKey: Uint8Array, eventTs: string, plainToken: string) => string;
15
- /**
16
- * 签名
17
- * @param secret 机器人密钥
18
- * @param eventTs 计算签名使用时间戳
19
- * @param plainToken 需要计算签名的字符串
20
- * @returns 生成的十六进制格式的签名
21
- */
22
- export declare const sign: (secret: string, eventTs: string, plainToken: string) => string;