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