@alemonjs/qq-bot 2.1.0-alpha.2 → 2.1.0-alpha.21
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 -30
- package/lib/config.d.ts +8 -0
- package/lib/config.js +20 -0
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +3 -12
- package/lib/hook.d.ts +30 -9
- package/lib/hook.js +19 -17
- package/lib/index.d.ts +5 -6
- package/lib/index.js +37 -19
- package/lib/index.webhook.d.ts +1 -0
- package/lib/index.webhook.js +5 -4
- package/lib/index.websoket.d.ts +1 -0
- package/lib/index.websoket.js +41 -22
- package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -0
- package/lib/message/AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/CHANNEL_CREATE.d.ts +15 -0
- package/lib/message/CHANNEL_CREATE.js +1 -0
- package/lib/message/CHANNEL_DELETE.d.ts +15 -0
- package/lib/message/CHANNEL_DELETE.js +1 -0
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
- package/lib/message/CHANNEL_UPDATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
- package/lib/message/ERROR.d.ts +1 -0
- package/lib/message/ERROR.js +1 -0
- package/lib/message/GUILD_CREATE.d.ts +15 -0
- package/lib/message/GUILD_CREATE.js +1 -0
- package/lib/message/GUILD_DELETE.d.ts +15 -0
- package/lib/message/GUILD_DELETE.js +1 -0
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/message/GUILD_UPDATE.d.ts +15 -0
- package/lib/message/GUILD_UPDATE.js +1 -0
- package/lib/message/INTERACTION_CREATE.d.ts +53 -0
- package/lib/message/INTERACTION_CREATE.js +1 -0
- package/lib/message/MESSAGE_CREATE.d.ts +1 -0
- package/lib/message/MESSAGE_CREATE.js +1 -0
- package/lib/message/MESSAGE_DELETE.d.ts +1 -0
- package/lib/message/MESSAGE_DELETE.js +1 -0
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
- package/lib/message/READY.d.ts +6 -0
- package/lib/message/READY.js +1 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +9 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
- package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
- package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
- package/lib/message/group/C2C_MSG_REJECT.js +1 -0
- package/lib/message/group/FRIEND_ADD.d.ts +4 -0
- package/lib/message/group/FRIEND_ADD.js +1 -0
- package/lib/message/group/FRIEND_DEL.d.ts +4 -0
- package/lib/message/group/FRIEND_DEL.js +1 -0
- package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +11 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
- package/lib/register.d.ts +2 -3
- package/lib/register.js +270 -176
- package/lib/sdk/api.d.ts +196 -969
- package/lib/sdk/api.js +267 -916
- package/lib/sdk/client.webhook.d.ts +9 -0
- package/lib/sdk/{client.js → client.webhook.js} +19 -53
- package/lib/sdk/client.websoket.d.ts +9 -0
- package/lib/sdk/client.websoket.js +43 -96
- package/lib/sdk/config.d.ts +1 -0
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +3 -0
- package/lib/sdk/intents.js +25 -90
- package/lib/sdk/message.d.ts +4 -0
- package/lib/sdk/message.group.d.ts +24 -0
- package/lib/sdk/message.group.js +1 -0
- package/lib/sdk/message.guild.d.ts +38 -0
- package/lib/sdk/message.guild.js +1 -0
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/message.public.d.ts +6 -0
- package/lib/sdk/message.public.js +1 -0
- package/lib/sdk/typing.d.ts +67 -59
- package/lib/sdk/typing.js +1 -0
- package/lib/sdk/webhook.secret.d.ts +14 -0
- package/lib/sdk/webhook.secret.js +6 -21
- package/lib/sends.d.ts +29 -0
- package/lib/sends.js +546 -477
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +7 -12
- package/package.json +9 -5
- package/lib/index.group.js +0 -19
- package/lib/index.guild.js +0 -36
- package/lib/sdk/client.websoket.group.js +0 -221
- package/lib/sdk/client.websoket.guild.js +0 -205
- package/lib/sdk/counter.js +0 -19
- package/lib/sdk/from.js +0 -44
package/lib/sends.js
CHANGED
|
@@ -12,25 +12,26 @@ 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: {
|
|
18
|
-
label: typeof value
|
|
19
|
-
visited_label: typeof value
|
|
24
|
+
label: typeof value === 'object' ? value.title : value,
|
|
25
|
+
visited_label: typeof value === 'object' ? value.label : value,
|
|
20
26
|
style: 0
|
|
21
27
|
},
|
|
22
28
|
action: {
|
|
23
|
-
|
|
24
|
-
type: typeof options.data === 'object' ? 1 : options?.isLink ? 0 : 2,
|
|
29
|
+
type: map[typing],
|
|
25
30
|
permission: {
|
|
26
|
-
// 所有人
|
|
27
31
|
type: 2
|
|
28
|
-
// "specify_role_ids": ["1", "2", "3"]
|
|
29
32
|
},
|
|
30
|
-
// "click_limit": 10,
|
|
31
33
|
unsupport_tips: options?.toolTip ?? '',
|
|
32
34
|
data: options?.data ?? '',
|
|
33
|
-
// reply: true,
|
|
34
35
|
at_bot_show_channel_list: options.showList ?? false,
|
|
35
36
|
enter: options?.autoEnter ?? false
|
|
36
37
|
}
|
|
@@ -147,529 +148,597 @@ const createArkList = (value) => {
|
|
|
147
148
|
]
|
|
148
149
|
};
|
|
149
150
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
151
|
+
const map = {
|
|
152
|
+
'MD.title': value => `# ${value}`,
|
|
153
|
+
'MD.subtitle': value => `## ${value}`,
|
|
154
|
+
'MD.text': value => `${value} `,
|
|
155
|
+
'MD.bold': value => `**${value}** `,
|
|
156
|
+
'MD.divider': () => '\n————————\n',
|
|
157
|
+
'MD.italic': value => `_${value}_ `,
|
|
158
|
+
'MD.italicStar': value => `*${value}* `,
|
|
159
|
+
'MD.strikethrough': value => `~~${value}~~ `,
|
|
160
|
+
'MD.blockquote': value => `\n> ${value}`,
|
|
161
|
+
'MD.newline': () => '\n',
|
|
162
|
+
'MD.link': value => `[🔗${value.text}](${value.url}) `
|
|
163
|
+
};
|
|
164
|
+
const createMarkdownText = (data) => {
|
|
165
|
+
const content = data
|
|
166
|
+
.map(mdItem => {
|
|
167
|
+
if (map[mdItem.type]) {
|
|
168
|
+
const value = mdItem?.value;
|
|
169
|
+
return map[mdItem.type](value);
|
|
163
170
|
}
|
|
164
|
-
|
|
165
|
-
|
|
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 '';
|
|
171
|
+
if (mdItem.type === 'MD.image') {
|
|
172
|
+
return `\n\n`;
|
|
175
173
|
}
|
|
176
|
-
else if (
|
|
177
|
-
|
|
174
|
+
else if (mdItem.type === 'MD.list') {
|
|
175
|
+
const listStr = mdItem.value.map(listItem => {
|
|
176
|
+
if (typeof listItem.value === 'object') {
|
|
177
|
+
return `\n${listItem.value.index}. ${listItem.value.text}`;
|
|
178
|
+
}
|
|
179
|
+
return `\n- ${listItem.value}`;
|
|
180
|
+
});
|
|
181
|
+
return `${listStr}\n`;
|
|
182
|
+
}
|
|
183
|
+
else if (mdItem.type === 'MD.code') {
|
|
184
|
+
const language = mdItem?.options?.language || '';
|
|
185
|
+
return `\n\`\`\`${language}\n${mdItem.value}\n\`\`\`\n`;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const value = mdItem['value'] || '';
|
|
189
|
+
return String(value);
|
|
178
190
|
}
|
|
179
191
|
})
|
|
180
192
|
.join('');
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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;
|
|
193
|
+
return content;
|
|
194
|
+
};
|
|
195
|
+
const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
196
|
+
const baseParams = {};
|
|
197
|
+
if (event.tag === 'INTERACTION_CREATE_GROUP') {
|
|
198
|
+
baseParams['event_id'] = event.MessageId;
|
|
196
199
|
}
|
|
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
|
-
});
|
|
200
|
+
else {
|
|
201
|
+
baseParams['msg_id'] = event.MessageId;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const content = val
|
|
205
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
206
|
+
.map(item => {
|
|
207
|
+
if (item.type === 'Link') {
|
|
208
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
213
209
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
})
|
|
223
|
-
.then(res => res?.file_info);
|
|
224
|
-
if (!file_info) {
|
|
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
|
-
});
|
|
210
|
+
else if (item.type === 'Mention') {
|
|
211
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
212
|
+
return '';
|
|
213
|
+
}
|
|
214
|
+
if (item.options?.belong === 'user') {
|
|
215
|
+
return `<@${item.value}>`;
|
|
216
|
+
}
|
|
217
|
+
return '';
|
|
239
218
|
}
|
|
240
|
-
|
|
241
|
-
return
|
|
219
|
+
else if (item.type === 'Text') {
|
|
220
|
+
return item.value;
|
|
242
221
|
}
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
222
|
+
})
|
|
223
|
+
.join('');
|
|
224
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
225
|
+
if (images && images.length > 0) {
|
|
226
|
+
let url = '';
|
|
227
|
+
for (let i = 0; i < images.length; i++) {
|
|
228
|
+
if (url) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
const item = images[i];
|
|
232
|
+
if (item.type === 'ImageURL') {
|
|
233
|
+
url = item.value;
|
|
234
|
+
}
|
|
235
|
+
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
236
|
+
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
237
|
+
const file_data = item.type === 'ImageFile' ? getFileBase64() : item.value;
|
|
238
|
+
const file_info = await client
|
|
239
|
+
.postRichMediaByGroup(event.ChannelId, {
|
|
240
|
+
file_type: 1,
|
|
241
|
+
file_data: file_data
|
|
242
|
+
})
|
|
243
|
+
.then(res => res?.file_info);
|
|
244
|
+
if (file_info) {
|
|
245
|
+
url = file_info;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
265
248
|
}
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
content: '',
|
|
271
|
-
msg_id: event.MessageId,
|
|
272
|
-
keyboard: {
|
|
273
|
-
content: data
|
|
249
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
250
|
+
content: content,
|
|
251
|
+
media: {
|
|
252
|
+
file_info: url
|
|
274
253
|
},
|
|
254
|
+
msg_type: 7,
|
|
255
|
+
...baseParams
|
|
256
|
+
});
|
|
257
|
+
return [
|
|
258
|
+
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
259
|
+
id: res.id
|
|
260
|
+
})
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
264
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
265
|
+
const params = {};
|
|
266
|
+
mdAndButtons.forEach(item => {
|
|
267
|
+
if (item.type === 'ButtonTemplate') {
|
|
268
|
+
const template_id = item?.value;
|
|
269
|
+
if (template_id) {
|
|
270
|
+
params['keyboard'] = {
|
|
271
|
+
id: template_id
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else if (item.type === 'BT.group') {
|
|
276
|
+
const rows = item.value;
|
|
277
|
+
const content = createButtonsData(rows);
|
|
278
|
+
params['keyboard'] = {
|
|
279
|
+
content: content
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
else if (item.type === 'Markdown') {
|
|
283
|
+
const content = createMarkdownText(item.value);
|
|
284
|
+
if (content) {
|
|
285
|
+
params['markdown'] = {
|
|
286
|
+
content: content
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
292
|
+
content: content,
|
|
275
293
|
msg_type: 2,
|
|
276
|
-
|
|
294
|
+
...params,
|
|
295
|
+
...baseParams
|
|
277
296
|
});
|
|
278
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
279
|
-
|
|
297
|
+
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
298
|
+
}
|
|
299
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
300
|
+
if (ark && ark.length > 0) {
|
|
301
|
+
const params = {};
|
|
302
|
+
ark.forEach(item => {
|
|
303
|
+
if (item.type === 'Ark.Card') {
|
|
304
|
+
const arkData = createArkCardData(item.value);
|
|
305
|
+
params['ark'] = arkData;
|
|
306
|
+
}
|
|
307
|
+
else if (item.type === 'Ark.BigCard') {
|
|
308
|
+
const arkData = createArkBigCardData(item.value);
|
|
309
|
+
params['ark'] = arkData;
|
|
310
|
+
}
|
|
311
|
+
else if (item.type === 'Ark.list') {
|
|
312
|
+
const arkData = createArkList(item.value);
|
|
313
|
+
params['ark'] = arkData;
|
|
314
|
+
}
|
|
280
315
|
});
|
|
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,
|
|
316
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
317
|
+
content: content,
|
|
315
318
|
msg_type: 3,
|
|
316
|
-
|
|
319
|
+
...params,
|
|
320
|
+
...baseParams
|
|
317
321
|
});
|
|
318
|
-
return createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id });
|
|
319
|
-
})).catch(err => [
|
|
320
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
321
|
-
]);
|
|
322
|
-
}
|
|
323
|
-
return Promise.all([]);
|
|
324
|
-
};
|
|
325
|
-
/**
|
|
326
|
-
* 私聊消息
|
|
327
|
-
* @param client
|
|
328
|
-
* @param event
|
|
329
|
-
* @param val
|
|
330
|
-
* @returns
|
|
331
|
-
*/
|
|
332
|
-
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
333
|
-
const content = val
|
|
334
|
-
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
335
|
-
.map(item => {
|
|
336
|
-
if (item.type == 'Link') {
|
|
337
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
322
|
+
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
338
323
|
}
|
|
339
|
-
|
|
340
|
-
|
|
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,
|
|
324
|
+
if (content) {
|
|
325
|
+
const res = await client.groupOpenMessages(event.ChannelId, {
|
|
326
|
+
content: content,
|
|
350
327
|
msg_type: 0,
|
|
351
|
-
|
|
352
|
-
});
|
|
353
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
354
|
-
id: res.id
|
|
328
|
+
...baseParams
|
|
355
329
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
]);
|
|
359
|
-
}
|
|
360
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
361
|
-
if (images && images.length > 0) {
|
|
362
|
-
return Promise.all(images.map(async (item) => {
|
|
363
|
-
if (item.type == 'ImageURL') {
|
|
364
|
-
const res = await client.usersOpenMessages(event.OpenId, {
|
|
365
|
-
content: '',
|
|
366
|
-
media: {
|
|
367
|
-
file_info: item.value
|
|
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', {
|
|
330
|
+
return [
|
|
331
|
+
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
374
332
|
id: res.id
|
|
375
|
-
})
|
|
333
|
+
})
|
|
334
|
+
];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
339
|
+
}
|
|
340
|
+
return [];
|
|
341
|
+
};
|
|
342
|
+
const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
343
|
+
const baseParams = {};
|
|
344
|
+
if (event.tag === 'INTERACTION_CREATE_C2C') {
|
|
345
|
+
baseParams['event_id'] = event.MessageId;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
baseParams['msg_id'] = event.MessageId;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
const content = val
|
|
352
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
353
|
+
.map(item => {
|
|
354
|
+
if (item.type === 'Link') {
|
|
355
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
376
356
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (
|
|
387
|
-
return
|
|
388
|
-
|
|
389
|
-
|
|
357
|
+
else if (item.type === 'Mention') {
|
|
358
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
359
|
+
return '';
|
|
360
|
+
}
|
|
361
|
+
if (item.options?.belong === 'user') {
|
|
362
|
+
return `<@${item.value}>`;
|
|
363
|
+
}
|
|
364
|
+
return '';
|
|
365
|
+
}
|
|
366
|
+
else if (item.type === 'Text') {
|
|
367
|
+
return item.value;
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
.join('');
|
|
371
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
372
|
+
if (images && images.length > 0) {
|
|
373
|
+
let url = '';
|
|
374
|
+
for (let i = 0; i < images.length; i++) {
|
|
375
|
+
if (url) {
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
const item = images[i];
|
|
379
|
+
if (item.type === 'ImageURL') {
|
|
380
|
+
url = item.value;
|
|
381
|
+
}
|
|
382
|
+
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
383
|
+
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
384
|
+
const file_data = item.type === 'ImageFile' ? getFileBase64() : item.value;
|
|
385
|
+
const file_info = await client
|
|
386
|
+
.postRichMediaByUser(event.UserId, {
|
|
387
|
+
file_type: 1,
|
|
388
|
+
file_data: file_data
|
|
389
|
+
})
|
|
390
|
+
.then(res => res?.file_info);
|
|
391
|
+
if (file_info) {
|
|
392
|
+
url = file_info;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
397
|
+
content: content,
|
|
390
398
|
media: {
|
|
391
|
-
file_info
|
|
399
|
+
file_info: url
|
|
392
400
|
},
|
|
393
|
-
msg_id: event.MessageId,
|
|
394
401
|
msg_type: 7,
|
|
395
|
-
|
|
402
|
+
...baseParams
|
|
396
403
|
});
|
|
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', {
|
|
404
|
+
return [
|
|
405
|
+
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
417
406
|
id: res.id
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
407
|
+
})
|
|
408
|
+
];
|
|
409
|
+
}
|
|
410
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
411
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
412
|
+
const params = {};
|
|
413
|
+
mdAndButtons.forEach(item => {
|
|
414
|
+
if (item.type === 'ButtonTemplate') {
|
|
415
|
+
const template_id = item?.value;
|
|
416
|
+
if (template_id) {
|
|
417
|
+
params['keyboard'] = {
|
|
418
|
+
id: template_id
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (item.type === 'BT.group') {
|
|
423
|
+
const rows = item.value;
|
|
424
|
+
const content = createButtonsData(rows);
|
|
425
|
+
params['keyboard'] = {
|
|
426
|
+
content: content
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
else if (item.type === 'Markdown') {
|
|
430
|
+
const content = createMarkdownText(item.value);
|
|
431
|
+
if (content) {
|
|
432
|
+
params['markdown'] = {
|
|
433
|
+
content: content
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
439
|
+
content: content,
|
|
429
440
|
msg_type: 2,
|
|
430
|
-
|
|
441
|
+
...params,
|
|
442
|
+
...baseParams
|
|
431
443
|
});
|
|
432
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
433
|
-
|
|
444
|
+
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
445
|
+
}
|
|
446
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
447
|
+
if (ark && ark.length > 0) {
|
|
448
|
+
const params = {};
|
|
449
|
+
ark.forEach(item => {
|
|
450
|
+
if (item.type === 'Ark.Card') {
|
|
451
|
+
const arkData = createArkCardData(item.value);
|
|
452
|
+
params['ark'] = arkData;
|
|
453
|
+
}
|
|
454
|
+
else if (item.type === 'Ark.BigCard') {
|
|
455
|
+
const arkData = createArkBigCardData(item.value);
|
|
456
|
+
params['ark'] = arkData;
|
|
457
|
+
}
|
|
458
|
+
else if (item.type === 'Ark.list') {
|
|
459
|
+
const arkData = createArkList(item.value);
|
|
460
|
+
params['ark'] = arkData;
|
|
461
|
+
}
|
|
434
462
|
});
|
|
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,
|
|
463
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
464
|
+
content: content,
|
|
467
465
|
msg_type: 3,
|
|
468
|
-
|
|
466
|
+
...params,
|
|
467
|
+
...baseParams
|
|
469
468
|
});
|
|
470
|
-
return createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id });
|
|
471
|
-
})).catch(err => [
|
|
472
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
473
|
-
]);
|
|
474
|
-
}
|
|
475
|
-
return Promise.all([]);
|
|
476
|
-
};
|
|
477
|
-
/**
|
|
478
|
-
* 频道私聊
|
|
479
|
-
* @param client
|
|
480
|
-
* @param event
|
|
481
|
-
* @param val
|
|
482
|
-
* @returns
|
|
483
|
-
*/
|
|
484
|
-
const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
485
|
-
const content = val
|
|
486
|
-
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
487
|
-
.map(item => {
|
|
488
|
-
if (item.type == 'Link') {
|
|
489
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
490
|
-
}
|
|
491
|
-
if (item.type == 'Text') {
|
|
492
|
-
return item.value;
|
|
469
|
+
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
493
470
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const res = await client.dmsMessage(event.OpenId, {
|
|
500
|
-
content: item,
|
|
501
|
-
msg_id: event.MessageId
|
|
471
|
+
if (content) {
|
|
472
|
+
const res = await client.usersOpenMessages(event.UserId, {
|
|
473
|
+
content: content,
|
|
474
|
+
msg_type: 0,
|
|
475
|
+
...baseParams
|
|
502
476
|
});
|
|
503
|
-
return
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
]);
|
|
507
|
-
}
|
|
508
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
509
|
-
if (images && images.length > 0) {
|
|
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'
|
|
477
|
+
return [
|
|
478
|
+
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
479
|
+
id: res.id
|
|
516
480
|
})
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
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
|
-
]);
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
catch (err) {
|
|
485
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
533
486
|
}
|
|
534
|
-
return
|
|
487
|
+
return [];
|
|
535
488
|
};
|
|
536
|
-
const
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
if (item.options?.belong == 'user') {
|
|
551
|
-
return `<@!${item.value}>`;
|
|
489
|
+
const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
490
|
+
const baseParams = {};
|
|
491
|
+
if (event.tag === 'INTERACTION_CREATE_GUILD') {
|
|
492
|
+
baseParams['event_id'] = event.MessageId;
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
baseParams['msg_id'] = event.MessageId;
|
|
496
|
+
}
|
|
497
|
+
try {
|
|
498
|
+
const content = val
|
|
499
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
500
|
+
.map(item => {
|
|
501
|
+
if (item.type === 'Link') {
|
|
502
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
552
503
|
}
|
|
553
|
-
|
|
554
|
-
return
|
|
504
|
+
if (item.type === 'Text') {
|
|
505
|
+
return item.value;
|
|
555
506
|
}
|
|
556
507
|
return '';
|
|
508
|
+
})
|
|
509
|
+
.join('');
|
|
510
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
511
|
+
if (images && images.length > 0) {
|
|
512
|
+
let imageBuffer = null;
|
|
513
|
+
for (let i = 0; i < images.length; i++) {
|
|
514
|
+
if (imageBuffer) {
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
const item = images[i];
|
|
518
|
+
if (item.value === 'ImageURL') {
|
|
519
|
+
const data = await axios
|
|
520
|
+
.get(item.value, {
|
|
521
|
+
responseType: 'arraybuffer'
|
|
522
|
+
})
|
|
523
|
+
.then(res => res?.data);
|
|
524
|
+
imageBuffer = data;
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const file_data = item.type === 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
528
|
+
imageBuffer = file_data;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
532
|
+
content: content,
|
|
533
|
+
...baseParams
|
|
534
|
+
}, imageBuffer);
|
|
535
|
+
return [createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id })];
|
|
557
536
|
}
|
|
558
|
-
|
|
559
|
-
|
|
537
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
538
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
539
|
+
const params = {};
|
|
540
|
+
mdAndButtons.forEach(item => {
|
|
541
|
+
if (item.type === 'ButtonTemplate') {
|
|
542
|
+
const template_id = item?.value;
|
|
543
|
+
if (template_id) {
|
|
544
|
+
params['keyboard'] = {
|
|
545
|
+
id: template_id
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
else if (item.type === 'BT.group') {
|
|
550
|
+
const rows = item.value;
|
|
551
|
+
const content = createButtonsData(rows);
|
|
552
|
+
params['keyboard'] = {
|
|
553
|
+
content: content
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
else if (item.type === 'Markdown') {
|
|
557
|
+
const content = createMarkdownText(item.value);
|
|
558
|
+
if (content) {
|
|
559
|
+
params['markdown'] = {
|
|
560
|
+
content: content
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
566
|
+
content: '',
|
|
567
|
+
...params,
|
|
568
|
+
...baseParams
|
|
569
|
+
});
|
|
570
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
560
571
|
}
|
|
561
|
-
|
|
562
|
-
.
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
572
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
573
|
+
if (ark && ark.length > 0) {
|
|
574
|
+
const params = {};
|
|
575
|
+
ark.forEach(item => {
|
|
576
|
+
if (item.type === 'Ark.Card') {
|
|
577
|
+
const arkData = createArkCardData(item.value);
|
|
578
|
+
params['ark'] = arkData;
|
|
579
|
+
}
|
|
580
|
+
else if (item.type === 'Ark.BigCard') {
|
|
581
|
+
const arkData = createArkBigCardData(item.value);
|
|
582
|
+
params['ark'] = arkData;
|
|
583
|
+
}
|
|
584
|
+
else if (item.type === 'Ark.list') {
|
|
585
|
+
const arkData = createArkList(item.value);
|
|
586
|
+
params['ark'] = arkData;
|
|
587
|
+
}
|
|
568
588
|
});
|
|
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)
|
|
589
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
590
|
+
content: content,
|
|
591
|
+
...params,
|
|
592
|
+
...baseParams
|
|
594
593
|
});
|
|
595
|
-
return createResult(ResultCode.Ok, 'client.
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
594
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
595
|
+
}
|
|
596
|
+
if (content) {
|
|
597
|
+
const res = await client.dmsMessages(event.UserId, {
|
|
598
|
+
content: content,
|
|
599
|
+
...baseParams
|
|
600
|
+
});
|
|
601
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id })];
|
|
602
|
+
}
|
|
603
|
+
return [];
|
|
604
|
+
}
|
|
605
|
+
catch (err) {
|
|
606
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
599
607
|
}
|
|
600
|
-
return Promise.all([]);
|
|
601
608
|
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (item.value == 'everyone' ||
|
|
617
|
-
item.value == 'all' ||
|
|
618
|
-
item.value == '' ||
|
|
619
|
-
typeof item.value != 'string') {
|
|
620
|
-
return `@everyone`;
|
|
609
|
+
const MESSAGE_CREATE = async (client, event, val) => {
|
|
610
|
+
const baseParams = {};
|
|
611
|
+
if (event.tag === 'INTERACTION_CREATE_GUILD') {
|
|
612
|
+
baseParams['event_id'] = event.MessageId;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
baseParams['msg_id'] = event.MessageId;
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
const content = val
|
|
619
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
620
|
+
.map(item => {
|
|
621
|
+
if (item.type === 'Link') {
|
|
622
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
621
623
|
}
|
|
622
|
-
if (item.
|
|
623
|
-
|
|
624
|
+
if (item.type === 'Mention') {
|
|
625
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
626
|
+
return '@everyone';
|
|
627
|
+
}
|
|
628
|
+
if (item.options?.belong === 'user') {
|
|
629
|
+
return `<@!${item.value}>`;
|
|
630
|
+
}
|
|
631
|
+
else if (item.options?.belong === 'channel') {
|
|
632
|
+
return `<#${item.value}>`;
|
|
633
|
+
}
|
|
634
|
+
return '';
|
|
624
635
|
}
|
|
625
|
-
else if (item.
|
|
626
|
-
return
|
|
636
|
+
else if (item.type === 'Text') {
|
|
637
|
+
return item.value;
|
|
627
638
|
}
|
|
628
|
-
|
|
639
|
+
})
|
|
640
|
+
.join('');
|
|
641
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
642
|
+
if (images && images.length > 0) {
|
|
643
|
+
let imageBuffer = null;
|
|
644
|
+
for (let i = 0; i < images.length; i++) {
|
|
645
|
+
if (imageBuffer) {
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
const item = images[i];
|
|
649
|
+
if (item.value === 'ImageURL') {
|
|
650
|
+
const data = await axios
|
|
651
|
+
.get(item.value, {
|
|
652
|
+
responseType: 'arraybuffer'
|
|
653
|
+
})
|
|
654
|
+
.then(res => res?.data);
|
|
655
|
+
imageBuffer = data;
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
const file_data = item.type === 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
659
|
+
imageBuffer = file_data;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
663
|
+
content: content,
|
|
664
|
+
...baseParams
|
|
665
|
+
}, imageBuffer);
|
|
666
|
+
return [createResult(ResultCode.Ok, 'client.postImage', { id: res?.id })];
|
|
629
667
|
}
|
|
630
|
-
|
|
631
|
-
|
|
668
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
669
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
670
|
+
const params = {};
|
|
671
|
+
mdAndButtons.forEach(item => {
|
|
672
|
+
if (item.type === 'ButtonTemplate') {
|
|
673
|
+
const template_id = item?.value;
|
|
674
|
+
if (template_id) {
|
|
675
|
+
params['keyboard'] = {
|
|
676
|
+
id: template_id
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else if (item.type === 'BT.group') {
|
|
681
|
+
const rows = item.value;
|
|
682
|
+
const content = createButtonsData(rows);
|
|
683
|
+
params['keyboard'] = {
|
|
684
|
+
content: content
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
else if (item.type === 'Markdown') {
|
|
688
|
+
const content = createMarkdownText(item.value);
|
|
689
|
+
if (content) {
|
|
690
|
+
params['markdown'] = {
|
|
691
|
+
content: content
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
697
|
+
content: '',
|
|
698
|
+
...params,
|
|
699
|
+
...baseParams
|
|
700
|
+
});
|
|
701
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
632
702
|
}
|
|
633
|
-
|
|
634
|
-
.
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
703
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
704
|
+
if (ark && ark.length > 0) {
|
|
705
|
+
const params = {};
|
|
706
|
+
ark.forEach(item => {
|
|
707
|
+
if (item.type === 'Ark.Card') {
|
|
708
|
+
const arkData = createArkCardData(item.value);
|
|
709
|
+
params['ark'] = arkData;
|
|
710
|
+
}
|
|
711
|
+
else if (item.type === 'Ark.BigCard') {
|
|
712
|
+
const arkData = createArkBigCardData(item.value);
|
|
713
|
+
params['ark'] = arkData;
|
|
714
|
+
}
|
|
715
|
+
else if (item.type === 'Ark.list') {
|
|
716
|
+
const arkData = createArkList(item.value);
|
|
717
|
+
params['ark'] = arkData;
|
|
718
|
+
}
|
|
640
719
|
});
|
|
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, {
|
|
720
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
721
|
+
content: content,
|
|
664
722
|
msg_id: event.MessageId,
|
|
665
|
-
|
|
723
|
+
...params
|
|
666
724
|
});
|
|
667
|
-
return createResult(ResultCode.Ok, 'client.
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
725
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
726
|
+
}
|
|
727
|
+
if (content) {
|
|
728
|
+
const res = await client.channelsMessages(event.ChannelId, {
|
|
729
|
+
content: content,
|
|
730
|
+
...baseParams
|
|
731
|
+
});
|
|
732
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id })];
|
|
733
|
+
}
|
|
734
|
+
return [];
|
|
735
|
+
}
|
|
736
|
+
catch (err) {
|
|
737
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
671
738
|
}
|
|
672
|
-
|
|
739
|
+
};
|
|
740
|
+
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
741
|
+
return MESSAGE_CREATE(client, event, val);
|
|
673
742
|
};
|
|
674
743
|
|
|
675
744
|
export { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE };
|