@alemonjs/qq-bot 2.1.0-alpha.2 → 2.1.0-alpha.4
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/dist/assets/index.css +1255 -1
- package/dist/assets/index.js +11364 -5
- package/dist/index.html +1 -1
- package/lib/register.js +63 -55
- package/lib/sends.js +10 -12
- package/package.json +1 -1
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>AlemonJS</title>
|
|
8
8
|
<script type="module" crossorigin src="/assets/index.js"></script>
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/assets/index.css"
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index.css" />
|
|
10
10
|
</head>
|
|
11
11
|
|
|
12
12
|
<body>
|
package/lib/register.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getConfigValue, cbpPlatform, useUserHashKey } from 'alemonjs';
|
|
1
|
+
import { getConfigValue, cbpPlatform, useUserHashKey, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { GROUP_AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, AT_MESSAGE_CREATE, MESSAGE_CREATE } from './sends.js';
|
|
3
3
|
|
|
4
4
|
const platform = 'qq-bot';
|
|
@@ -238,56 +238,64 @@ const register = (client) => {
|
|
|
238
238
|
cbp.send(e);
|
|
239
239
|
});
|
|
240
240
|
client.on('ERROR', console.error);
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
241
|
+
const api = {
|
|
242
|
+
active: {
|
|
243
|
+
send: {
|
|
244
|
+
channel: async (channel_id, val) => {
|
|
245
|
+
if (!channel_id || typeof channel_id !== 'string') {
|
|
246
|
+
throw new Error('Invalid channel_id: channel_id must be a string');
|
|
247
|
+
}
|
|
248
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
249
|
+
ChannelId: channel_id
|
|
250
|
+
}, val);
|
|
251
|
+
},
|
|
252
|
+
user: async (user_id, val) => {
|
|
253
|
+
if (!user_id || typeof user_id !== 'string') {
|
|
254
|
+
throw new Error('Invalid user_id: user_id must be a string');
|
|
255
|
+
}
|
|
256
|
+
return await C2C_MESSAGE_CREATE(client, {
|
|
257
|
+
OpenId: user_id
|
|
258
|
+
}, val);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
use: {
|
|
263
|
+
send: async (event, val) => {
|
|
264
|
+
if (val.length < 0)
|
|
265
|
+
Promise.all([]);
|
|
266
|
+
// 打 tag
|
|
267
|
+
const tag = event.tag;
|
|
268
|
+
// 群at
|
|
269
|
+
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
270
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
271
|
+
}
|
|
272
|
+
// 私聊
|
|
273
|
+
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
274
|
+
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
275
|
+
}
|
|
276
|
+
// 频道私聊
|
|
277
|
+
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
278
|
+
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
279
|
+
}
|
|
280
|
+
// 频道at
|
|
281
|
+
if (tag == 'AT_MESSAGE_CREATE') {
|
|
282
|
+
return await AT_MESSAGE_CREATE(client, event, val);
|
|
283
|
+
}
|
|
284
|
+
// 频道消息
|
|
285
|
+
if (tag == 'MESSAGE_CREATE') {
|
|
286
|
+
return await MESSAGE_CREATE(client, event, val);
|
|
287
|
+
}
|
|
288
|
+
return Promise.all([]);
|
|
289
|
+
},
|
|
290
|
+
mention: async (event) => {
|
|
291
|
+
event.value;
|
|
292
|
+
event.tag;
|
|
293
|
+
// const event = e.value
|
|
294
|
+
const Metions = [];
|
|
295
|
+
// group
|
|
296
|
+
return Metions;
|
|
297
|
+
}
|
|
287
298
|
}
|
|
288
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
289
|
-
OpenId: user_id
|
|
290
|
-
}, data);
|
|
291
299
|
};
|
|
292
300
|
// 处理行为
|
|
293
301
|
cbp.onactions(async (data, consume) => {
|
|
@@ -296,28 +304,28 @@ const register = (client) => {
|
|
|
296
304
|
const event = data.payload.event;
|
|
297
305
|
const paramFormat = data.payload.params.format;
|
|
298
306
|
// 消费
|
|
299
|
-
const res = await
|
|
307
|
+
const res = await api.use.send(event, paramFormat);
|
|
300
308
|
consume(res);
|
|
301
309
|
}
|
|
302
310
|
else if (data.action === 'mention.get') {
|
|
303
311
|
const event = data.payload.event;
|
|
304
312
|
// 获取提及
|
|
305
|
-
const metions = await
|
|
313
|
+
const metions = await api.use.mention(event);
|
|
306
314
|
// 消费
|
|
307
|
-
consume(metions);
|
|
315
|
+
consume([createResult(ResultCode.Ok, '请求完成', metions)]);
|
|
308
316
|
}
|
|
309
317
|
else if (data.action === 'message.send.channel') {
|
|
310
318
|
// 主动发送消息到频道
|
|
311
319
|
const channel_id = data.payload.ChannelId;
|
|
312
320
|
const paramFormat = data.payload.params.format;
|
|
313
|
-
const res = await
|
|
321
|
+
const res = await api.active.send.channel(channel_id, paramFormat);
|
|
314
322
|
consume(res);
|
|
315
323
|
}
|
|
316
324
|
else if (data.action === 'message.send.user') {
|
|
317
325
|
// 主动发送消息到用户
|
|
318
326
|
const user_id = data.payload.UserId;
|
|
319
327
|
const paramFormat = data.payload.params.format;
|
|
320
|
-
const res = await
|
|
328
|
+
const res = await api.active.send.user(user_id, paramFormat);
|
|
321
329
|
consume(res);
|
|
322
330
|
}
|
|
323
331
|
});
|
package/lib/sends.js
CHANGED
|
@@ -212,9 +212,8 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
try {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
: item.value;
|
|
215
|
+
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
216
|
+
const file_data = item.type == 'ImageFile' ? getFileBase64() : item.value;
|
|
218
217
|
const file_info = await client
|
|
219
218
|
.postRichMediaByGroup(event.GuildId, {
|
|
220
219
|
file_type: 1,
|
|
@@ -374,9 +373,8 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
374
373
|
id: res.id
|
|
375
374
|
});
|
|
376
375
|
}
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
: item.value;
|
|
376
|
+
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
377
|
+
const file_data = item.type == 'ImageFile' ? getFileBase64() : item.value;
|
|
380
378
|
const file_info = await client
|
|
381
379
|
.postRichMediaByUsers(event.OpenId, {
|
|
382
380
|
file_type: 1,
|
|
@@ -521,10 +519,10 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
521
519
|
});
|
|
522
520
|
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
523
521
|
}
|
|
524
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
522
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
525
523
|
const res = await client.postDirectImage(event.OpenId, {
|
|
526
524
|
msg_id: event.MessageId,
|
|
527
|
-
image:
|
|
525
|
+
image: file_data
|
|
528
526
|
});
|
|
529
527
|
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
530
528
|
})).catch(err => [
|
|
@@ -587,10 +585,10 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
587
585
|
});
|
|
588
586
|
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
589
587
|
}
|
|
590
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
588
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
591
589
|
const res = await client.postImage(event.ChannelId, {
|
|
592
590
|
msg_id: event.MessageId,
|
|
593
|
-
image:
|
|
591
|
+
image: file_data
|
|
594
592
|
});
|
|
595
593
|
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
596
594
|
})).catch(err => [
|
|
@@ -659,10 +657,10 @@ const MESSAGE_CREATE = (client, event, val) => {
|
|
|
659
657
|
});
|
|
660
658
|
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
661
659
|
}
|
|
662
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
660
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
663
661
|
const res = await client.postImage(event.ChannelId, {
|
|
664
662
|
msg_id: event.MessageId,
|
|
665
|
-
image:
|
|
663
|
+
image: file_data
|
|
666
664
|
});
|
|
667
665
|
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
668
666
|
})).catch(err => [
|