@alemonjs/qq-bot 0.0.12 → 0.0.14

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 (54) hide show
  1. package/README.md +27 -12
  2. package/dist/assets/index.css +472 -1
  3. package/dist/assets/index.js +11002 -14
  4. package/dist/index.html +1 -1
  5. package/lib/api.d.ts +971 -843
  6. package/lib/api.js +1172 -1156
  7. package/lib/client.d.ts +22 -22
  8. package/lib/client.js +201 -217
  9. package/lib/config.js +2 -2
  10. package/lib/desktop.js +3 -1
  11. package/lib/from.js +27 -34
  12. package/lib/index.d.ts +3 -3
  13. package/lib/index.group.js +226 -0
  14. package/lib/index.guild.js +320 -0
  15. package/lib/index.js +59 -38
  16. package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -35
  17. package/lib/message/C2C_MESSAGE_CREATE.d.ts +9 -9
  18. package/lib/message/CHANNEL_CREATE.d.ts +15 -15
  19. package/lib/message/CHANNEL_DELETE.d.ts +15 -15
  20. package/lib/message/CHANNEL_UPDATE.d.ts +15 -15
  21. package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -29
  22. package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -17
  23. package/lib/message/ERROR.d.ts +2 -2
  24. package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +10 -10
  25. package/lib/message/GUILD_CREATE.d.ts +15 -15
  26. package/lib/message/GUILD_DELETE.d.ts +15 -15
  27. package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -14
  28. package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -14
  29. package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -14
  30. package/lib/message/GUILD_UPDATE.d.ts +15 -15
  31. package/lib/message/INTERACTION_CREATE.d.ts +2 -2
  32. package/lib/message/MESSAGE_CREATE.d.ts +2 -2
  33. package/lib/message/MESSAGE_DELETE.d.ts +2 -2
  34. package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -13
  35. package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -13
  36. package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -15
  37. package/lib/message/READY.d.ts +6 -6
  38. package/lib/message.d.ts +46 -46
  39. package/lib/sdk/api.d.ts +847 -0
  40. package/lib/sdk/api.js +1184 -0
  41. package/lib/sdk/client.js +228 -0
  42. package/lib/sdk/config.js +3 -0
  43. package/lib/sdk/counter.js +19 -0
  44. package/lib/sdk/from.js +44 -0
  45. package/lib/sdk/intents.js +102 -0
  46. package/lib/sdk/typing.d.ts +56 -0
  47. package/lib/sdk/webhook.secret.js +53 -0
  48. package/lib/sdk/websoket.group.js +221 -0
  49. package/lib/sdk/websoket.guild.js +203 -0
  50. package/lib/send/index.js +97 -21
  51. package/lib/typing.d.ts +62 -54
  52. package/lib/utils.js +14 -0
  53. package/lib/webhook.js +46 -48
  54. package/package.json +4 -1
package/lib/sdk/api.js ADDED
@@ -0,0 +1,1184 @@
1
+ import axios from 'axios';
2
+ import { config } from './config.js';
3
+ import FormData from 'form-data';
4
+ import { createPicFrom } from './from.js';
5
+
6
+ class QQBotAPI {
7
+ /**
8
+ * qq机器人
9
+ */
10
+ BOTS_API_RUL = 'https://bots.qq.com';
11
+ /**
12
+ * qq群 沙河接口
13
+ */
14
+ API_URL_SANDBOX = 'https://sandbox.api.sgroup.qq.com';
15
+ /**
16
+ * qq群
17
+ */
18
+ API_URL = 'https://api.sgroup.qq.com';
19
+ /**
20
+ * 得到鉴权
21
+ * @param appId
22
+ * @param clientSecret
23
+ * @param url
24
+ * @returns
25
+ */
26
+ getAuthentication(app_id, clientSecret) {
27
+ return axios.post(`${this.BOTS_API_RUL}/app/getAppAccessToken`, {
28
+ appId: app_id,
29
+ clientSecret: clientSecret
30
+ });
31
+ }
32
+ /**
33
+ * group
34
+ * @param config
35
+ * @returns
36
+ */
37
+ async groupService(options) {
38
+ const app_id = config.get('app_id');
39
+ // 群聊是加密token
40
+ const token = config.get('access_token');
41
+ const service = await axios.create({
42
+ baseURL: this.API_URL,
43
+ timeout: 20000,
44
+ headers: {
45
+ 'X-Union-Appid': app_id,
46
+ 'Authorization': `QQBot ${token}`
47
+ }
48
+ });
49
+ return service(options);
50
+ }
51
+ /**
52
+ * guild
53
+ * @param opstion
54
+ * @returns
55
+ */
56
+ async guildServer(opstion) {
57
+ const app_id = config.get('app_id');
58
+ const token = config.get('token');
59
+ const sandbox = config.get('sandbox');
60
+ const service = await axios.create({
61
+ baseURL: sandbox ? this.API_URL_SANDBOX : this.API_URL,
62
+ timeout: 20000,
63
+ headers: {
64
+ Authorization: `Bot ${app_id}.${token}`
65
+ }
66
+ });
67
+ return service(opstion);
68
+ }
69
+ /**
70
+ * 得到鉴权
71
+ * @returns
72
+ */
73
+ async gateway() {
74
+ let service = '';
75
+ switch (config.get('mode')) {
76
+ case 'group':
77
+ service = 'groupService';
78
+ break;
79
+ case 'guild':
80
+ service = 'guildServer';
81
+ break;
82
+ default:
83
+ service = 'groupService';
84
+ }
85
+ return this[service]({
86
+ url: '/gateway'
87
+ }).then(res => res?.data);
88
+ }
89
+ /**
90
+ * 发送私聊消息
91
+ * @param openid
92
+ * @param content
93
+ * @param msg_id
94
+ * @returns
95
+ * 0 文本 1 图文 2 md 3 ark 4 embed
96
+ */
97
+ async usersOpenMessages(openid, data, _msg_id) {
98
+ return this.groupService({
99
+ url: `/v2/users/${openid}/messages`,
100
+ method: 'post',
101
+ data: data
102
+ }).then(res => res?.data);
103
+ }
104
+ // /\[🔗[^\]]+\]\([^)]+\)|@everyone/.test(content)
105
+ #map = new Map();
106
+ /**
107
+ * 得到消息序列
108
+ * @param MessageId
109
+ * @returns
110
+ */
111
+ getMessageSeq(MessageId) {
112
+ let seq = this.#map.get(MessageId) || 0;
113
+ seq++;
114
+ this.#map.set(MessageId, seq);
115
+ // 如果映射表大小超过 100,则删除最早添加的 MessageId
116
+ if (this.#map.size > 100) {
117
+ const firstKey = this.#map.keys().next().value;
118
+ if (firstKey)
119
+ this.#map.delete(firstKey);
120
+ }
121
+ return seq;
122
+ }
123
+ /**
124
+ * 发送群聊消息
125
+ * @param group_openid
126
+ * @param content
127
+ * @param msg_id
128
+ * @returns
129
+ */
130
+ async groupOpenMessages(group_openid, data) {
131
+ return this.groupService({
132
+ url: `/v2/groups/${group_openid}/messages`,
133
+ method: 'post',
134
+ data: data
135
+ }).then(res => res?.data);
136
+ }
137
+ /**
138
+ * 发送私聊富媒体文件
139
+ * @param openid
140
+ * @param content
141
+ * @param file_type
142
+ * @returns
143
+ * 1 图文 2 视频 3 语言 4 文件
144
+ * 图片:png/jpg,视频:mp4,语音:silk
145
+ */
146
+ async postRichMediaByUsers(openid, data) {
147
+ return this.groupService({
148
+ url: `/v2/users/${openid}/files`,
149
+ method: 'post',
150
+ data: data
151
+ }).then(res => res?.data);
152
+ }
153
+ /**
154
+ * 发送私聊富媒体文件
155
+ * @param openid
156
+ * @param content
157
+ * @param file_type
158
+ * @returns
159
+ * 1 图文 2 视频 3 语言 4 文件
160
+ * 图片:png/jpg,视频:mp4,语音:silk
161
+ */
162
+ async userFiles(openid, data) {
163
+ return this.groupService({
164
+ url: `/v2/users/${openid}/files`,
165
+ method: 'post',
166
+ data: data
167
+ }).then(res => res?.data);
168
+ }
169
+ /**
170
+ * 发送群里文件
171
+ * @param openid
172
+ * @param content
173
+ * @param file_type
174
+ * @returns
175
+ * 1 图文 2 视频 3 语言 4 文件
176
+ * 图片:png/jpg,视频:mp4,语音:silk
177
+ */
178
+ async postRichMediaByGroup(openid, data) {
179
+ return this.groupService({
180
+ url: `/v2/groups/${openid}/files`,
181
+ method: 'post',
182
+ data: {
183
+ srv_send_msg: false,
184
+ ...data
185
+ }
186
+ }).then(res => res?.data);
187
+ }
188
+ /**
189
+ *
190
+ * @param openid
191
+ * @param data
192
+ * @returns
193
+ */
194
+ async groupsFiles(openid, data) {
195
+ return this.groupService({
196
+ url: `/v2/groups/${openid}/files`,
197
+ method: 'post',
198
+ data: {
199
+ srv_send_msg: false,
200
+ ...data
201
+ }
202
+ }).then(res => res?.data);
203
+ }
204
+ /**
205
+ * 创建模板
206
+ * *********
207
+ * 使用该方法,你需要申请模板Id
208
+ * 并设置markdown源码为{{.text_0}}{{.text_1}}
209
+ * {{.text_2}}{{.text_3}}{{.text_4}}{{.text_5}}
210
+ * {{.text_6}}{{.text_7}}{{.text_8}}{{.text_9}}
211
+ * 当前,你也可以传递回调对key和values进行休整
212
+ * @param custom_template_id
213
+ * @param mac 默认 9
214
+ * @param callBack 默认 (key,values)=>({key,values})
215
+ * @returns
216
+ */
217
+ createTemplate(custom_template_id, mac = 10, callBack = (key, values) => ({ key, values })) {
218
+ let size = -1;
219
+ const params = [];
220
+ const Id = custom_template_id;
221
+ /**
222
+ * 消耗一个参数
223
+ * @param value 值
224
+ * @param change 是否换行
225
+ * @returns
226
+ */
227
+ const text = (value, change = false) => {
228
+ // 仅限push
229
+ if (size > mac - 1)
230
+ return;
231
+ size++;
232
+ params.push(callBack(`text_${size}`, [`${value}${change ? '\r' : ''}`]));
233
+ };
234
+ /**
235
+ * 消耗一个参数
236
+ * @param start 开始的值
237
+ * @param change 是否换行
238
+ * @returns
239
+ */
240
+ const prefix = (start, label) => {
241
+ text(`${start}[${label}]`);
242
+ };
243
+ /**
244
+ * 消耗一个参数
245
+ * @param param0.value 发送的值
246
+ * @param param0.enter 是否自动发送
247
+ * @param param0.reply 是否回复
248
+ * @param param0.change 是否换行
249
+ * @param param0.end 尾部字符串
250
+ */
251
+ const suffix = ({ value, enter = true, reply = false, change = false, end = '' }) => {
252
+ text(`(mqqapi://aio/inlinecmd?command=${value}&enter=${enter}&reply=${reply})${end}${change ? '\r' : ''}`);
253
+ };
254
+ /**
255
+ * 消耗2个参数
256
+ * @param param0.label 显示的值
257
+ * @param param0.value 发送的值
258
+ * @param param0.enter 是否自动发送
259
+ * @param param0.reply 是否回复
260
+ * @param param0.change 是否换行
261
+ * @param param0.start 头部字符串
262
+ * @param param0.end 尾部字符串
263
+ */
264
+ const button = ({ label, value, start = '', end = '', enter = true, reply = false, change = false }) => {
265
+ // size 只少留两个
266
+ if (size > mac - 1 - 2)
267
+ return;
268
+ prefix(start, label);
269
+ suffix({ value, enter, reply, change, end });
270
+ };
271
+ /**
272
+ * **********
273
+ * 代码块
274
+ * **********
275
+ * 跟在后面
276
+ * 前面需要设置换行
277
+ * 消耗4个参数
278
+ * @param val
279
+ * @returns
280
+ */
281
+ const code = (val) => {
282
+ // size 至少留4个
283
+ if (size > mac - 1 - 4)
284
+ return;
285
+ text('``');
286
+ text('`javascript\r' + val);
287
+ text('\r`');
288
+ text('``\r');
289
+ };
290
+ const getParam = () => {
291
+ return {
292
+ msg_type: 2,
293
+ markdown: {
294
+ custom_template_id: Id,
295
+ params
296
+ }
297
+ };
298
+ };
299
+ return {
300
+ size,
301
+ text,
302
+ prefix,
303
+ suffix,
304
+ button,
305
+ code,
306
+ getParam
307
+ };
308
+ }
309
+ /**
310
+ *
311
+ * @param openid
312
+ * @param message_id
313
+ * @returns
314
+ */
315
+ userMessageDelete(openid, message_id) {
316
+ return this.groupService({
317
+ url: `/v2/users/${openid}/messages/${message_id}`,
318
+ method: 'delete'
319
+ }).then(res => res?.data);
320
+ }
321
+ /**
322
+ *
323
+ * @param group_openid
324
+ * @param message_id
325
+ * @returns
326
+ */
327
+ grouMessageDelte(group_openid, message_id) {
328
+ return this.groupService({
329
+ url: `/v2/groups/${group_openid}/messages/${message_id}`,
330
+ method: 'delete'
331
+ }).then(res => res?.data);
332
+ }
333
+ /**
334
+ * 创建form
335
+ * @param image
336
+ * @param msg_id
337
+ * @param content
338
+ * @param name
339
+ * @returns
340
+ */
341
+ async createFrom(image, msg_id, content, Name = 'image.jpg') {
342
+ const from = await createPicFrom(image, Name);
343
+ if (!from)
344
+ return false;
345
+ const { picData, name } = from;
346
+ const formdata = new FormData();
347
+ formdata.append('msg_id', msg_id);
348
+ if (typeof content === 'string')
349
+ formdata.append('content', content);
350
+ formdata.append('file_image', picData, name);
351
+ return formdata;
352
+ }
353
+ /**
354
+ * ************
355
+ * 消息-图片接口
356
+ * ***********
357
+ */
358
+ /**
359
+ * 发送buffer图片
360
+ * @param id 私信传频道id,公信传子频道id
361
+ * @param message {消息编号,图片,内容}
362
+ * @param isGroup 是否是群聊
363
+ * @returns
364
+ */
365
+ async postImage(channel_id, message) {
366
+ const formdata = await this.createFrom(message.image, message.msg_id, message.content, message.name);
367
+ const dary = formdata != false ? formdata.getBoundary() : '';
368
+ return this.guildServer({
369
+ method: 'post',
370
+ url: `/channels/${channel_id}/messages`,
371
+ headers: {
372
+ 'Content-Type': `multipart/form-data; boundary=${dary}`
373
+ },
374
+ data: formdata
375
+ }).then(res => res?.data);
376
+ }
377
+ /**
378
+ * 私聊发送buffer图片
379
+ * @param id 私信传频道id,公信传子频道id
380
+ * @param message {消息编号,图片,内容}
381
+ * @returns
382
+ */
383
+ async postDirectImage(guild_id, message) {
384
+ const formdata = await this.createFrom(message.image, message.msg_id, message.content, message.name);
385
+ const dary = formdata != false ? formdata.getBoundary() : '';
386
+ return this.guildServer({
387
+ method: 'post',
388
+ url: `/dms/${guild_id}/messages`,
389
+ headers: {
390
+ 'Content-Type': `multipart/form-data; boundary=${dary}`
391
+ },
392
+ data: formdata
393
+ }).then(res => res?.data);
394
+ }
395
+ /**
396
+ * ********
397
+ * 用户api
398
+ * *******
399
+ */
400
+ /**
401
+ * 获取用户详情
402
+ * @param message
403
+ * @returns
404
+ */
405
+ async usersMe() {
406
+ return this.guildServer({
407
+ method: 'get',
408
+ url: `/users/@me`
409
+ }).then(res => res?.data);
410
+ }
411
+ /**
412
+ * 获取用户频道列表
413
+ * @param message
414
+ * @returns
415
+ */
416
+ async usersMeGuilds(params) {
417
+ return this.guildServer({
418
+ method: 'get',
419
+ url: `/users/@me/guilds`,
420
+ params
421
+ }).then(res => res?.data);
422
+ }
423
+ /**
424
+ * **********
425
+ * 频道api
426
+ * **********
427
+ */
428
+ /**
429
+ * 获取频道详细
430
+ * @param guild_id
431
+ * @returns
432
+ */
433
+ async guilds(guild_id) {
434
+ return this.guildServer({
435
+ method: 'get',
436
+ url: `/guilds/${guild_id}`
437
+ }).then(res => res?.data);
438
+ }
439
+ /**
440
+ * ************
441
+ * 子频道api
442
+ * ***********
443
+ */
444
+ /**
445
+ * 获取子频道列表
446
+ * @param guild_id
447
+ * @returns
448
+ */
449
+ async guildsChannels(guild_id) {
450
+ return this.guildServer({
451
+ method: 'get',
452
+ url: `/guilds/${guild_id}/channels`
453
+ }).then(res => res?.data);
454
+ }
455
+ /**
456
+ * 获取子频道详情
457
+ * @param channel_id
458
+ * @returns
459
+ */
460
+ async channels(channel_id) {
461
+ return this.guildServer({
462
+ method: 'get',
463
+ url: `/channels/${channel_id}`
464
+ }).then(res => res?.data);
465
+ }
466
+ /**
467
+ * 创建子频道
468
+ * @param guild_id
469
+ * @returns
470
+ */
471
+ async guildsChannelsCreate(guild_id, data) {
472
+ return this.guildServer({
473
+ method: 'post',
474
+ url: `/guilds/${guild_id}/channels`,
475
+ data
476
+ }).then(res => res?.data);
477
+ }
478
+ /**
479
+ * 创建子频道
480
+ * @param channel_id
481
+ * @returns
482
+ */
483
+ async guildsChannelsUpdate(channel_id, data) {
484
+ return this.guildServer({
485
+ method: 'PATCH',
486
+ url: `/channels/${channel_id}`,
487
+ data
488
+ }).then(res => res?.data);
489
+ }
490
+ /**
491
+ * 删除子频道
492
+ * @param channel_id
493
+ * @param data
494
+ * @returns
495
+ */
496
+ async guildsChannelsdelete(channel_id, data) {
497
+ return this.guildServer({
498
+ method: 'DELETE',
499
+ url: `/channels/${channel_id}`,
500
+ data
501
+ }).then(res => res?.data);
502
+ }
503
+ /**
504
+ * 获取在线成员数
505
+ * @param channel_id
506
+ * @returns
507
+ */
508
+ async channelsChannelOnlineNums(channel_id) {
509
+ return this.guildServer({
510
+ method: 'GET',
511
+ url: `/channels/${channel_id}/online_nums`
512
+ }).then(res => res?.data);
513
+ }
514
+ /**
515
+ * *********
516
+ * 成员api
517
+ * *********
518
+ */
519
+ /**
520
+ * 获取频道成员列表
521
+ * @param guild_id
522
+ * @returns
523
+ */
524
+ async guildsMembers(guild_id, params) {
525
+ return this.guildServer({
526
+ method: 'GET',
527
+ url: `/guilds/${guild_id}/members`,
528
+ params
529
+ }).then(res => res?.data);
530
+ }
531
+ /**
532
+ * 获取频道身份组成员列表
533
+ * @param guild_id
534
+ * @param role_id
535
+ * @param params
536
+ * @returns
537
+ */
538
+ async guildsRolesMembers(guild_id, role_id, params) {
539
+ return this.guildServer({
540
+ method: 'GET',
541
+ url: `/guilds/${guild_id}/roles/${role_id}/members`,
542
+ params
543
+ }).then(res => res?.data);
544
+ }
545
+ /**
546
+ * 获取成员详情
547
+ * @param guild_id
548
+ * @param user_id
549
+ * @returns
550
+ */
551
+ async guildsMembersMessage(guild_id, user_id) {
552
+ return this.guildServer({
553
+ method: 'GET',
554
+ url: `/guilds/${guild_id}/members/${user_id}`
555
+ }).then(res => res?.data);
556
+ }
557
+ /**
558
+ * 删除频道成员
559
+ * @param guild_id
560
+ * @param user_id
561
+ * @returns
562
+ */
563
+ async guildsMembersDelete(guild_id, user_id) {
564
+ return this.guildServer({
565
+ method: 'DELETE',
566
+ url: `/guilds/${guild_id}/members/${user_id}`
567
+ }).then(res => res?.data);
568
+ }
569
+ /**
570
+ * 获取指定消息
571
+ * @param channel_id
572
+ * @param message_id
573
+ * @returns
574
+ */
575
+ async channelsMessages(channel_id, message_id) {
576
+ return this.guildServer({
577
+ method: 'GET',
578
+ url: `/channels/${channel_id}/messages/${message_id}`
579
+ }).then(res => res?.data);
580
+ }
581
+ /**
582
+ * 发送消息
583
+ * @param channel_id
584
+ * @param message_id
585
+ * @param data
586
+ * @returns
587
+ */
588
+ async channelsMessagesPost(channel_id, data) {
589
+ return this.guildServer({
590
+ method: 'POST',
591
+ url: `/channels/${channel_id}/messages`,
592
+ data
593
+ }).then(res => res?.data);
594
+ }
595
+ /**
596
+ * 撤回消息
597
+ * @param channel_id
598
+ * @param message_id
599
+ * @param hidetip
600
+ * @returns
601
+ */
602
+ async channelsMessagesDelete(channel_id, message_id, hidetip = true) {
603
+ return this.guildServer({
604
+ method: 'DELETE',
605
+ url: `/channels/${channel_id}/messages/${message_id}?hidetip=${hidetip}`
606
+ }).then(res => res?.data);
607
+ }
608
+ /**
609
+ * ***********
610
+ * 频道身份api
611
+ * ***********
612
+ */
613
+ /**
614
+ * 获取频道身份组列表
615
+ * @param guild_id 频道id
616
+ * @returns
617
+ */
618
+ async guildsRoles(guild_id) {
619
+ return this.guildServer({
620
+ method: 'GET',
621
+ url: `/guilds/${guild_id}/roles`
622
+ }).then(res => res?.data);
623
+ }
624
+ /**
625
+ * 创建频道身份组
626
+ * @param guild_id 频道id
627
+ * @param {object} data 参数
628
+ * @param {object?} data.name 身份组名称
629
+ * @param {object?} data.color ARGB 的 HEX 十六进制颜色值转换后的十进制数值
630
+ * @param {object?} data.hoist 在成员列表中单独展示: 0-否, 1-是
631
+ * @returns
632
+ */
633
+ async guildsRolesPost(guild_id, data) {
634
+ return this.guildServer({
635
+ method: 'POST',
636
+ url: `/guilds/${guild_id}/roles`,
637
+ data
638
+ }).then(res => res?.data);
639
+ }
640
+ /**
641
+ * 修改频道身份组
642
+ * @param guild_id 频道id
643
+ * @param {object} data 参数
644
+ * @param {object?} data.name 身份组名称
645
+ * @param {object?} data.color ARGB 的 HEX 十六进制颜色值转换后的十进制数值
646
+ * @param {object?} data.hoist 在成员列表中单独展示: 0-否, 1-是
647
+ * @returns
648
+ */
649
+ async guildsRolesPatch(guild_id, role_id, data) {
650
+ return this.guildServer({
651
+ method: 'PATCH',
652
+ url: `/guilds/${guild_id}/roles/${role_id}`,
653
+ data
654
+ }).then(res => res?.data);
655
+ }
656
+ /**
657
+ * 删除频道身份组
658
+ * @param guild_id 频道id
659
+ * @param role_id 身份组id
660
+ */
661
+ async guildsRolesDelete(guild_id, role_id) {
662
+ return this.guildServer({
663
+ method: 'DELETE',
664
+ url: `/guilds/${guild_id}/roles/${role_id}`
665
+ }).then(res => res?.data);
666
+ }
667
+ /**
668
+ * 将成员添加到频道身份组
669
+ * @param guild_id 频道id
670
+ * @param channel_id 子频道id
671
+ * @param user_id 用户id
672
+ * @param role_id 身份组id
673
+ * @returns
674
+ */
675
+ async guildsRolesMembersPut(guild_id, channel_id, user_id, role_id) {
676
+ return this.guildServer({
677
+ method: 'PUT',
678
+ url: `/guilds/${guild_id}/members/${user_id}/roles/${role_id}`,
679
+ data: {
680
+ channel: {
681
+ id: channel_id
682
+ }
683
+ }
684
+ }).then(res => res?.data);
685
+ }
686
+ /**
687
+ * 将成员从频道身份组移除
688
+ * @param guild_id 频道id
689
+ * @param channel_id 子频道id
690
+ * @param user_id 用户id
691
+ * @param role_id 身份组id
692
+ * @returns
693
+ */
694
+ async guildsRolesMembersDelete(guild_id, channel_id, user_id, role_id) {
695
+ return this.guildServer({
696
+ method: 'DELETE',
697
+ url: `/guilds/${guild_id}/members/${user_id}/roles/${role_id}`,
698
+ data: {
699
+ channel: {
700
+ id: channel_id
701
+ }
702
+ }
703
+ }).then(res => res?.data);
704
+ }
705
+ /**
706
+ * **********
707
+ * 子频道权限api
708
+ * **********
709
+ */
710
+ /**
711
+ * 获取子频道用户权限
712
+ * @param channel_id 子频道id
713
+ * @param user_id 用户id
714
+ */
715
+ async channelsPermissions(channel_id, user_id) {
716
+ return this.guildServer({
717
+ method: 'GET',
718
+ url: `/channels/${channel_id}/members/${user_id}/permissions`
719
+ }).then(res => res?.data);
720
+ }
721
+ /**
722
+ * 修改子频道用户权限
723
+ * @param channel_id 子频道id
724
+ * @param user_id 用户id
725
+ * @param 参数包括add和remove两个字段分别表示授予的权限以及删除的权限。要授予用户权限即把add对应位置 1,删除用户权限即把remove对应位置 1。当两个字段同一位都为 1,表现为删除权限。
726
+ */
727
+ async channelsPermissionsPut(channel_id, user_id, add, remove) {
728
+ return this.guildServer({
729
+ method: 'PUT',
730
+ url: `/channels/${channel_id}/members/${user_id}/permissions`,
731
+ data: {
732
+ add,
733
+ remove
734
+ }
735
+ }).then(res => res?.data);
736
+ }
737
+ /**
738
+ * *******
739
+ * 消息api
740
+ * ********
741
+ */
742
+ /**
743
+ * ************
744
+ * 消息频率api
745
+ * **********
746
+ */
747
+ /**
748
+ * 查询频道消息频率限制
749
+ * @param guild_id 频道id
750
+ * @returns
751
+ */
752
+ async guildsMessageSetting(guild_id) {
753
+ return this.guildServer({
754
+ method: 'GET',
755
+ url: `/guilds/${guild_id}/message/setting`
756
+ }).then(res => res?.data);
757
+ }
758
+ /**
759
+ * ***********
760
+ * 私信api
761
+ * **********
762
+ */
763
+ /**
764
+ * 创建私信会话
765
+ * @param recipient_id 接收者 id
766
+ * @param source_guild_id 源频道 id
767
+ * @returns
768
+ */
769
+ async usersMeDms() {
770
+ return this.guildServer({
771
+ method: 'POST',
772
+ url: `/users/@me/dms`
773
+ }).then(res => res?.data);
774
+ }
775
+ /**
776
+ * 发送私信
777
+ * @param guild_id
778
+ * @returns
779
+ */
780
+ async dmsMessage(guild_id, data) {
781
+ return this.guildServer({
782
+ method: 'POST',
783
+ url: `/dms/${guild_id}/messages`,
784
+ data
785
+ }).then(res => res?.data);
786
+ }
787
+ /**
788
+ * 撤回私信
789
+ * @param guild_id
790
+ * @param data
791
+ * @returns
792
+ */
793
+ async dmsMessageDelete(guild_id, message_id, hidetip = true) {
794
+ return this.guildServer({
795
+ method: 'DELETE',
796
+ url: `/dms/${guild_id}/messages/${message_id}?hidetip=${hidetip}`
797
+ }).then(res => res?.data);
798
+ }
799
+ /**
800
+ * *********
801
+ * 禁言api
802
+ * *******
803
+ */
804
+ /**
805
+ * 全体禁言(非管理员)
806
+ * @param guild_id 频道id
807
+ * @param data { mute_end_timestamp:禁言结束时间戳, mute_seconds:禁言时长 } 两个参数必须传一个 优先级 mute_end_timestamp > mute_seconds
808
+ * 将mute_end_timestamp或mute_seconds传值为字符串'0',则表示解除全体禁言
809
+ */
810
+ async guildsMuteAll(guild_id, data) {
811
+ return this.guildServer({
812
+ method: 'PATCH',
813
+ url: `/guilds/${guild_id}/mute`,
814
+ data
815
+ }).then(res => res?.data);
816
+ }
817
+ /**
818
+ * 频道指定成员禁言
819
+ * @param guild_id 频道id
820
+ * @param user_id 用户id
821
+ * @param data { mute_end_timestamp:禁言结束时间戳, mute_seconds:禁言时长 } 两个参数必须传一个 优先级 mute_end_timestamp > mute_seconds
822
+ * 将mute_end_timestamp或mute_seconds传值为字符串'0',则表示解除禁言
823
+ * @returns
824
+ */
825
+ async guildsMemberMute(guild_id, user_id, data) {
826
+ return this.guildServer({
827
+ method: 'PATCH',
828
+ url: `/guilds/${guild_id}/members/${user_id}/mute`,
829
+ data
830
+ }).then(res => res?.data);
831
+ }
832
+ /**
833
+ * 频道批量禁言
834
+ * @param guild_id 频道id
835
+ * @param data { mute_end_timestamp:禁言结束时间戳, mute_seconds:禁言时长, user_ids:用户id数组 } 两个参数必须传一个 优先级 mute_end_timestamp > mute_seconds
836
+ * 将mute_end_timestamp或mute_seconds传值为字符串'0',则表示解除禁言
837
+ */
838
+ async guildsMute(guild_id, data) {
839
+ return this.guildServer({
840
+ method: 'PATCH',
841
+ url: `/guilds/${guild_id}/mute`,
842
+ data
843
+ }).then(res => res?.data);
844
+ }
845
+ /**
846
+ * *******
847
+ * 公告api
848
+ * *******
849
+ */
850
+ /**
851
+ * 创建频道公告
852
+ * 公告类型分为 消息类型的频道公告 和 推荐子频道类型的频道公告
853
+ * 详见 https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/announces/post_guild_announces.html#%E5%8A%9F%E8%83%BD%E6%8F%8F%E8%BF%B0
854
+ * @param guild_id 频道id
855
+ * @param data { message_id:消息id, channel_id:频道id, announces_type:公告类型, recommend_channels:推荐频道id数组 }
856
+ * @param channel_id 子频道id 消息id存在时必须传
857
+ * @param announces_type 0:成员公告 1:欢迎公告 默认为 0
858
+ * @param recommend_channels 推荐频道id数组 "recommend_channels": [{ "channel_id": "xxxx","introduce": "推荐语" }]
859
+ * @returns 返回Announces 对象 (https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/announces/model.html#Announces)
860
+ */
861
+ async guildsAnnounces(guild_id, data) {
862
+ return this.guildServer({
863
+ method: 'POST',
864
+ url: `/guilds/${guild_id}/announces`,
865
+ data
866
+ }).then(res => res?.data);
867
+ }
868
+ /**
869
+ * 删除频道公告
870
+ * @param guild_id 频道id
871
+ * @param message_id 消息id message_id 有值时,会校验 message_id 合法性,若不校验校验 message_id,请将 message_id 设置为 all
872
+ * @returns
873
+ */
874
+ async guildsAnnouncesDelete(guild_id, message_id) {
875
+ return this.guildServer({
876
+ method: 'DELETE',
877
+ url: `/guilds/${guild_id}/announces/${message_id}`
878
+ }).then(res => res?.data);
879
+ }
880
+ /**
881
+ * **********
882
+ * 精华消息api
883
+ * **********
884
+ */
885
+ /**
886
+ * 添加精华消息
887
+ * @param channel_id 频道id
888
+ * @param message_id 消息id
889
+ * @returns 返回 PinsMessage对象 { "guild_id": "xxxxxx", "channel_id": "xxxxxx", "message_ids": ["xxxxx"]}
890
+ * @returns message_ids 为当前请求后子频道内所有精华消息 message_id 数组
891
+ */
892
+ async channelsPinsPut(channel_id, message_id) {
893
+ return this.guildServer({
894
+ method: 'PUT',
895
+ url: `/channels/${channel_id}/pins/${message_id}`
896
+ }).then(res => res?.data);
897
+ }
898
+ /**
899
+ * 删除精华消息
900
+ * @param channel_id 子频道id
901
+ * @param message_id 消息id
902
+ * 删除子频道内全部精华消息,请将 message_id 设置为 all
903
+ * @returns
904
+ */
905
+ async channelsPinsDelete(channel_id, message_id) {
906
+ return this.guildServer({
907
+ method: 'DELETE',
908
+ url: `/channels/${channel_id}/pins/${message_id}`
909
+ }).then(res => res?.data);
910
+ }
911
+ /**
912
+ * 获取精华消息
913
+ * @param channel_id 子频道id
914
+ * @returns 返回 PinsMessage对象 { "guild_id": "xxxxxx", "channel_id": "xxxxxx", "message_ids": ["xxxxx"]}
915
+ * @returns message_ids 为当前请求后子频道内所有精华消息 message_id 数组
916
+ */
917
+ async channelsPins(channel_id) {
918
+ return this.guildServer({
919
+ method: 'GET',
920
+ url: `/channels/${channel_id}/pins`
921
+ }).then(res => res?.data);
922
+ }
923
+ /**
924
+ * ********
925
+ * 日程api
926
+ * *******
927
+ */
928
+ /**
929
+ * 获取频道日程列表
930
+ * @param channel_id 子频道id
931
+ * @returns 返回 Schedule 对象数组(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/schedule/model.html#schedule)
932
+ */
933
+ async channelsSchedules(channel_id) {
934
+ return this.guildServer({
935
+ method: 'GET',
936
+ url: `/channels/${channel_id}/schedules`
937
+ }).then(res => res?.data);
938
+ }
939
+ /**
940
+ * 获取频道日程详情
941
+ * @param channel_id 子频道id
942
+ * @param schedule_id 日程id
943
+ * @returns 返回 Schedule 对象(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/schedule/model.html#schedule)
944
+ */
945
+ async channelsSchedulesSchedule(channel_id, schedule_id) {
946
+ return this.guildServer({
947
+ method: 'GET',
948
+ url: `/channels/${channel_id}/schedules/${schedule_id}`
949
+ }).then(res => res?.data);
950
+ }
951
+ /**
952
+ * 创建频道日程
953
+ * @param channel_id 子频道id
954
+ * @param name 日程名称
955
+ * @param description 日程描述
956
+ * @param start_timestamp 日程开始时间戳
957
+ * @param end_timestamp 日程结束时间戳
958
+ * @param jump_channel_id 日程开始时跳转的子频道id
959
+ * @param remind_type 日程提醒类型
960
+ * 0 不提醒
961
+ * 1 开始时提醒
962
+ * 2 开始前 5 分钟提醒
963
+ * 3 开始前 15 分钟提醒
964
+ * 4 开始前 30 分钟提醒
965
+ * 5 开始前 60 分钟提醒
966
+ * @returns 返回 Schedule 对象(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/schedule/model.html#schedule)
967
+ */
968
+ async channelsSchedulesPost(channel_id, data) {
969
+ return this.guildServer({
970
+ method: 'POST',
971
+ url: `/channels/${channel_id}/schedules`,
972
+ data
973
+ }).then(res => res?.data);
974
+ }
975
+ /**
976
+ * 修改频道日程
977
+ * @param channel_id 子频道id
978
+ * @param schedule_id 日程id
979
+ * @param name 日程名称
980
+ * @param description 日程描述
981
+ * @param start_timestamp 日程开始时间戳
982
+ * @param end_timestamp 日程结束时间戳
983
+ * @param jump_channel_id 日程开始时跳转的子频道id
984
+ * @param remind_type 日程提醒类型
985
+ * 0 不提醒
986
+ * 1 开始时提醒
987
+ * 2 开始前 5 分钟提醒
988
+ * 3 开始前 15 分钟提醒
989
+ * 4 开始前 30 分钟提醒
990
+ * 5 开始前 60 分钟提醒
991
+ * @returns 返回 Schedule 对象(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/schedule/model.html#schedule)
992
+ */
993
+ async channelsSchedulesSchedulePatch(channel_id, schedule_id, data) {
994
+ return this.guildServer({
995
+ method: 'PATCH',
996
+ url: `/channels/${channel_id}/schedules/${schedule_id}`,
997
+ data
998
+ }).then(res => res?.data);
999
+ }
1000
+ /**
1001
+ * 删除频道日程
1002
+ * @param channel_id 子频道id
1003
+ * @param schedule_id 日程id
1004
+ * @returns
1005
+ */
1006
+ async channelsSchedulesScheduleDelete(channel_id, schedule_id) {
1007
+ return this.guildServer({
1008
+ method: 'DELETE',
1009
+ url: `/channels/${channel_id}/schedules/${schedule_id}`
1010
+ }).then(res => res?.data);
1011
+ }
1012
+ /**
1013
+ * ***********
1014
+ * 表情表态api
1015
+ * ***********
1016
+ */
1017
+ /**
1018
+ * 机器人发表表情表态
1019
+ * @param channel_id 子频道id
1020
+ * @param message_id 消息id
1021
+ * @param type 表情类型 1:系统表情 2:emoji表情
1022
+ * @param id 表情id 参考https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#Emoji%20%E5%88%97%E8%A1%A8
1023
+ * @returns
1024
+ */
1025
+ async channelsMessagesReactionsPut(channel_id, message_id, type, id) {
1026
+ return this.guildServer({
1027
+ method: 'PUT',
1028
+ url: `/channels/${channel_id}/messages/${message_id}/reactions/${type}/${id}`
1029
+ }).then(res => res?.data);
1030
+ }
1031
+ /**
1032
+ * 删除机器人发表的表情表态
1033
+ * @param channel_id 子频道id
1034
+ * @param message_id 消息id
1035
+ * @param type 表情类型 1:系统表情 2:emoji表情
1036
+ * @param id 表情id 参考https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#Emoji%20%E5%88%97%E8%A1%A8
1037
+ * @returns
1038
+ */
1039
+ async channelsMessagesReactionsDelete(channel_id, message_id, type, id) {
1040
+ return this.guildServer({
1041
+ method: 'DELETE',
1042
+ url: `/channels/${channel_id}/messages/${message_id}/reactions/${type}/${id}`
1043
+ }).then(res => res?.data);
1044
+ }
1045
+ /**
1046
+ * 获取消息表情表态的用户列表
1047
+ * @param channel_id 子频道id
1048
+ * @param message_id 消息id
1049
+ * @param type 表情类型 1:系统表情 2:emoji表情
1050
+ * @param id 表情id 参考https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#Emoji%20%E5%88%97%E8%A1%A8
1051
+ * @param {object} data
1052
+ * @param {object} data.cookie 返回的cookie 第一次请求不传,后续请求传上次返回的cookie
1053
+ * @param {object} data.limit 返回的用户数量 默认20 最大50
1054
+ * @returns data:{ users:User[], cookie:string,is_end:true|false }
1055
+ */
1056
+ async channelsMessagesReactionsUsers(channel_id, message_id, type, id, data) {
1057
+ return this.guildServer({
1058
+ method: 'GET',
1059
+ url: `/channels/${channel_id}/messages/${message_id}/reactions/${type}/${id}`,
1060
+ data
1061
+ }).then(res => res?.data);
1062
+ }
1063
+ /**
1064
+ * ***********
1065
+ * 音频api
1066
+ * 音频接口:仅限音频类机器人才能使用,后续会根据机器人类型自动开通接口权限,现如需调用,需联系平台申请权限
1067
+ * **********
1068
+ */
1069
+ /**
1070
+ * 音频控制
1071
+ * @param channel_id 子频道id
1072
+ * @param audio_url 音频url status为0时传
1073
+ * @param status 0:开始 1:暂停 2:继续 3:停止
1074
+ * @param text 状态文本(比如:简单爱-周杰伦),可选,status为0时传,其他操作不传
1075
+ * @returns
1076
+ */
1077
+ async channelsAudioPost(channel_id, data) {
1078
+ return this.guildServer({
1079
+ method: 'POST',
1080
+ url: `/channels/${channel_id}/audio`,
1081
+ data
1082
+ }).then(res => res?.data);
1083
+ }
1084
+ /**
1085
+ * 机器人上麦
1086
+ * @param channel_id 语音子频道id
1087
+ * @returns {}
1088
+ */
1089
+ async channelsMicPut(channel_id) {
1090
+ return this.guildServer({
1091
+ method: 'PUT',
1092
+ url: `/channels/${channel_id}/mic`
1093
+ }).then(res => res?.data);
1094
+ }
1095
+ /**
1096
+ * 机器人下麦
1097
+ * @param channel_id 语音子频道id
1098
+ * @returns {}
1099
+ */
1100
+ async channelsMicDelete(channel_id) {
1101
+ return this.guildServer({
1102
+ method: 'DELETE',
1103
+ url: `/channels/${channel_id}/mic`
1104
+ }).then(res => res?.data);
1105
+ }
1106
+ /**
1107
+ * **********
1108
+ * 帖子api
1109
+ * 注意
1110
+ * 公域机器人暂不支持申请,仅私域机器人可用,选择私域机器人后默认开通。
1111
+ * 注意: 开通后需要先将机器人从频道移除,然后重新添加,方可生效。
1112
+ * **********
1113
+ */
1114
+ /**
1115
+ * 获取帖子列表
1116
+ * @param channel_id 子频道id
1117
+ * @returns {threads:Thread[],is_finish:0|1}
1118
+ * @returns 返回 Thread 对象数组(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/forum/model.html#Thread)
1119
+ * @returns is_finish 为 1 时,表示已拉取完 为 0 时,表示未拉取完
1120
+ */
1121
+ async channelsThreads(channel_id) {
1122
+ return this.guildServer({
1123
+ method: 'GET',
1124
+ url: `/channels/${channel_id}/threads`
1125
+ }).then(res => res?.data);
1126
+ }
1127
+ /**
1128
+ * 获取帖子详情
1129
+ * @param channel_id 子频道id
1130
+ * @param thread_id 帖子id
1131
+ * @returns 返回 帖子详情对象(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/forum/model.html#ThreadInfo)
1132
+ * 其中content字段可参考 https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/forum/model.html#RichText
1133
+ */
1134
+ async channelsThreadsThread(channel_id, thread_id) {
1135
+ return this.guildServer({
1136
+ method: 'GET',
1137
+ url: `/channels/${channel_id}/threads/${thread_id}`
1138
+ }).then(res => res?.data);
1139
+ }
1140
+ /**
1141
+ * 发表帖子
1142
+ * @param channel_id 子频道id
1143
+ * @param title 帖子标题
1144
+ * @param content 帖子内容
1145
+ * @param format 帖子内容格式 1:纯文本 2:HTML 3:Markdown 4:JSON
1146
+ * @returns 返回 {task_id:string,create_time:string} 其中 task_id 为帖子id,create_time 发帖时间戳
1147
+ */
1148
+ async channelsThreadsPut(channel_id, data) {
1149
+ return this.guildServer({
1150
+ method: 'PUT',
1151
+ url: `/channels/${channel_id}/threads`,
1152
+ data
1153
+ }).then(res => res?.data);
1154
+ }
1155
+ /**
1156
+ * 删除帖子
1157
+ * @param channel_id 子频道id
1158
+ * @param thread_id 帖子id
1159
+ * @returns
1160
+ */
1161
+ async channelsThreadsDelete(channel_id, thread_id) {
1162
+ return this.guildServer({
1163
+ method: 'DELETE',
1164
+ url: `/channels/${channel_id}/threads/${thread_id}`
1165
+ }).then(res => res?.data);
1166
+ }
1167
+ /**
1168
+ * ********
1169
+ * 接口权限api
1170
+ * **********
1171
+ */
1172
+ /**
1173
+ * 获得频道可用权限列表
1174
+ * @param guild_id
1175
+ * @returns
1176
+ */
1177
+ async guildApiPermission(guild_id) {
1178
+ return this.guildServer({
1179
+ url: `/guilds/${guild_id}/api_permission`
1180
+ }).then(res => res?.data);
1181
+ }
1182
+ }
1183
+
1184
+ export { QQBotAPI };