@alemonjs/onebot 2.1.0-alpha.16 → 2.1.0-alpha.17
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 +31 -16
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -128,7 +128,15 @@ const main = () => {
|
|
|
128
128
|
return empty;
|
|
129
129
|
}
|
|
130
130
|
else if (item.type === 'Image') {
|
|
131
|
-
if (
|
|
131
|
+
if (Buffer.isBuffer(item.value)) {
|
|
132
|
+
return {
|
|
133
|
+
type: 'image',
|
|
134
|
+
data: {
|
|
135
|
+
file: `base64://${item.value.toString('base64')}`
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (typeof item.value === 'string' && (item.value.startsWith('http://') || item.value.startsWith('https://'))) {
|
|
132
140
|
const res = await getBufferByURL(item.value);
|
|
133
141
|
return {
|
|
134
142
|
type: 'image',
|
|
@@ -156,7 +164,7 @@ const main = () => {
|
|
|
156
164
|
};
|
|
157
165
|
}
|
|
158
166
|
else if (item.value.startsWith('file://')) {
|
|
159
|
-
const db = readFileSync(item.value);
|
|
167
|
+
const db = readFileSync(item.value.slice(7));
|
|
160
168
|
return {
|
|
161
169
|
type: 'image',
|
|
162
170
|
data: {
|
|
@@ -194,7 +202,7 @@ const main = () => {
|
|
|
194
202
|
return message;
|
|
195
203
|
};
|
|
196
204
|
const sendGroup = async (ChannelId, val) => {
|
|
197
|
-
if (val.length
|
|
205
|
+
if (!val || val.length <= 0) {
|
|
198
206
|
return [];
|
|
199
207
|
}
|
|
200
208
|
try {
|
|
@@ -210,7 +218,7 @@ const main = () => {
|
|
|
210
218
|
}
|
|
211
219
|
};
|
|
212
220
|
const sendPrivate = async (UserId, val) => {
|
|
213
|
-
if (val.length
|
|
221
|
+
if (!val || val.length <= 0) {
|
|
214
222
|
return [];
|
|
215
223
|
}
|
|
216
224
|
try {
|
|
@@ -238,8 +246,8 @@ const main = () => {
|
|
|
238
246
|
},
|
|
239
247
|
use: {
|
|
240
248
|
send: (event, val) => {
|
|
241
|
-
if (val.length
|
|
242
|
-
return
|
|
249
|
+
if (!val || val.length <= 0) {
|
|
250
|
+
return [];
|
|
243
251
|
}
|
|
244
252
|
if (event['name'] === 'private.message.create') {
|
|
245
253
|
const UserId = Number(event.UserId);
|
|
@@ -356,21 +364,23 @@ const main = () => {
|
|
|
356
364
|
return consume([res]);
|
|
357
365
|
}
|
|
358
366
|
case 'message.forward.channel': {
|
|
359
|
-
const
|
|
360
|
-
.channel(data.payload.ChannelId, data.payload.params.map(i => ({
|
|
367
|
+
const params = await Promise.all(data.payload.params.map(async (i) => ({
|
|
361
368
|
...i,
|
|
362
|
-
content: DataToMessage(i.content)
|
|
363
|
-
})))
|
|
369
|
+
content: await DataToMessage(i.content)
|
|
370
|
+
})));
|
|
371
|
+
const res = await api.use.forward
|
|
372
|
+
.channel(data.payload.ChannelId, params)
|
|
364
373
|
.then(res => createResult(ResultCode.Ok, data.action, res))
|
|
365
374
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
366
375
|
return consume([res]);
|
|
367
376
|
}
|
|
368
377
|
case 'message.forward.user': {
|
|
369
|
-
const
|
|
370
|
-
.user(data.payload.UserId, data.payload.params.map(i => ({
|
|
378
|
+
const params = await Promise.all(data.payload.params.map(async (i) => ({
|
|
371
379
|
...i,
|
|
372
|
-
content: DataToMessage(i.content)
|
|
373
|
-
})))
|
|
380
|
+
content: await DataToMessage(i.content)
|
|
381
|
+
})));
|
|
382
|
+
const res = await api.use.forward
|
|
383
|
+
.user(data.payload.UserId, params)
|
|
374
384
|
.then(res => createResult(ResultCode.Ok, data.action, res))
|
|
375
385
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
376
386
|
return consume([res]);
|
|
@@ -385,8 +395,13 @@ const main = () => {
|
|
|
385
395
|
const key = data.payload?.key;
|
|
386
396
|
if (client[key]) {
|
|
387
397
|
const params = data.payload.params;
|
|
388
|
-
|
|
389
|
-
|
|
398
|
+
try {
|
|
399
|
+
const res = await client[key](...params);
|
|
400
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
404
|
+
}
|
|
390
405
|
}
|
|
391
406
|
else {
|
|
392
407
|
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|