@alemonjs/qq-bot 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +2 -1
- package/lib/register.js +25 -52
- package/lib/sends.js +223 -123
- package/package.json +1 -1
- package/dist/assets/index.css +0 -1255
- package/dist/assets/index.js +0 -11257
- package/dist/index.html +0 -15
- package/lib/send/index.js +0 -453
package/lib/sends.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
|
+
import { createResult, ResultCode } from 'alemonjs';
|
|
2
3
|
import axios from 'axios';
|
|
3
4
|
|
|
4
5
|
const createButtonsData = (rows) => {
|
|
@@ -43,62 +44,62 @@ const createButtonsData = (rows) => {
|
|
|
43
44
|
};
|
|
44
45
|
const createArkCardData = (value) => {
|
|
45
46
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
template_id: 24,
|
|
48
|
+
kv: [
|
|
48
49
|
{
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
key: '#DESC#',
|
|
51
|
+
value: value.decs
|
|
51
52
|
},
|
|
52
53
|
{
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
key: '#PROMPT#',
|
|
55
|
+
value: value.prompt
|
|
55
56
|
},
|
|
56
57
|
{
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
key: '#TITLE#',
|
|
59
|
+
value: value.title
|
|
59
60
|
},
|
|
60
61
|
{
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
key: '#METADESC#',
|
|
63
|
+
value: value.metadecs
|
|
63
64
|
},
|
|
64
65
|
{
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
key: '#IMG#',
|
|
67
|
+
value: value.cover
|
|
67
68
|
},
|
|
68
69
|
{
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
key: '#LINK#',
|
|
71
|
+
value: value.link
|
|
71
72
|
},
|
|
72
73
|
{
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
key: '#SUBTITLE#',
|
|
75
|
+
value: value.subtitle
|
|
75
76
|
}
|
|
76
77
|
]
|
|
77
78
|
};
|
|
78
79
|
};
|
|
79
80
|
const createArkBigCardData = (value) => {
|
|
80
81
|
return {
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
template_id: 37,
|
|
83
|
+
kv: [
|
|
83
84
|
{
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
key: '#PROMPT#',
|
|
86
|
+
value: value.prompt
|
|
86
87
|
},
|
|
87
88
|
{
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
key: '#METATITLE#',
|
|
90
|
+
value: value.title
|
|
90
91
|
},
|
|
91
92
|
{
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
key: '#METASUBTITLE#',
|
|
94
|
+
value: value.subtitle
|
|
94
95
|
},
|
|
95
96
|
{
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
key: '#METACOVER#',
|
|
98
|
+
value: value.cover
|
|
98
99
|
},
|
|
99
100
|
{
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
key: '#METAURL#',
|
|
102
|
+
value: value.link
|
|
102
103
|
}
|
|
103
104
|
]
|
|
104
105
|
};
|
|
@@ -106,39 +107,39 @@ const createArkBigCardData = (value) => {
|
|
|
106
107
|
const createArkList = (value) => {
|
|
107
108
|
const [tip, data] = value;
|
|
108
109
|
return {
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
template_id: 23,
|
|
111
|
+
kv: [
|
|
111
112
|
{
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
key: '#DESC#',
|
|
114
|
+
value: tip.value.desc
|
|
114
115
|
},
|
|
115
116
|
{
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
key: '#PROMPT#',
|
|
118
|
+
value: tip.value.prompt
|
|
118
119
|
},
|
|
119
120
|
{
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
key: '#LIST#',
|
|
122
|
+
obj: data.value.map(item => {
|
|
122
123
|
const value = item.value;
|
|
123
124
|
if (typeof value === 'string') {
|
|
124
125
|
return {
|
|
125
|
-
|
|
126
|
+
obj_kv: [
|
|
126
127
|
{
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
key: 'desc',
|
|
129
|
+
value: value
|
|
129
130
|
}
|
|
130
131
|
]
|
|
131
132
|
};
|
|
132
133
|
}
|
|
133
134
|
return {
|
|
134
|
-
|
|
135
|
+
obj_kv: [
|
|
135
136
|
{
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
key: 'desc',
|
|
138
|
+
value: value.title
|
|
138
139
|
},
|
|
139
140
|
{
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
key: 'link',
|
|
142
|
+
value: value.link
|
|
142
143
|
}
|
|
143
144
|
]
|
|
144
145
|
};
|
|
@@ -147,7 +148,14 @@ const createArkList = (value) => {
|
|
|
147
148
|
]
|
|
148
149
|
};
|
|
149
150
|
};
|
|
150
|
-
|
|
151
|
+
/**
|
|
152
|
+
* 群组消息
|
|
153
|
+
* @param client
|
|
154
|
+
* @param event
|
|
155
|
+
* @param val
|
|
156
|
+
* @returns
|
|
157
|
+
*/
|
|
158
|
+
const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
151
159
|
const content = val
|
|
152
160
|
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
153
161
|
.map(item => {
|
|
@@ -172,18 +180,26 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
172
180
|
})
|
|
173
181
|
.join('');
|
|
174
182
|
if (content) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
183
|
+
const res = await Promise.all([content].map(async (item) => {
|
|
184
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
185
|
+
content: item,
|
|
186
|
+
msg_id: event.MessageId,
|
|
187
|
+
msg_type: 0,
|
|
188
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
189
|
+
});
|
|
190
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
191
|
+
id: res.id
|
|
192
|
+
});
|
|
193
|
+
})).catch(err => [
|
|
194
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
195
|
+
]);
|
|
196
|
+
return res;
|
|
181
197
|
}
|
|
182
198
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
183
199
|
if (images && images.length > 0) {
|
|
184
200
|
return Promise.all(images.map(async (item) => {
|
|
185
201
|
if (item.type == 'ImageURL') {
|
|
186
|
-
|
|
202
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
187
203
|
content: '',
|
|
188
204
|
media: {
|
|
189
205
|
file_info: item.value
|
|
@@ -192,28 +208,42 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
192
208
|
msg_type: 7,
|
|
193
209
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
194
210
|
});
|
|
211
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
212
|
+
id: res.id
|
|
213
|
+
});
|
|
195
214
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
try {
|
|
216
|
+
const file_data = item.type == 'ImageFile'
|
|
217
|
+
? readFileSync(item.value, 'base64')
|
|
218
|
+
: item.value.toString('base64');
|
|
219
|
+
const file_info = await client
|
|
220
|
+
.postRichMediaByGroup(event.GuildId, {
|
|
221
|
+
file_type: 1,
|
|
222
|
+
file_data: file_data
|
|
223
|
+
})
|
|
224
|
+
.then(res => res?.file_info);
|
|
225
|
+
if (!file_info) {
|
|
226
|
+
return createResult(ResultCode.Fail, 'client.postRichMediaByGroup', null);
|
|
227
|
+
}
|
|
228
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
229
|
+
content: '',
|
|
230
|
+
media: {
|
|
231
|
+
file_info
|
|
232
|
+
},
|
|
233
|
+
msg_id: event.MessageId,
|
|
234
|
+
msg_type: 7,
|
|
235
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
236
|
+
});
|
|
237
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
238
|
+
id: res.id
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
return createResult(ResultCode.Fail, error ? error?.message ?? error : 'client.groupOpenMessages', null);
|
|
243
|
+
}
|
|
244
|
+
})).catch(err => [
|
|
245
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
246
|
+
]);
|
|
217
247
|
}
|
|
218
248
|
// buttons
|
|
219
249
|
const buttons = val.filter(item => item.type == 'BT.group');
|
|
@@ -221,7 +251,7 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
221
251
|
return Promise.all(buttons.map(async (item) => {
|
|
222
252
|
const template_id = item?.options?.template_id;
|
|
223
253
|
if (template_id) {
|
|
224
|
-
|
|
254
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
225
255
|
content: '',
|
|
226
256
|
msg_id: event.MessageId,
|
|
227
257
|
keyboard: {
|
|
@@ -230,11 +260,14 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
230
260
|
msg_type: 2,
|
|
231
261
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
232
262
|
});
|
|
263
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
264
|
+
id: res.id
|
|
265
|
+
});
|
|
233
266
|
}
|
|
234
267
|
const rows = item.value;
|
|
235
268
|
// 构造成按钮
|
|
236
269
|
const data = createButtonsData(rows);
|
|
237
|
-
|
|
270
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
238
271
|
content: '',
|
|
239
272
|
msg_id: event.MessageId,
|
|
240
273
|
keyboard: {
|
|
@@ -243,7 +276,12 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
243
276
|
msg_type: 2,
|
|
244
277
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
245
278
|
});
|
|
246
|
-
|
|
279
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
280
|
+
id: res.id
|
|
281
|
+
});
|
|
282
|
+
})).catch(err => [
|
|
283
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
284
|
+
]);
|
|
247
285
|
}
|
|
248
286
|
// ark
|
|
249
287
|
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
@@ -251,33 +289,47 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
251
289
|
return Promise.all(ark.map(async (item) => {
|
|
252
290
|
if (item.type === 'Ark.Card') {
|
|
253
291
|
const arkData = createArkCardData(item.value);
|
|
254
|
-
|
|
292
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
255
293
|
msg_id: event.MessageId,
|
|
256
294
|
ark: arkData,
|
|
257
295
|
msg_type: 3,
|
|
258
296
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
259
297
|
});
|
|
298
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
299
|
+
id: res.id
|
|
300
|
+
});
|
|
260
301
|
}
|
|
261
302
|
if (item.type === 'Ark.BigCard') {
|
|
262
303
|
const arkData = createArkBigCardData(item.value);
|
|
263
|
-
|
|
304
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
264
305
|
msg_id: event.MessageId,
|
|
265
306
|
ark: arkData,
|
|
266
307
|
msg_type: 3,
|
|
267
308
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
268
309
|
});
|
|
310
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
269
311
|
}
|
|
270
312
|
const arkData = createArkList(item.value);
|
|
271
|
-
|
|
313
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
272
314
|
msg_id: event.MessageId,
|
|
273
315
|
ark: arkData,
|
|
274
316
|
msg_type: 3,
|
|
275
317
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
276
318
|
});
|
|
277
|
-
|
|
319
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
320
|
+
})).catch(err => [
|
|
321
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
322
|
+
]);
|
|
278
323
|
}
|
|
279
324
|
return Promise.all([]);
|
|
280
325
|
};
|
|
326
|
+
/**
|
|
327
|
+
* 私聊消息
|
|
328
|
+
* @param client
|
|
329
|
+
* @param event
|
|
330
|
+
* @param val
|
|
331
|
+
* @returns
|
|
332
|
+
*/
|
|
281
333
|
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
282
334
|
const content = val
|
|
283
335
|
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
@@ -292,18 +344,25 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
292
344
|
})
|
|
293
345
|
.join('');
|
|
294
346
|
if (content) {
|
|
295
|
-
return Promise.all([content].map(item =>
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
347
|
+
return Promise.all([content].map(async (item) => {
|
|
348
|
+
const res = await client.usersOpenMessages(event.OpenId, {
|
|
349
|
+
content: item,
|
|
350
|
+
msg_id: event.MessageId,
|
|
351
|
+
msg_type: 0,
|
|
352
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
353
|
+
});
|
|
354
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
355
|
+
id: res.id
|
|
356
|
+
});
|
|
357
|
+
})).catch(err => [
|
|
358
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
359
|
+
]);
|
|
301
360
|
}
|
|
302
361
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
303
362
|
if (images && images.length > 0) {
|
|
304
363
|
return Promise.all(images.map(async (item) => {
|
|
305
364
|
if (item.type == 'ImageURL') {
|
|
306
|
-
|
|
365
|
+
const res = await client.usersOpenMessages(event.OpenId, {
|
|
307
366
|
content: '',
|
|
308
367
|
media: {
|
|
309
368
|
file_info: item.value
|
|
@@ -312,6 +371,9 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
312
371
|
msg_type: 7,
|
|
313
372
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
314
373
|
});
|
|
374
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
375
|
+
id: res.id
|
|
376
|
+
});
|
|
315
377
|
}
|
|
316
378
|
const file_data = item.type == 'ImageFile'
|
|
317
379
|
? readFileSync(item.value, 'base64')
|
|
@@ -333,7 +395,9 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
333
395
|
msg_type: 7,
|
|
334
396
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
335
397
|
});
|
|
336
|
-
}))
|
|
398
|
+
})).catch(err => [
|
|
399
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
400
|
+
]);
|
|
337
401
|
}
|
|
338
402
|
// buttons
|
|
339
403
|
const buttons = val.filter(item => item.type == 'BT.group');
|
|
@@ -341,7 +405,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
341
405
|
return Promise.all(buttons.map(async (item) => {
|
|
342
406
|
const template_id = item?.options?.template_id;
|
|
343
407
|
if (template_id) {
|
|
344
|
-
|
|
408
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
345
409
|
content: '',
|
|
346
410
|
msg_id: event.MessageId,
|
|
347
411
|
keyboard: {
|
|
@@ -350,15 +414,14 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
350
414
|
msg_type: 2,
|
|
351
415
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
352
416
|
});
|
|
417
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
418
|
+
id: res.id
|
|
419
|
+
});
|
|
353
420
|
}
|
|
354
421
|
const rows = item.value;
|
|
355
|
-
// 看看是否是模板id的
|
|
356
|
-
rows.map(row => {
|
|
357
|
-
return row;
|
|
358
|
-
});
|
|
359
422
|
// 构造成按钮
|
|
360
423
|
const data = createButtonsData(rows);
|
|
361
|
-
|
|
424
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
362
425
|
content: '',
|
|
363
426
|
msg_id: event.MessageId,
|
|
364
427
|
keyboard: {
|
|
@@ -367,7 +430,12 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
367
430
|
msg_type: 2,
|
|
368
431
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
369
432
|
});
|
|
370
|
-
|
|
433
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
434
|
+
id: res.id
|
|
435
|
+
});
|
|
436
|
+
})).catch(err => [
|
|
437
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
438
|
+
]);
|
|
371
439
|
}
|
|
372
440
|
// ark
|
|
373
441
|
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
@@ -375,30 +443,35 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
375
443
|
return Promise.all(ark.map(async (item) => {
|
|
376
444
|
if (item.type === 'Ark.Card') {
|
|
377
445
|
const arkData = createArkCardData(item.value);
|
|
378
|
-
|
|
446
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
379
447
|
msg_id: event.MessageId,
|
|
380
448
|
ark: arkData,
|
|
381
449
|
msg_type: 3,
|
|
382
450
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
383
451
|
});
|
|
452
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
384
453
|
}
|
|
385
454
|
if (item.type === 'Ark.BigCard') {
|
|
386
455
|
const arkData = createArkBigCardData(item.value);
|
|
387
|
-
|
|
456
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
388
457
|
msg_id: event.MessageId,
|
|
389
458
|
ark: arkData,
|
|
390
459
|
msg_type: 3,
|
|
391
460
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
392
461
|
});
|
|
462
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
393
463
|
}
|
|
394
464
|
const arkData = createArkList(item.value);
|
|
395
|
-
|
|
465
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
396
466
|
msg_id: event.MessageId,
|
|
397
467
|
ark: arkData,
|
|
398
468
|
msg_type: 3,
|
|
399
469
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
400
470
|
});
|
|
401
|
-
|
|
471
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
472
|
+
})).catch(err => [
|
|
473
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
474
|
+
]);
|
|
402
475
|
}
|
|
403
476
|
return Promise.all([]);
|
|
404
477
|
};
|
|
@@ -423,13 +496,18 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
423
496
|
})
|
|
424
497
|
.join('');
|
|
425
498
|
if (content) {
|
|
426
|
-
return Promise.all([content].map(item =>
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
499
|
+
return Promise.all([content].map(async (item) => {
|
|
500
|
+
const res = await client.dmsMessage(event.OpenId, {
|
|
501
|
+
content: item,
|
|
502
|
+
msg_id: event.MessageId
|
|
503
|
+
});
|
|
504
|
+
return createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id });
|
|
505
|
+
})).catch(err => [
|
|
506
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
507
|
+
]);
|
|
430
508
|
}
|
|
431
509
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
432
|
-
if (images) {
|
|
510
|
+
if (images && images.length > 0) {
|
|
433
511
|
return Promise.all(images.map(async (item) => {
|
|
434
512
|
if (item.value == 'ImageURL') {
|
|
435
513
|
// 请求得到buffer
|
|
@@ -437,20 +515,24 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
437
515
|
.get(item.value, {
|
|
438
516
|
responseType: 'arraybuffer'
|
|
439
517
|
})
|
|
440
|
-
.then(res => res
|
|
441
|
-
|
|
518
|
+
.then(res => res?.data);
|
|
519
|
+
const res = await client.postDirectImage(event.OpenId, {
|
|
442
520
|
msg_id: event.MessageId,
|
|
443
521
|
image: data
|
|
444
522
|
});
|
|
523
|
+
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
445
524
|
}
|
|
446
525
|
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
447
|
-
|
|
526
|
+
const res = await client.postDirectImage(event.OpenId, {
|
|
448
527
|
msg_id: event.MessageId,
|
|
449
528
|
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
450
529
|
});
|
|
451
|
-
|
|
530
|
+
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
531
|
+
})).catch(err => [
|
|
532
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
533
|
+
]);
|
|
452
534
|
}
|
|
453
|
-
return [];
|
|
535
|
+
return Promise.all([]);
|
|
454
536
|
};
|
|
455
537
|
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
456
538
|
const content = val
|
|
@@ -480,10 +562,15 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
480
562
|
})
|
|
481
563
|
.join('');
|
|
482
564
|
if (content) {
|
|
483
|
-
return Promise.all([content].map(item =>
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
565
|
+
return Promise.all([content].map(async (item) => {
|
|
566
|
+
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
567
|
+
content: item,
|
|
568
|
+
msg_id: event.MessageId
|
|
569
|
+
});
|
|
570
|
+
return createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id });
|
|
571
|
+
})).catch(err => [
|
|
572
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
573
|
+
]);
|
|
487
574
|
}
|
|
488
575
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
489
576
|
if (images && images.length > 0) {
|
|
@@ -495,17 +582,21 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
495
582
|
responseType: 'arraybuffer'
|
|
496
583
|
})
|
|
497
584
|
.then(res => res.data);
|
|
498
|
-
|
|
585
|
+
const res = await client.postImage(event.ChannelId, {
|
|
499
586
|
msg_id: event.MessageId,
|
|
500
587
|
image: data
|
|
501
588
|
});
|
|
589
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
502
590
|
}
|
|
503
591
|
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
504
|
-
|
|
592
|
+
const res = await client.postImage(event.ChannelId, {
|
|
505
593
|
msg_id: event.MessageId,
|
|
506
594
|
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
507
595
|
});
|
|
508
|
-
|
|
596
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
597
|
+
})).catch(err => [
|
|
598
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
599
|
+
]);
|
|
509
600
|
}
|
|
510
601
|
return Promise.all([]);
|
|
511
602
|
};
|
|
@@ -543,10 +634,15 @@ const MESSAGE_CREATE = (client, event, val) => {
|
|
|
543
634
|
})
|
|
544
635
|
.join('');
|
|
545
636
|
if (content) {
|
|
546
|
-
return Promise.all([content].map(item =>
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
637
|
+
return Promise.all([content].map(async (item) => {
|
|
638
|
+
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
639
|
+
content: item,
|
|
640
|
+
msg_id: event.MessageId
|
|
641
|
+
});
|
|
642
|
+
return createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id });
|
|
643
|
+
})).catch(err => [
|
|
644
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
645
|
+
]);
|
|
550
646
|
}
|
|
551
647
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
552
648
|
if (images && images.length > 0) {
|
|
@@ -558,17 +654,21 @@ const MESSAGE_CREATE = (client, event, val) => {
|
|
|
558
654
|
responseType: 'arraybuffer'
|
|
559
655
|
})
|
|
560
656
|
.then(res => res.data);
|
|
561
|
-
|
|
657
|
+
const res = await client.postImage(event.ChannelId, {
|
|
562
658
|
msg_id: event.MessageId,
|
|
563
659
|
image: data
|
|
564
660
|
});
|
|
661
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
565
662
|
}
|
|
566
663
|
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
567
|
-
|
|
664
|
+
const res = await client.postImage(event.ChannelId, {
|
|
568
665
|
msg_id: event.MessageId,
|
|
569
666
|
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
570
667
|
});
|
|
571
|
-
|
|
668
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
669
|
+
})).catch(err => [
|
|
670
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
671
|
+
]);
|
|
572
672
|
}
|
|
573
673
|
return Promise.all([]);
|
|
574
674
|
};
|