@alemonjs/onebot 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +38 -11
- package/lib/sdk/wss.js +0 -3
- package/lib/server/index.js +32 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { getConfigValue, useUserHashKey, onProcessor, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { OneBotClient } from './sdk/wss.js';
|
|
3
|
-
import {
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
4
|
|
|
5
|
+
const ImageURLToBuffer = async (url) => {
|
|
6
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
7
|
+
return Buffer.from(arrayBuffer);
|
|
8
|
+
};
|
|
5
9
|
const client = new Proxy({}, {
|
|
6
10
|
get: (_, prop) => {
|
|
7
11
|
if (prop in global.client) {
|
|
@@ -82,7 +86,7 @@ var index = definePlatform(() => {
|
|
|
82
86
|
UserAvatar: UserAvatar,
|
|
83
87
|
// message
|
|
84
88
|
MessageId: String(event.message_id),
|
|
85
|
-
MessageText: msg,
|
|
89
|
+
MessageText: msg.trim(),
|
|
86
90
|
// 用户openId
|
|
87
91
|
OpenId: String(event.user_id),
|
|
88
92
|
// 创建时间
|
|
@@ -143,7 +147,7 @@ var index = definePlatform(() => {
|
|
|
143
147
|
UserAvatar: UserAvatar,
|
|
144
148
|
// message
|
|
145
149
|
MessageId: String(event.message_id),
|
|
146
|
-
MessageText: msg,
|
|
150
|
+
MessageText: msg.trim(),
|
|
147
151
|
// 用户openId
|
|
148
152
|
OpenId: String(event.user_id),
|
|
149
153
|
// 创建时间
|
|
@@ -161,12 +165,11 @@ var index = definePlatform(() => {
|
|
|
161
165
|
console.error('ERROR', event);
|
|
162
166
|
});
|
|
163
167
|
global.client = client;
|
|
164
|
-
createServer(client);
|
|
165
168
|
const sendGroup = async (event, val) => {
|
|
166
169
|
if (val.length < 0)
|
|
167
170
|
return Promise.all([]);
|
|
168
171
|
const content = val
|
|
169
|
-
.filter(item => item.type == '
|
|
172
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
170
173
|
.map(item => item.value)
|
|
171
174
|
.join('');
|
|
172
175
|
if (content) {
|
|
@@ -187,16 +190,28 @@ var index = definePlatform(() => {
|
|
|
187
190
|
});
|
|
188
191
|
}));
|
|
189
192
|
}
|
|
190
|
-
const images = val.filter(item => item.type == 'Image'
|
|
193
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
191
194
|
if (images) {
|
|
192
|
-
return Promise.all(images.map(item => {
|
|
195
|
+
return Promise.all(images.map(async (item) => {
|
|
196
|
+
let data = null;
|
|
197
|
+
if (item.type === 'ImageFile') {
|
|
198
|
+
const db = readFileSync(item.value);
|
|
199
|
+
data = db;
|
|
200
|
+
}
|
|
201
|
+
else if (item.type === 'ImageURL') {
|
|
202
|
+
const db = await ImageURLToBuffer(item.value);
|
|
203
|
+
data = db;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
data = item.value;
|
|
207
|
+
}
|
|
193
208
|
client.sendGroupMessage({
|
|
194
209
|
group_id: event.ChannelId,
|
|
195
210
|
message: [
|
|
196
211
|
{
|
|
197
212
|
type: 'image',
|
|
198
213
|
data: {
|
|
199
|
-
file: `base64://${
|
|
214
|
+
file: `base64://${data.toString('base64')}`
|
|
200
215
|
}
|
|
201
216
|
}
|
|
202
217
|
]
|
|
@@ -241,16 +256,28 @@ var index = definePlatform(() => {
|
|
|
241
256
|
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
242
257
|
]);
|
|
243
258
|
}
|
|
244
|
-
const images = val.filter(item => item.type == 'Image'
|
|
259
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
245
260
|
if (images) {
|
|
246
|
-
return Promise.all(images.map(item => {
|
|
261
|
+
return Promise.all(images.map(async (item) => {
|
|
262
|
+
let data = null;
|
|
263
|
+
if (item.type === 'ImageFile') {
|
|
264
|
+
const db = readFileSync(item.value);
|
|
265
|
+
data = db;
|
|
266
|
+
}
|
|
267
|
+
else if (item.type === 'ImageURL') {
|
|
268
|
+
const db = await ImageURLToBuffer(item.value);
|
|
269
|
+
data = db;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
data = item.value;
|
|
273
|
+
}
|
|
247
274
|
client.sendGroupMessage({
|
|
248
275
|
group_id: event.ChannelId,
|
|
249
276
|
message: [
|
|
250
277
|
{
|
|
251
278
|
type: 'image',
|
|
252
279
|
data: {
|
|
253
|
-
file: `base64://${
|
|
280
|
+
file: `base64://${data.toString('base64')}`
|
|
254
281
|
}
|
|
255
282
|
}
|
|
256
283
|
]
|
package/lib/sdk/wss.js
CHANGED
package/lib/server/index.js
CHANGED
|
@@ -31,6 +31,38 @@ const createServer = (client) => {
|
|
|
31
31
|
client.getGroupMemberList({ group_id: Number(group_id) });
|
|
32
32
|
ctx.body = 'Hello, World!';
|
|
33
33
|
});
|
|
34
|
+
// 同意加群
|
|
35
|
+
router.get('/set_group_add_request', async (ctx) => {
|
|
36
|
+
const flag = ctx.query.flag;
|
|
37
|
+
const sub_type = ctx.query.sub_type;
|
|
38
|
+
const approve = ctx.query.approve;
|
|
39
|
+
if (!flag || !sub_type || !approve) {
|
|
40
|
+
ctx.status = 400;
|
|
41
|
+
ctx.body = 'flag, sub_type and approve are required';
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
client.setGroupAddRequest({
|
|
45
|
+
flag: String(flag),
|
|
46
|
+
sub_type: String(sub_type),
|
|
47
|
+
approve: Boolean(approve),
|
|
48
|
+
});
|
|
49
|
+
ctx.body = 'Hello, World!';
|
|
50
|
+
});
|
|
51
|
+
// 同意加好友
|
|
52
|
+
router.get('/set_friend_add_request', async (ctx) => {
|
|
53
|
+
const flag = ctx.query.flag;
|
|
54
|
+
const approve = ctx.query.approve;
|
|
55
|
+
if (!flag || !approve) {
|
|
56
|
+
ctx.status = 400;
|
|
57
|
+
ctx.body = 'flag and approve are required';
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
client.setFriendAddRequest({
|
|
61
|
+
flag: String(flag),
|
|
62
|
+
approve: Boolean(approve),
|
|
63
|
+
});
|
|
64
|
+
ctx.body = 'Hello, World!';
|
|
65
|
+
});
|
|
34
66
|
app.use(router.routes());
|
|
35
67
|
app.use(router.allowedMethods());
|
|
36
68
|
app.listen(port, () => {
|