@alemonjs/onebot 0.2.3 → 0.2.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/lib/index.js +38 -9
- 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,12 @@
|
|
|
1
1
|
import { getConfigValue, useUserHashKey, onProcessor, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { OneBotClient } from './sdk/wss.js';
|
|
3
3
|
import { createServer } from './server/index.js';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
4
5
|
|
|
6
|
+
const ImageURLToBuffer = async (url) => {
|
|
7
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
8
|
+
return Buffer.from(arrayBuffer);
|
|
9
|
+
};
|
|
5
10
|
const client = new Proxy({}, {
|
|
6
11
|
get: (_, prop) => {
|
|
7
12
|
if (prop in global.client) {
|
|
@@ -82,7 +87,7 @@ var index = definePlatform(() => {
|
|
|
82
87
|
UserAvatar: UserAvatar,
|
|
83
88
|
// message
|
|
84
89
|
MessageId: String(event.message_id),
|
|
85
|
-
MessageText: msg,
|
|
90
|
+
MessageText: msg.trim(),
|
|
86
91
|
// 用户openId
|
|
87
92
|
OpenId: String(event.user_id),
|
|
88
93
|
// 创建时间
|
|
@@ -143,7 +148,7 @@ var index = definePlatform(() => {
|
|
|
143
148
|
UserAvatar: UserAvatar,
|
|
144
149
|
// message
|
|
145
150
|
MessageId: String(event.message_id),
|
|
146
|
-
MessageText: msg,
|
|
151
|
+
MessageText: msg.trim(),
|
|
147
152
|
// 用户openId
|
|
148
153
|
OpenId: String(event.user_id),
|
|
149
154
|
// 创建时间
|
|
@@ -166,7 +171,7 @@ var index = definePlatform(() => {
|
|
|
166
171
|
if (val.length < 0)
|
|
167
172
|
return Promise.all([]);
|
|
168
173
|
const content = val
|
|
169
|
-
.filter(item => item.type == '
|
|
174
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
170
175
|
.map(item => item.value)
|
|
171
176
|
.join('');
|
|
172
177
|
if (content) {
|
|
@@ -187,16 +192,28 @@ var index = definePlatform(() => {
|
|
|
187
192
|
});
|
|
188
193
|
}));
|
|
189
194
|
}
|
|
190
|
-
const images = val.filter(item => item.type == 'Image'
|
|
195
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
191
196
|
if (images) {
|
|
192
|
-
return Promise.all(images.map(item => {
|
|
197
|
+
return Promise.all(images.map(async (item) => {
|
|
198
|
+
let data = null;
|
|
199
|
+
if (item.type === 'ImageFile') {
|
|
200
|
+
const db = readFileSync(item.value);
|
|
201
|
+
data = db;
|
|
202
|
+
}
|
|
203
|
+
else if (item.type === 'ImageURL') {
|
|
204
|
+
const db = await ImageURLToBuffer(item.value);
|
|
205
|
+
data = db;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
data = item.value;
|
|
209
|
+
}
|
|
193
210
|
client.sendGroupMessage({
|
|
194
211
|
group_id: event.ChannelId,
|
|
195
212
|
message: [
|
|
196
213
|
{
|
|
197
214
|
type: 'image',
|
|
198
215
|
data: {
|
|
199
|
-
file: `base64://${
|
|
216
|
+
file: `base64://${data.toString('base64')}`
|
|
200
217
|
}
|
|
201
218
|
}
|
|
202
219
|
]
|
|
@@ -241,16 +258,28 @@ var index = definePlatform(() => {
|
|
|
241
258
|
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
242
259
|
]);
|
|
243
260
|
}
|
|
244
|
-
const images = val.filter(item => item.type == 'Image'
|
|
261
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
245
262
|
if (images) {
|
|
246
|
-
return Promise.all(images.map(item => {
|
|
263
|
+
return Promise.all(images.map(async (item) => {
|
|
264
|
+
let data = null;
|
|
265
|
+
if (item.type === 'ImageFile') {
|
|
266
|
+
const db = readFileSync(item.value);
|
|
267
|
+
data = db;
|
|
268
|
+
}
|
|
269
|
+
else if (item.type === 'ImageURL') {
|
|
270
|
+
const db = await ImageURLToBuffer(item.value);
|
|
271
|
+
data = db;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
data = item.value;
|
|
275
|
+
}
|
|
247
276
|
client.sendGroupMessage({
|
|
248
277
|
group_id: event.ChannelId,
|
|
249
278
|
message: [
|
|
250
279
|
{
|
|
251
280
|
type: 'image',
|
|
252
281
|
data: {
|
|
253
|
-
file: `base64://${
|
|
282
|
+
file: `base64://${data.toString('base64')}`
|
|
254
283
|
}
|
|
255
284
|
}
|
|
256
285
|
]
|
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, () => {
|