@alemonjs/qq-bot 2.1.0-alpha.1 → 2.1.0-alpha.11
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/README.md +7 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +20 -0
- package/lib/hook.d.ts +35 -1
- package/lib/hook.js +23 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.group.js +2 -1
- package/lib/index.guild.js +2 -1
- package/lib/index.js +4 -2
- package/lib/index.webhook.js +2 -1
- package/lib/index.websoket.js +2 -1
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +16 -0
- package/lib/register.js +218 -101
- package/lib/sdk/api.d.ts +750 -966
- package/lib/sdk/api.js +103 -197
- package/lib/sdk/typing.d.ts +52 -54
- package/lib/sends.js +609 -450
- package/package.json +1 -1
- package/dist/assets/index.css +0 -1255
- package/dist/assets/index.js +0 -11393
- package/dist/index.html +0 -15
- package/lib/utils.js +0 -13
package/lib/sends.js
CHANGED
|
@@ -12,6 +12,12 @@ const createButtonsData = (rows) => {
|
|
|
12
12
|
const value = button.value;
|
|
13
13
|
const options = button.options;
|
|
14
14
|
id++;
|
|
15
|
+
const typing = options?.type ?? 'command';
|
|
16
|
+
const map = {
|
|
17
|
+
command: 2,
|
|
18
|
+
link: 0,
|
|
19
|
+
call: 1
|
|
20
|
+
};
|
|
15
21
|
return {
|
|
16
22
|
id: String(id),
|
|
17
23
|
render_data: {
|
|
@@ -21,7 +27,7 @@ const createButtonsData = (rows) => {
|
|
|
21
27
|
},
|
|
22
28
|
action: {
|
|
23
29
|
// 0 link 1 callback , 2 command
|
|
24
|
-
type:
|
|
30
|
+
type: map[typing],
|
|
25
31
|
permission: {
|
|
26
32
|
// 所有人
|
|
27
33
|
type: 2
|
|
@@ -147,6 +153,74 @@ const createArkList = (value) => {
|
|
|
147
153
|
]
|
|
148
154
|
};
|
|
149
155
|
};
|
|
156
|
+
// 数据md转为文本
|
|
157
|
+
const createMarkdownText = (data) => {
|
|
158
|
+
const content = data
|
|
159
|
+
.map(mdItem => {
|
|
160
|
+
if (mdItem.type === 'MD.title') {
|
|
161
|
+
// \n
|
|
162
|
+
return `# ${mdItem.value}\n`;
|
|
163
|
+
}
|
|
164
|
+
else if (mdItem.type === 'MD.subtitle') {
|
|
165
|
+
// \n
|
|
166
|
+
return `## ${mdItem.value}\n`;
|
|
167
|
+
}
|
|
168
|
+
else if (mdItem.type === 'MD.text') {
|
|
169
|
+
// 正文
|
|
170
|
+
return `${mdItem.value} `;
|
|
171
|
+
}
|
|
172
|
+
else if (mdItem.type === 'MD.bold') {
|
|
173
|
+
// 加粗
|
|
174
|
+
return `**${mdItem.value}** `;
|
|
175
|
+
}
|
|
176
|
+
else if (mdItem.type === 'MD.divider') {
|
|
177
|
+
// 分割线
|
|
178
|
+
return '\n————————\n';
|
|
179
|
+
}
|
|
180
|
+
else if (mdItem.type === 'MD.italic') {
|
|
181
|
+
// 斜体
|
|
182
|
+
return `_${mdItem.value}_ `;
|
|
183
|
+
}
|
|
184
|
+
else if (mdItem.type === 'MD.italicStar') {
|
|
185
|
+
// 星号斜体
|
|
186
|
+
return `*${mdItem.value}* `;
|
|
187
|
+
}
|
|
188
|
+
else if (mdItem.type === 'MD.strikethrough') {
|
|
189
|
+
// 删除线
|
|
190
|
+
return `~~${mdItem.value}~~ `;
|
|
191
|
+
}
|
|
192
|
+
else if (mdItem.type === 'MD.blockquote') {
|
|
193
|
+
// \n
|
|
194
|
+
return `> ${mdItem.value}\n`;
|
|
195
|
+
}
|
|
196
|
+
else if (mdItem.type === 'MD.newline') {
|
|
197
|
+
// 换行
|
|
198
|
+
return '\n';
|
|
199
|
+
}
|
|
200
|
+
else if (mdItem.type === 'MD.link') {
|
|
201
|
+
//
|
|
202
|
+
return `[🔗${mdItem.value.text}](${mdItem.value.url}) `;
|
|
203
|
+
}
|
|
204
|
+
else if (mdItem.type === 'MD.image') {
|
|
205
|
+
//
|
|
206
|
+
return ` `;
|
|
207
|
+
}
|
|
208
|
+
else if (mdItem.type === 'MD.list') {
|
|
209
|
+
const listStr = mdItem.value.map(listItem => {
|
|
210
|
+
// 有序
|
|
211
|
+
if (typeof listItem.value === 'object') {
|
|
212
|
+
return `\n${listItem.value.index}. ${listItem.value.text}`;
|
|
213
|
+
}
|
|
214
|
+
// 无序
|
|
215
|
+
return `\n- ${listItem.value}`;
|
|
216
|
+
});
|
|
217
|
+
return `${listStr}\n`;
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
})
|
|
221
|
+
.join('');
|
|
222
|
+
return content;
|
|
223
|
+
};
|
|
150
224
|
/**
|
|
151
225
|
* 群组消息
|
|
152
226
|
* @param client
|
|
@@ -155,172 +229,158 @@ const createArkList = (value) => {
|
|
|
155
229
|
* @returns
|
|
156
230
|
*/
|
|
157
231
|
const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (item.type == 'Link') {
|
|
162
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
163
|
-
}
|
|
164
|
-
else if (item.type == 'Mention') {
|
|
165
|
-
if (item.value == 'everyone' ||
|
|
166
|
-
item.value == 'all' ||
|
|
167
|
-
item.value == '' ||
|
|
168
|
-
typeof item.value != 'string') {
|
|
169
|
-
return ``;
|
|
170
|
-
}
|
|
171
|
-
if (item.options?.belong == 'user') {
|
|
172
|
-
return `<@${item.value}>`;
|
|
173
|
-
}
|
|
174
|
-
return '';
|
|
175
|
-
}
|
|
176
|
-
else if (item.type == 'Text') {
|
|
177
|
-
return item.value;
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
.join('');
|
|
181
|
-
if (content) {
|
|
182
|
-
const res = await Promise.all([content].map(async (item) => {
|
|
183
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
184
|
-
content: item,
|
|
185
|
-
msg_id: event.MessageId,
|
|
186
|
-
msg_type: 0,
|
|
187
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
188
|
-
});
|
|
189
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
190
|
-
id: res.id
|
|
191
|
-
});
|
|
192
|
-
})).catch(err => [
|
|
193
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
194
|
-
]);
|
|
195
|
-
return res;
|
|
232
|
+
const baseParams = {};
|
|
233
|
+
if (event.tag === 'INTERACTION_CREATE_GROUP') {
|
|
234
|
+
baseParams['event_id'] = event.MessageId;
|
|
196
235
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
msg_id: event.MessageId,
|
|
207
|
-
msg_type: 7,
|
|
208
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
209
|
-
});
|
|
210
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
211
|
-
id: res.id
|
|
212
|
-
});
|
|
236
|
+
else {
|
|
237
|
+
baseParams['msg_id'] = event.MessageId;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const content = val
|
|
241
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
242
|
+
.map(item => {
|
|
243
|
+
if (item.type == 'Link') {
|
|
244
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
213
245
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return createResult(ResultCode.Fail, 'client.postRichMediaByGroup', null);
|
|
226
|
-
}
|
|
227
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
228
|
-
content: '',
|
|
229
|
-
media: {
|
|
230
|
-
file_info
|
|
231
|
-
},
|
|
232
|
-
msg_id: event.MessageId,
|
|
233
|
-
msg_type: 7,
|
|
234
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
235
|
-
});
|
|
236
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
237
|
-
id: res.id
|
|
238
|
-
});
|
|
246
|
+
else if (item.type == 'Mention') {
|
|
247
|
+
if (item.value == 'everyone' ||
|
|
248
|
+
item.value == 'all' ||
|
|
249
|
+
item.value == '' ||
|
|
250
|
+
typeof item.value != 'string') {
|
|
251
|
+
return ``;
|
|
252
|
+
}
|
|
253
|
+
if (item.options?.belong == 'user') {
|
|
254
|
+
return `<@${item.value}>`;
|
|
255
|
+
}
|
|
256
|
+
return '';
|
|
239
257
|
}
|
|
240
|
-
|
|
241
|
-
return
|
|
258
|
+
else if (item.type == 'Text') {
|
|
259
|
+
return item.value;
|
|
242
260
|
}
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
})
|
|
262
|
+
.join('');
|
|
263
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
264
|
+
if (images && images.length > 0) {
|
|
265
|
+
let url = '';
|
|
266
|
+
for (let i = 0; i < images.length; i++) {
|
|
267
|
+
// 已经处理。
|
|
268
|
+
if (url)
|
|
269
|
+
break;
|
|
270
|
+
const item = images[i];
|
|
271
|
+
if (item.type == 'ImageURL') {
|
|
272
|
+
url = item.value;
|
|
273
|
+
}
|
|
274
|
+
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
275
|
+
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
276
|
+
const file_data = item.type == 'ImageFile' ? getFileBase64() : item.value;
|
|
277
|
+
const file_info = await client
|
|
278
|
+
.postRichMediaById(event.ChannelId, {
|
|
279
|
+
file_type: 1,
|
|
280
|
+
file_data: file_data
|
|
281
|
+
})
|
|
282
|
+
.then(res => res?.file_info);
|
|
283
|
+
if (file_info) {
|
|
284
|
+
url = file_info;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
265
287
|
}
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
content: '',
|
|
271
|
-
msg_id: event.MessageId,
|
|
272
|
-
keyboard: {
|
|
273
|
-
content: data
|
|
288
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
289
|
+
content: content,
|
|
290
|
+
media: {
|
|
291
|
+
file_info: url
|
|
274
292
|
},
|
|
293
|
+
msg_type: 7,
|
|
294
|
+
...baseParams
|
|
295
|
+
});
|
|
296
|
+
return [
|
|
297
|
+
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
298
|
+
id: res.id
|
|
299
|
+
})
|
|
300
|
+
];
|
|
301
|
+
}
|
|
302
|
+
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
303
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
304
|
+
const params = {};
|
|
305
|
+
mdAndButtons.forEach(async (item) => {
|
|
306
|
+
if (item.type === 'BT.group') {
|
|
307
|
+
// 如果是按钮,获取参数
|
|
308
|
+
const template_id = item?.options?.template_id;
|
|
309
|
+
if (template_id) {
|
|
310
|
+
params['keyboard'] = {
|
|
311
|
+
id: template_id
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
const rows = item.value;
|
|
316
|
+
// 构造成按钮
|
|
317
|
+
const content = createButtonsData(rows);
|
|
318
|
+
params['keyboard'] = {
|
|
319
|
+
content: content
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if (item.type === 'Markdown') {
|
|
324
|
+
// 如果是markdown,获取内容
|
|
325
|
+
const content = createMarkdownText(item.value);
|
|
326
|
+
if (content) {
|
|
327
|
+
params['markdown'] = {
|
|
328
|
+
content: content
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
334
|
+
content: content,
|
|
275
335
|
msg_type: 2,
|
|
276
|
-
|
|
336
|
+
...params,
|
|
337
|
+
...baseParams
|
|
277
338
|
});
|
|
278
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
279
|
-
|
|
339
|
+
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
340
|
+
}
|
|
341
|
+
// ark
|
|
342
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
343
|
+
if (ark && ark.length > 0) {
|
|
344
|
+
const params = {};
|
|
345
|
+
ark.forEach(async (item) => {
|
|
346
|
+
if (item.type === 'Ark.Card') {
|
|
347
|
+
const arkData = createArkCardData(item.value);
|
|
348
|
+
params['ark'] = arkData;
|
|
349
|
+
}
|
|
350
|
+
else if (item.type === 'Ark.BigCard') {
|
|
351
|
+
const arkData = createArkBigCardData(item.value);
|
|
352
|
+
params['ark'] = arkData;
|
|
353
|
+
}
|
|
354
|
+
else if (item.type === 'Ark.list') {
|
|
355
|
+
const arkData = createArkList(item.value);
|
|
356
|
+
params['ark'] = arkData;
|
|
357
|
+
}
|
|
280
358
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
]);
|
|
284
|
-
}
|
|
285
|
-
// ark
|
|
286
|
-
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
287
|
-
if (ark && ark.length > 0) {
|
|
288
|
-
return Promise.all(ark.map(async (item) => {
|
|
289
|
-
if (item.type === 'Ark.Card') {
|
|
290
|
-
const arkData = createArkCardData(item.value);
|
|
291
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
292
|
-
msg_id: event.MessageId,
|
|
293
|
-
ark: arkData,
|
|
294
|
-
msg_type: 3,
|
|
295
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
296
|
-
});
|
|
297
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
298
|
-
id: res.id
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
if (item.type === 'Ark.BigCard') {
|
|
302
|
-
const arkData = createArkBigCardData(item.value);
|
|
303
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
304
|
-
msg_id: event.MessageId,
|
|
305
|
-
ark: arkData,
|
|
306
|
-
msg_type: 3,
|
|
307
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
308
|
-
});
|
|
309
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
310
|
-
}
|
|
311
|
-
const arkData = createArkList(item.value);
|
|
312
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
313
|
-
msg_id: event.MessageId,
|
|
314
|
-
ark: arkData,
|
|
359
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
360
|
+
content: content,
|
|
315
361
|
msg_type: 3,
|
|
316
|
-
|
|
362
|
+
...params,
|
|
363
|
+
...baseParams
|
|
317
364
|
});
|
|
318
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
365
|
+
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
366
|
+
}
|
|
367
|
+
if (content) {
|
|
368
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
369
|
+
content: content,
|
|
370
|
+
msg_type: 0,
|
|
371
|
+
...baseParams
|
|
372
|
+
});
|
|
373
|
+
return [
|
|
374
|
+
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
375
|
+
id: res.id
|
|
376
|
+
})
|
|
377
|
+
];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
catch (err) {
|
|
381
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
322
382
|
}
|
|
323
|
-
return
|
|
383
|
+
return [];
|
|
324
384
|
};
|
|
325
385
|
/**
|
|
326
386
|
* 私聊消息
|
|
@@ -329,150 +389,159 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
329
389
|
* @param val
|
|
330
390
|
* @returns
|
|
331
391
|
*/
|
|
332
|
-
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (item.type == 'Link') {
|
|
337
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
338
|
-
}
|
|
339
|
-
else if (item.type == 'Text') {
|
|
340
|
-
return item.value;
|
|
341
|
-
}
|
|
342
|
-
return '';
|
|
343
|
-
})
|
|
344
|
-
.join('');
|
|
345
|
-
if (content) {
|
|
346
|
-
return Promise.all([content].map(async (item) => {
|
|
347
|
-
const res = await client.usersOpenMessages(event.OpenId, {
|
|
348
|
-
content: item,
|
|
349
|
-
msg_id: event.MessageId,
|
|
350
|
-
msg_type: 0,
|
|
351
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
352
|
-
});
|
|
353
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
354
|
-
id: res.id
|
|
355
|
-
});
|
|
356
|
-
})).catch(err => [
|
|
357
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
358
|
-
]);
|
|
392
|
+
const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
393
|
+
const baseParams = {};
|
|
394
|
+
if (event.tag === 'INTERACTION_CREATE_C2C') {
|
|
395
|
+
baseParams['event_id'] = event.MessageId;
|
|
359
396
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
msg_id: event.MessageId,
|
|
370
|
-
msg_type: 7,
|
|
371
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
372
|
-
});
|
|
373
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
374
|
-
id: res.id
|
|
375
|
-
});
|
|
397
|
+
else {
|
|
398
|
+
baseParams['msg_id'] = event.MessageId;
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
const content = val
|
|
402
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
403
|
+
.map(item => {
|
|
404
|
+
if (item.type == 'Link') {
|
|
405
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
376
406
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return
|
|
388
|
-
|
|
389
|
-
|
|
407
|
+
else if (item.type == 'Mention') {
|
|
408
|
+
if (item.value == 'everyone' ||
|
|
409
|
+
item.value == 'all' ||
|
|
410
|
+
item.value == '' ||
|
|
411
|
+
typeof item.value != 'string') {
|
|
412
|
+
return ``;
|
|
413
|
+
}
|
|
414
|
+
if (item.options?.belong == 'user') {
|
|
415
|
+
return `<@${item.value}>`;
|
|
416
|
+
}
|
|
417
|
+
return '';
|
|
418
|
+
}
|
|
419
|
+
else if (item.type == 'Text') {
|
|
420
|
+
return item.value;
|
|
421
|
+
}
|
|
422
|
+
})
|
|
423
|
+
.join('');
|
|
424
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
425
|
+
if (images && images.length > 0) {
|
|
426
|
+
let url = '';
|
|
427
|
+
for (let i = 0; i < images.length; i++) {
|
|
428
|
+
// 已经处理。
|
|
429
|
+
if (url)
|
|
430
|
+
break;
|
|
431
|
+
const item = images[i];
|
|
432
|
+
if (item.type == 'ImageURL') {
|
|
433
|
+
url = item.value;
|
|
434
|
+
}
|
|
435
|
+
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
436
|
+
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
437
|
+
const file_data = item.type == 'ImageFile' ? getFileBase64() : item.value;
|
|
438
|
+
const file_info = await client
|
|
439
|
+
.postRichMediaById(event.UserId, {
|
|
440
|
+
file_type: 1,
|
|
441
|
+
file_data: file_data
|
|
442
|
+
})
|
|
443
|
+
.then(res => res?.file_info);
|
|
444
|
+
if (file_info) {
|
|
445
|
+
url = file_info;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
450
|
+
content: content,
|
|
390
451
|
media: {
|
|
391
|
-
file_info
|
|
452
|
+
file_info: url
|
|
392
453
|
},
|
|
393
|
-
msg_id: event.MessageId,
|
|
394
454
|
msg_type: 7,
|
|
395
|
-
|
|
455
|
+
...baseParams
|
|
396
456
|
});
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
]);
|
|
400
|
-
}
|
|
401
|
-
// buttons
|
|
402
|
-
const buttons = val.filter(item => item.type == 'BT.group');
|
|
403
|
-
if (buttons && buttons.length > 0) {
|
|
404
|
-
return Promise.all(buttons.map(async (item) => {
|
|
405
|
-
const template_id = item?.options?.template_id;
|
|
406
|
-
if (template_id) {
|
|
407
|
-
const res = await client.usersOpenMessages(event.GuildId, {
|
|
408
|
-
content: '',
|
|
409
|
-
msg_id: event.MessageId,
|
|
410
|
-
keyboard: {
|
|
411
|
-
id: template_id
|
|
412
|
-
},
|
|
413
|
-
msg_type: 2,
|
|
414
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
415
|
-
});
|
|
416
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
457
|
+
return [
|
|
458
|
+
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
417
459
|
id: res.id
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
460
|
+
})
|
|
461
|
+
];
|
|
462
|
+
}
|
|
463
|
+
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
464
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
465
|
+
const params = {};
|
|
466
|
+
mdAndButtons.forEach(async (item) => {
|
|
467
|
+
if (item.type === 'BT.group') {
|
|
468
|
+
// 如果是按钮,获取参数
|
|
469
|
+
const template_id = item?.options?.template_id;
|
|
470
|
+
if (template_id) {
|
|
471
|
+
params['keyboard'] = {
|
|
472
|
+
id: template_id
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
const rows = item.value;
|
|
477
|
+
// 构造成按钮
|
|
478
|
+
const content = createButtonsData(rows);
|
|
479
|
+
params['keyboard'] = {
|
|
480
|
+
content: content
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
else if (item.type === 'Markdown') {
|
|
485
|
+
// 如果是markdown,获取内容
|
|
486
|
+
const content = createMarkdownText(item.value);
|
|
487
|
+
if (content) {
|
|
488
|
+
params['markdown'] = {
|
|
489
|
+
content: content
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
495
|
+
content: content,
|
|
429
496
|
msg_type: 2,
|
|
430
|
-
|
|
497
|
+
...params,
|
|
498
|
+
...baseParams
|
|
431
499
|
});
|
|
432
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
433
|
-
|
|
500
|
+
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
501
|
+
}
|
|
502
|
+
// ark
|
|
503
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
504
|
+
if (ark && ark.length > 0) {
|
|
505
|
+
const params = {};
|
|
506
|
+
ark.forEach(async (item) => {
|
|
507
|
+
if (item.type === 'Ark.Card') {
|
|
508
|
+
const arkData = createArkCardData(item.value);
|
|
509
|
+
params['ark'] = arkData;
|
|
510
|
+
}
|
|
511
|
+
else if (item.type === 'Ark.BigCard') {
|
|
512
|
+
const arkData = createArkBigCardData(item.value);
|
|
513
|
+
params['ark'] = arkData;
|
|
514
|
+
}
|
|
515
|
+
else if (item.type === 'Ark.list') {
|
|
516
|
+
const arkData = createArkList(item.value);
|
|
517
|
+
params['ark'] = arkData;
|
|
518
|
+
}
|
|
434
519
|
});
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
]);
|
|
438
|
-
}
|
|
439
|
-
// ark
|
|
440
|
-
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
441
|
-
if (ark && ark.length > 0) {
|
|
442
|
-
return Promise.all(ark.map(async (item) => {
|
|
443
|
-
if (item.type === 'Ark.Card') {
|
|
444
|
-
const arkData = createArkCardData(item.value);
|
|
445
|
-
const res = await client.usersOpenMessages(event.GuildId, {
|
|
446
|
-
msg_id: event.MessageId,
|
|
447
|
-
ark: arkData,
|
|
448
|
-
msg_type: 3,
|
|
449
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
450
|
-
});
|
|
451
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
452
|
-
}
|
|
453
|
-
if (item.type === 'Ark.BigCard') {
|
|
454
|
-
const arkData = createArkBigCardData(item.value);
|
|
455
|
-
const res = await client.usersOpenMessages(event.GuildId, {
|
|
456
|
-
msg_id: event.MessageId,
|
|
457
|
-
ark: arkData,
|
|
458
|
-
msg_type: 3,
|
|
459
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
460
|
-
});
|
|
461
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
462
|
-
}
|
|
463
|
-
const arkData = createArkList(item.value);
|
|
464
|
-
const res = await client.usersOpenMessages(event.GuildId, {
|
|
465
|
-
msg_id: event.MessageId,
|
|
466
|
-
ark: arkData,
|
|
520
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
521
|
+
content: content,
|
|
467
522
|
msg_type: 3,
|
|
468
|
-
|
|
523
|
+
...params,
|
|
524
|
+
...baseParams
|
|
525
|
+
});
|
|
526
|
+
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
527
|
+
}
|
|
528
|
+
if (content) {
|
|
529
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
530
|
+
content: content,
|
|
531
|
+
msg_type: 0,
|
|
532
|
+
...baseParams
|
|
469
533
|
});
|
|
470
|
-
return
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
534
|
+
return [
|
|
535
|
+
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
536
|
+
id: res.id
|
|
537
|
+
})
|
|
538
|
+
];
|
|
539
|
+
}
|
|
474
540
|
}
|
|
475
|
-
|
|
541
|
+
catch (err) {
|
|
542
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
543
|
+
}
|
|
544
|
+
return [];
|
|
476
545
|
};
|
|
477
546
|
/**
|
|
478
547
|
* 频道私聊
|
|
@@ -481,195 +550,285 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
481
550
|
* @param val
|
|
482
551
|
* @returns
|
|
483
552
|
*/
|
|
484
|
-
const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (item.type == 'Link') {
|
|
489
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
490
|
-
}
|
|
491
|
-
if (item.type == 'Text') {
|
|
492
|
-
return item.value;
|
|
493
|
-
}
|
|
494
|
-
return '';
|
|
495
|
-
})
|
|
496
|
-
.join('');
|
|
497
|
-
if (content) {
|
|
498
|
-
return Promise.all([content].map(async (item) => {
|
|
499
|
-
const res = await client.dmsMessage(event.OpenId, {
|
|
500
|
-
content: item,
|
|
501
|
-
msg_id: event.MessageId
|
|
502
|
-
});
|
|
503
|
-
return createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id });
|
|
504
|
-
})).catch(err => [
|
|
505
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
506
|
-
]);
|
|
553
|
+
const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
554
|
+
const baseParams = {};
|
|
555
|
+
if (event.tag === 'INTERACTION_CREATE_GUILD') {
|
|
556
|
+
baseParams['event_id'] = event.MessageId;
|
|
507
557
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return Promise.all(images.map(async (item) => {
|
|
511
|
-
if (item.value == 'ImageURL') {
|
|
512
|
-
// 请求得到buffer
|
|
513
|
-
const data = await axios
|
|
514
|
-
.get(item.value, {
|
|
515
|
-
responseType: 'arraybuffer'
|
|
516
|
-
})
|
|
517
|
-
.then(res => res?.data);
|
|
518
|
-
const res = await client.postDirectImage(event.OpenId, {
|
|
519
|
-
msg_id: event.MessageId,
|
|
520
|
-
image: data
|
|
521
|
-
});
|
|
522
|
-
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
523
|
-
}
|
|
524
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
525
|
-
const res = await client.postDirectImage(event.OpenId, {
|
|
526
|
-
msg_id: event.MessageId,
|
|
527
|
-
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
528
|
-
});
|
|
529
|
-
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
530
|
-
})).catch(err => [
|
|
531
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
532
|
-
]);
|
|
558
|
+
else {
|
|
559
|
+
baseParams['msg_id'] = event.MessageId;
|
|
533
560
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
if (item.type == 'Link') {
|
|
541
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
542
|
-
}
|
|
543
|
-
if (item.type == 'Mention') {
|
|
544
|
-
if (item.value == 'everyone' ||
|
|
545
|
-
item.value == 'all' ||
|
|
546
|
-
item.value == '' ||
|
|
547
|
-
typeof item.value != 'string') {
|
|
548
|
-
return `@everyone`;
|
|
561
|
+
try {
|
|
562
|
+
const content = val
|
|
563
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
564
|
+
.map(item => {
|
|
565
|
+
if (item.type == 'Link') {
|
|
566
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
549
567
|
}
|
|
550
|
-
if (item.
|
|
551
|
-
return
|
|
552
|
-
}
|
|
553
|
-
else if (item.options?.belong == 'channel') {
|
|
554
|
-
return `<#${item.value}>`;
|
|
568
|
+
if (item.type == 'Text') {
|
|
569
|
+
return item.value;
|
|
555
570
|
}
|
|
556
571
|
return '';
|
|
572
|
+
})
|
|
573
|
+
.join('');
|
|
574
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
575
|
+
if (images && images.length > 0) {
|
|
576
|
+
let imageBuffer = null;
|
|
577
|
+
for (let i = 0; i < images.length; i++) {
|
|
578
|
+
// 已经处理。
|
|
579
|
+
if (imageBuffer)
|
|
580
|
+
break;
|
|
581
|
+
const item = images[i];
|
|
582
|
+
if (item.value == 'ImageURL') {
|
|
583
|
+
// 请求得到buffer
|
|
584
|
+
const data = await axios
|
|
585
|
+
.get(item.value, {
|
|
586
|
+
responseType: 'arraybuffer'
|
|
587
|
+
})
|
|
588
|
+
.then(res => res?.data);
|
|
589
|
+
imageBuffer = data;
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
593
|
+
imageBuffer = file_data;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
597
|
+
content: content,
|
|
598
|
+
...baseParams
|
|
599
|
+
}, imageBuffer);
|
|
600
|
+
return [createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id })];
|
|
557
601
|
}
|
|
558
|
-
|
|
559
|
-
|
|
602
|
+
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
603
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
604
|
+
const params = {};
|
|
605
|
+
mdAndButtons.forEach(async (item) => {
|
|
606
|
+
if (item.type === 'BT.group') {
|
|
607
|
+
// 如果是按钮,获取参数
|
|
608
|
+
const template_id = item?.options?.template_id;
|
|
609
|
+
if (template_id) {
|
|
610
|
+
params['keyboard'] = {
|
|
611
|
+
id: template_id
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
const rows = item.value;
|
|
616
|
+
// 构造成按钮
|
|
617
|
+
const content = createButtonsData(rows);
|
|
618
|
+
params['keyboard'] = {
|
|
619
|
+
content: content
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
else if (item.type === 'Markdown') {
|
|
624
|
+
// 如果是markdown,获取内容
|
|
625
|
+
const content = createMarkdownText(item.value);
|
|
626
|
+
if (content) {
|
|
627
|
+
params['markdown'] = {
|
|
628
|
+
content: content
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
634
|
+
content: '',
|
|
635
|
+
...params,
|
|
636
|
+
...baseParams
|
|
637
|
+
});
|
|
638
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
560
639
|
}
|
|
561
|
-
|
|
562
|
-
.
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
640
|
+
// ark
|
|
641
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
642
|
+
if (ark && ark.length > 0) {
|
|
643
|
+
const params = {};
|
|
644
|
+
ark.forEach(async (item) => {
|
|
645
|
+
if (item.type === 'Ark.Card') {
|
|
646
|
+
const arkData = createArkCardData(item.value);
|
|
647
|
+
params['ark'] = arkData;
|
|
648
|
+
}
|
|
649
|
+
else if (item.type === 'Ark.BigCard') {
|
|
650
|
+
const arkData = createArkBigCardData(item.value);
|
|
651
|
+
params['ark'] = arkData;
|
|
652
|
+
}
|
|
653
|
+
else if (item.type === 'Ark.list') {
|
|
654
|
+
const arkData = createArkList(item.value);
|
|
655
|
+
params['ark'] = arkData;
|
|
656
|
+
}
|
|
568
657
|
});
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
575
|
-
if (images && images.length > 0) {
|
|
576
|
-
return Promise.all(images.map(async (item) => {
|
|
577
|
-
if (item.value == 'ImageURL') {
|
|
578
|
-
// 请求得到buffer
|
|
579
|
-
const data = await axios
|
|
580
|
-
.get(item.value, {
|
|
581
|
-
responseType: 'arraybuffer'
|
|
582
|
-
})
|
|
583
|
-
.then(res => res.data);
|
|
584
|
-
const res = await client.postImage(event.ChannelId, {
|
|
585
|
-
msg_id: event.MessageId,
|
|
586
|
-
image: data
|
|
587
|
-
});
|
|
588
|
-
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
589
|
-
}
|
|
590
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
591
|
-
const res = await client.postImage(event.ChannelId, {
|
|
592
|
-
msg_id: event.MessageId,
|
|
593
|
-
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
658
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
659
|
+
content: content,
|
|
660
|
+
...params,
|
|
661
|
+
...baseParams
|
|
594
662
|
});
|
|
595
|
-
return createResult(ResultCode.Ok, 'client.
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
663
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
664
|
+
}
|
|
665
|
+
if (content) {
|
|
666
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
667
|
+
content: content,
|
|
668
|
+
...baseParams
|
|
669
|
+
});
|
|
670
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id })];
|
|
671
|
+
}
|
|
672
|
+
return [];
|
|
673
|
+
}
|
|
674
|
+
catch (err) {
|
|
675
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
599
676
|
}
|
|
600
|
-
return Promise.all([]);
|
|
601
677
|
};
|
|
602
678
|
/**
|
|
603
|
-
*
|
|
679
|
+
* 频道公聊
|
|
604
680
|
* @param event
|
|
605
681
|
* @param val
|
|
606
682
|
* @returns
|
|
607
683
|
*/
|
|
608
|
-
const MESSAGE_CREATE = (client, event, val) => {
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
684
|
+
const MESSAGE_CREATE = async (client, event, val) => {
|
|
685
|
+
const baseParams = {};
|
|
686
|
+
if (event.tag === 'INTERACTION_CREATE_GUILD') {
|
|
687
|
+
baseParams['event_id'] = event.MessageId;
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
baseParams['msg_id'] = event.MessageId;
|
|
691
|
+
}
|
|
692
|
+
try {
|
|
693
|
+
const content = val
|
|
694
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
695
|
+
.map(item => {
|
|
696
|
+
if (item.type == 'Link') {
|
|
697
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
621
698
|
}
|
|
622
|
-
if (item.
|
|
623
|
-
|
|
699
|
+
if (item.type == 'Mention') {
|
|
700
|
+
if (item.value == 'everyone' ||
|
|
701
|
+
item.value == 'all' ||
|
|
702
|
+
item.value == '' ||
|
|
703
|
+
typeof item.value != 'string') {
|
|
704
|
+
return `@everyone`;
|
|
705
|
+
}
|
|
706
|
+
if (item.options?.belong == 'user') {
|
|
707
|
+
return `<@!${item.value}>`;
|
|
708
|
+
}
|
|
709
|
+
else if (item.options?.belong == 'channel') {
|
|
710
|
+
return `<#${item.value}>`;
|
|
711
|
+
}
|
|
712
|
+
return '';
|
|
624
713
|
}
|
|
625
|
-
else if (item.
|
|
626
|
-
return
|
|
714
|
+
else if (item.type == 'Text') {
|
|
715
|
+
return item.value;
|
|
627
716
|
}
|
|
628
|
-
|
|
717
|
+
})
|
|
718
|
+
.join('');
|
|
719
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
720
|
+
if (images && images.length > 0) {
|
|
721
|
+
let imageBuffer = null;
|
|
722
|
+
for (let i = 0; i < images.length; i++) {
|
|
723
|
+
// 已经处理。
|
|
724
|
+
if (imageBuffer)
|
|
725
|
+
break;
|
|
726
|
+
const item = images[i];
|
|
727
|
+
if (item.value == 'ImageURL') {
|
|
728
|
+
// 请求得到buffer
|
|
729
|
+
const data = await axios
|
|
730
|
+
.get(item.value, {
|
|
731
|
+
responseType: 'arraybuffer'
|
|
732
|
+
})
|
|
733
|
+
.then(res => res?.data);
|
|
734
|
+
imageBuffer = data;
|
|
735
|
+
}
|
|
736
|
+
else {
|
|
737
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
738
|
+
imageBuffer = file_data;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
742
|
+
content: content,
|
|
743
|
+
...baseParams
|
|
744
|
+
}, imageBuffer);
|
|
745
|
+
return [createResult(ResultCode.Ok, 'client.postImage', { id: res?.id })];
|
|
629
746
|
}
|
|
630
|
-
|
|
631
|
-
|
|
747
|
+
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
748
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
749
|
+
const params = {};
|
|
750
|
+
mdAndButtons.forEach(async (item) => {
|
|
751
|
+
if (item.type === 'BT.group') {
|
|
752
|
+
// 如果是按钮,获取参数
|
|
753
|
+
const template_id = item?.options?.template_id;
|
|
754
|
+
if (template_id) {
|
|
755
|
+
params['keyboard'] = {
|
|
756
|
+
id: template_id
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
const rows = item.value;
|
|
761
|
+
// 构造成按钮
|
|
762
|
+
const content = createButtonsData(rows);
|
|
763
|
+
params['keyboard'] = {
|
|
764
|
+
content: content
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
else if (item.type === 'Markdown') {
|
|
769
|
+
// 如果是markdown,获取内容
|
|
770
|
+
const content = createMarkdownText(item.value);
|
|
771
|
+
if (content) {
|
|
772
|
+
params['markdown'] = {
|
|
773
|
+
content: content
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
779
|
+
content: '',
|
|
780
|
+
...params,
|
|
781
|
+
...baseParams
|
|
782
|
+
});
|
|
783
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
632
784
|
}
|
|
633
|
-
|
|
634
|
-
.
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
785
|
+
// ark
|
|
786
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
787
|
+
if (ark && ark.length > 0) {
|
|
788
|
+
const params = {};
|
|
789
|
+
ark.forEach(async (item) => {
|
|
790
|
+
if (item.type === 'Ark.Card') {
|
|
791
|
+
const arkData = createArkCardData(item.value);
|
|
792
|
+
params['ark'] = arkData;
|
|
793
|
+
}
|
|
794
|
+
else if (item.type === 'Ark.BigCard') {
|
|
795
|
+
const arkData = createArkBigCardData(item.value);
|
|
796
|
+
params['ark'] = arkData;
|
|
797
|
+
}
|
|
798
|
+
else if (item.type === 'Ark.list') {
|
|
799
|
+
const arkData = createArkList(item.value);
|
|
800
|
+
params['ark'] = arkData;
|
|
801
|
+
}
|
|
640
802
|
});
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
644
|
-
]);
|
|
645
|
-
}
|
|
646
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
647
|
-
if (images && images.length > 0) {
|
|
648
|
-
return Promise.all(images.map(async (item) => {
|
|
649
|
-
if (item.value == 'ImageURL') {
|
|
650
|
-
// 请求得到buffer
|
|
651
|
-
const data = await axios
|
|
652
|
-
.get(item.value, {
|
|
653
|
-
responseType: 'arraybuffer'
|
|
654
|
-
})
|
|
655
|
-
.then(res => res.data);
|
|
656
|
-
const res = await client.postImage(event.ChannelId, {
|
|
657
|
-
msg_id: event.MessageId,
|
|
658
|
-
image: data
|
|
659
|
-
});
|
|
660
|
-
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
661
|
-
}
|
|
662
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
663
|
-
const res = await client.postImage(event.ChannelId, {
|
|
803
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
804
|
+
content: content,
|
|
664
805
|
msg_id: event.MessageId,
|
|
665
|
-
|
|
806
|
+
...params
|
|
807
|
+
});
|
|
808
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
809
|
+
}
|
|
810
|
+
if (content) {
|
|
811
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
812
|
+
content: content,
|
|
813
|
+
...baseParams
|
|
666
814
|
});
|
|
667
|
-
return createResult(ResultCode.Ok, 'client.
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
]);
|
|
815
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id })];
|
|
816
|
+
}
|
|
817
|
+
return [];
|
|
671
818
|
}
|
|
672
|
-
|
|
819
|
+
catch (err) {
|
|
820
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
/**
|
|
824
|
+
* 频道公聊 @
|
|
825
|
+
* @param client
|
|
826
|
+
* @param event
|
|
827
|
+
* @param val
|
|
828
|
+
* @returns
|
|
829
|
+
*/
|
|
830
|
+
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
831
|
+
return MESSAGE_CREATE(client, event, val);
|
|
673
832
|
};
|
|
674
833
|
|
|
675
834
|
export { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE };
|