@alemonjs/qq-bot 0.0.12 → 0.0.13

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