@alemonjs/qq-bot 0.0.21 → 0.0.22
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/register.js +20 -25
- package/lib/sends.js +195 -123
- package/package.json +1 -1
package/lib/register.js
CHANGED
|
@@ -337,35 +337,30 @@ const createClientAPI = (client) => {
|
|
|
337
337
|
use: {
|
|
338
338
|
send: async (event, val) => {
|
|
339
339
|
if (val.length < 0)
|
|
340
|
-
;
|
|
340
|
+
Promise.all([]);
|
|
341
341
|
// 打 tag
|
|
342
342
|
const tag = event.tag;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return await AT_MESSAGE_CREATE(client, event, val);
|
|
359
|
-
}
|
|
360
|
-
// 频道消息
|
|
361
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
362
|
-
return await MESSAGE_CREATE(client, event, val);
|
|
363
|
-
}
|
|
343
|
+
// 群at
|
|
344
|
+
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
345
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
346
|
+
}
|
|
347
|
+
// 私聊
|
|
348
|
+
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
349
|
+
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
350
|
+
}
|
|
351
|
+
// 频道私聊
|
|
352
|
+
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
353
|
+
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
354
|
+
}
|
|
355
|
+
// 频道at
|
|
356
|
+
if (tag == 'AT_MESSAGE_CREATE') {
|
|
357
|
+
return await AT_MESSAGE_CREATE(client, event, val);
|
|
364
358
|
}
|
|
365
|
-
|
|
366
|
-
|
|
359
|
+
// 频道消息
|
|
360
|
+
if (tag == 'MESSAGE_CREATE') {
|
|
361
|
+
return await MESSAGE_CREATE(client, event, val);
|
|
367
362
|
}
|
|
368
|
-
return [];
|
|
363
|
+
return Promise.all([]);
|
|
369
364
|
},
|
|
370
365
|
mention: async (e) => {
|
|
371
366
|
const event = e.value;
|
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,24 @@ 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 => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
194
|
+
return res;
|
|
181
195
|
}
|
|
182
196
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
183
197
|
if (images && images.length > 0) {
|
|
184
198
|
return Promise.all(images.map(async (item) => {
|
|
185
199
|
if (item.type == 'ImageURL') {
|
|
186
|
-
|
|
200
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
187
201
|
content: '',
|
|
188
202
|
media: {
|
|
189
203
|
file_info: item.value
|
|
@@ -192,28 +206,40 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
192
206
|
msg_type: 7,
|
|
193
207
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
194
208
|
});
|
|
209
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
210
|
+
id: res.id
|
|
211
|
+
});
|
|
195
212
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
try {
|
|
214
|
+
const file_data = item.type == 'ImageFile'
|
|
215
|
+
? readFileSync(item.value, 'base64')
|
|
216
|
+
: item.value.toString('base64');
|
|
217
|
+
const file_info = await client
|
|
218
|
+
.postRichMediaByGroup(event.GuildId, {
|
|
219
|
+
file_type: 1,
|
|
220
|
+
file_data: file_data
|
|
221
|
+
})
|
|
222
|
+
.then(res => res?.file_info);
|
|
223
|
+
if (!file_info) {
|
|
224
|
+
return createResult(ResultCode.Fail, 'client.postRichMediaByGroup', null);
|
|
225
|
+
}
|
|
226
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
227
|
+
content: '',
|
|
228
|
+
media: {
|
|
229
|
+
file_info
|
|
230
|
+
},
|
|
231
|
+
msg_id: event.MessageId,
|
|
232
|
+
msg_type: 7,
|
|
233
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
234
|
+
});
|
|
235
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
236
|
+
id: res.id
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
return createResult(ResultCode.Fail, error ? (error?.message ?? error) : 'client.groupOpenMessages', null);
|
|
241
|
+
}
|
|
242
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
217
243
|
}
|
|
218
244
|
// buttons
|
|
219
245
|
const buttons = val.filter(item => item.type == 'BT.group');
|
|
@@ -221,7 +247,7 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
221
247
|
return Promise.all(buttons.map(async (item) => {
|
|
222
248
|
const template_id = item?.options?.template_id;
|
|
223
249
|
if (template_id) {
|
|
224
|
-
|
|
250
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
225
251
|
content: '',
|
|
226
252
|
msg_id: event.MessageId,
|
|
227
253
|
keyboard: {
|
|
@@ -230,11 +256,14 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
230
256
|
msg_type: 2,
|
|
231
257
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
232
258
|
});
|
|
259
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
260
|
+
id: res.id
|
|
261
|
+
});
|
|
233
262
|
}
|
|
234
263
|
const rows = item.value;
|
|
235
264
|
// 构造成按钮
|
|
236
265
|
const data = createButtonsData(rows);
|
|
237
|
-
|
|
266
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
238
267
|
content: '',
|
|
239
268
|
msg_id: event.MessageId,
|
|
240
269
|
keyboard: {
|
|
@@ -243,7 +272,10 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
243
272
|
msg_type: 2,
|
|
244
273
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
245
274
|
});
|
|
246
|
-
|
|
275
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
276
|
+
id: res.id
|
|
277
|
+
});
|
|
278
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
247
279
|
}
|
|
248
280
|
// ark
|
|
249
281
|
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
@@ -251,33 +283,45 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
251
283
|
return Promise.all(ark.map(async (item) => {
|
|
252
284
|
if (item.type === 'Ark.Card') {
|
|
253
285
|
const arkData = createArkCardData(item.value);
|
|
254
|
-
|
|
286
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
255
287
|
msg_id: event.MessageId,
|
|
256
288
|
ark: arkData,
|
|
257
289
|
msg_type: 3,
|
|
258
290
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
259
291
|
});
|
|
292
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
293
|
+
id: res.id
|
|
294
|
+
});
|
|
260
295
|
}
|
|
261
296
|
if (item.type === 'Ark.BigCard') {
|
|
262
297
|
const arkData = createArkBigCardData(item.value);
|
|
263
|
-
|
|
298
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
264
299
|
msg_id: event.MessageId,
|
|
265
300
|
ark: arkData,
|
|
266
301
|
msg_type: 3,
|
|
267
302
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
268
303
|
});
|
|
304
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
269
305
|
}
|
|
270
306
|
const arkData = createArkList(item.value);
|
|
271
|
-
|
|
307
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
272
308
|
msg_id: event.MessageId,
|
|
273
309
|
ark: arkData,
|
|
274
310
|
msg_type: 3,
|
|
275
311
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
276
312
|
});
|
|
277
|
-
|
|
313
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
314
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
278
315
|
}
|
|
279
316
|
return Promise.all([]);
|
|
280
317
|
};
|
|
318
|
+
/**
|
|
319
|
+
* 私聊消息
|
|
320
|
+
* @param client
|
|
321
|
+
* @param event
|
|
322
|
+
* @param val
|
|
323
|
+
* @returns
|
|
324
|
+
*/
|
|
281
325
|
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
282
326
|
const content = val
|
|
283
327
|
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
@@ -292,18 +336,23 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
292
336
|
})
|
|
293
337
|
.join('');
|
|
294
338
|
if (content) {
|
|
295
|
-
return Promise.all([content].map(item =>
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
339
|
+
return Promise.all([content].map(async (item) => {
|
|
340
|
+
const res = await client.usersOpenMessages(event.OpenId, {
|
|
341
|
+
content: item,
|
|
342
|
+
msg_id: event.MessageId,
|
|
343
|
+
msg_type: 0,
|
|
344
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
345
|
+
});
|
|
346
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
347
|
+
id: res.id
|
|
348
|
+
});
|
|
349
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
301
350
|
}
|
|
302
351
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
303
352
|
if (images && images.length > 0) {
|
|
304
353
|
return Promise.all(images.map(async (item) => {
|
|
305
354
|
if (item.type == 'ImageURL') {
|
|
306
|
-
|
|
355
|
+
const res = await client.usersOpenMessages(event.OpenId, {
|
|
307
356
|
content: '',
|
|
308
357
|
media: {
|
|
309
358
|
file_info: item.value
|
|
@@ -312,6 +361,9 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
312
361
|
msg_type: 7,
|
|
313
362
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
314
363
|
});
|
|
364
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
365
|
+
id: res.id
|
|
366
|
+
});
|
|
315
367
|
}
|
|
316
368
|
const file_data = item.type == 'ImageFile'
|
|
317
369
|
? readFileSync(item.value, 'base64')
|
|
@@ -333,7 +385,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
333
385
|
msg_type: 7,
|
|
334
386
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
335
387
|
});
|
|
336
|
-
}));
|
|
388
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
337
389
|
}
|
|
338
390
|
// buttons
|
|
339
391
|
const buttons = val.filter(item => item.type == 'BT.group');
|
|
@@ -341,7 +393,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
341
393
|
return Promise.all(buttons.map(async (item) => {
|
|
342
394
|
const template_id = item?.options?.template_id;
|
|
343
395
|
if (template_id) {
|
|
344
|
-
|
|
396
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
345
397
|
content: '',
|
|
346
398
|
msg_id: event.MessageId,
|
|
347
399
|
keyboard: {
|
|
@@ -350,15 +402,14 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
350
402
|
msg_type: 2,
|
|
351
403
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
352
404
|
});
|
|
405
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
406
|
+
id: res.id
|
|
407
|
+
});
|
|
353
408
|
}
|
|
354
409
|
const rows = item.value;
|
|
355
|
-
// 看看是否是模板id的
|
|
356
|
-
rows.map(row => {
|
|
357
|
-
return row;
|
|
358
|
-
});
|
|
359
410
|
// 构造成按钮
|
|
360
411
|
const data = createButtonsData(rows);
|
|
361
|
-
|
|
412
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
362
413
|
content: '',
|
|
363
414
|
msg_id: event.MessageId,
|
|
364
415
|
keyboard: {
|
|
@@ -367,7 +418,10 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
367
418
|
msg_type: 2,
|
|
368
419
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
369
420
|
});
|
|
370
|
-
|
|
421
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
422
|
+
id: res.id
|
|
423
|
+
});
|
|
424
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
371
425
|
}
|
|
372
426
|
// ark
|
|
373
427
|
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
@@ -375,30 +429,33 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
375
429
|
return Promise.all(ark.map(async (item) => {
|
|
376
430
|
if (item.type === 'Ark.Card') {
|
|
377
431
|
const arkData = createArkCardData(item.value);
|
|
378
|
-
|
|
432
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
379
433
|
msg_id: event.MessageId,
|
|
380
434
|
ark: arkData,
|
|
381
435
|
msg_type: 3,
|
|
382
436
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
383
437
|
});
|
|
438
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
384
439
|
}
|
|
385
440
|
if (item.type === 'Ark.BigCard') {
|
|
386
441
|
const arkData = createArkBigCardData(item.value);
|
|
387
|
-
|
|
442
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
388
443
|
msg_id: event.MessageId,
|
|
389
444
|
ark: arkData,
|
|
390
445
|
msg_type: 3,
|
|
391
446
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
392
447
|
});
|
|
448
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
393
449
|
}
|
|
394
450
|
const arkData = createArkList(item.value);
|
|
395
|
-
|
|
451
|
+
const res = await client.usersOpenMessages(event.GuildId, {
|
|
396
452
|
msg_id: event.MessageId,
|
|
397
453
|
ark: arkData,
|
|
398
454
|
msg_type: 3,
|
|
399
455
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
400
456
|
});
|
|
401
|
-
|
|
457
|
+
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
458
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
402
459
|
}
|
|
403
460
|
return Promise.all([]);
|
|
404
461
|
};
|
|
@@ -423,13 +480,16 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
423
480
|
})
|
|
424
481
|
.join('');
|
|
425
482
|
if (content) {
|
|
426
|
-
return Promise.all([content].map(item =>
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
483
|
+
return Promise.all([content].map(async (item) => {
|
|
484
|
+
const res = await client.dmsMessage(event.OpenId, {
|
|
485
|
+
content: item,
|
|
486
|
+
msg_id: event.MessageId
|
|
487
|
+
});
|
|
488
|
+
return createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id });
|
|
489
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
430
490
|
}
|
|
431
491
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
432
|
-
if (images) {
|
|
492
|
+
if (images && images.length > 0) {
|
|
433
493
|
return Promise.all(images.map(async (item) => {
|
|
434
494
|
if (item.value == 'ImageURL') {
|
|
435
495
|
// 请求得到buffer
|
|
@@ -437,20 +497,22 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
437
497
|
.get(item.value, {
|
|
438
498
|
responseType: 'arraybuffer'
|
|
439
499
|
})
|
|
440
|
-
.then(res => res
|
|
441
|
-
|
|
500
|
+
.then(res => res?.data);
|
|
501
|
+
const res = await client.postDirectImage(event.OpenId, {
|
|
442
502
|
msg_id: event.MessageId,
|
|
443
503
|
image: data
|
|
444
504
|
});
|
|
505
|
+
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
445
506
|
}
|
|
446
507
|
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
447
|
-
|
|
508
|
+
const res = await client.postDirectImage(event.OpenId, {
|
|
448
509
|
msg_id: event.MessageId,
|
|
449
510
|
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
450
511
|
});
|
|
451
|
-
|
|
512
|
+
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
513
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
452
514
|
}
|
|
453
|
-
return [];
|
|
515
|
+
return Promise.all([]);
|
|
454
516
|
};
|
|
455
517
|
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
456
518
|
const content = val
|
|
@@ -480,10 +542,13 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
480
542
|
})
|
|
481
543
|
.join('');
|
|
482
544
|
if (content) {
|
|
483
|
-
return Promise.all([content].map(item =>
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
545
|
+
return Promise.all([content].map(async (item) => {
|
|
546
|
+
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
547
|
+
content: item,
|
|
548
|
+
msg_id: event.MessageId
|
|
549
|
+
});
|
|
550
|
+
return createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id });
|
|
551
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
487
552
|
}
|
|
488
553
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
489
554
|
if (images && images.length > 0) {
|
|
@@ -495,17 +560,19 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
495
560
|
responseType: 'arraybuffer'
|
|
496
561
|
})
|
|
497
562
|
.then(res => res.data);
|
|
498
|
-
|
|
563
|
+
const res = await client.postImage(event.ChannelId, {
|
|
499
564
|
msg_id: event.MessageId,
|
|
500
565
|
image: data
|
|
501
566
|
});
|
|
567
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
502
568
|
}
|
|
503
569
|
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
504
|
-
|
|
570
|
+
const res = await client.postImage(event.ChannelId, {
|
|
505
571
|
msg_id: event.MessageId,
|
|
506
572
|
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
507
573
|
});
|
|
508
|
-
|
|
574
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
575
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
509
576
|
}
|
|
510
577
|
return Promise.all([]);
|
|
511
578
|
};
|
|
@@ -543,10 +610,13 @@ const MESSAGE_CREATE = (client, event, val) => {
|
|
|
543
610
|
})
|
|
544
611
|
.join('');
|
|
545
612
|
if (content) {
|
|
546
|
-
return Promise.all([content].map(item =>
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
613
|
+
return Promise.all([content].map(async (item) => {
|
|
614
|
+
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
615
|
+
content: item,
|
|
616
|
+
msg_id: event.MessageId
|
|
617
|
+
});
|
|
618
|
+
return createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id });
|
|
619
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
550
620
|
}
|
|
551
621
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
552
622
|
if (images && images.length > 0) {
|
|
@@ -558,17 +628,19 @@ const MESSAGE_CREATE = (client, event, val) => {
|
|
|
558
628
|
responseType: 'arraybuffer'
|
|
559
629
|
})
|
|
560
630
|
.then(res => res.data);
|
|
561
|
-
|
|
631
|
+
const res = await client.postImage(event.ChannelId, {
|
|
562
632
|
msg_id: event.MessageId,
|
|
563
633
|
image: data
|
|
564
634
|
});
|
|
635
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
565
636
|
}
|
|
566
637
|
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
567
|
-
|
|
638
|
+
const res = await client.postImage(event.ChannelId, {
|
|
568
639
|
msg_id: event.MessageId,
|
|
569
640
|
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
570
641
|
});
|
|
571
|
-
|
|
642
|
+
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
643
|
+
})).catch(err => [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)]);
|
|
572
644
|
}
|
|
573
645
|
return Promise.all([]);
|
|
574
646
|
};
|