@alemonjs/onebot 2.1.0-alpha.14 → 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/db.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  export declare const BotMe: {
2
2
  id: string;
3
- name: string;
4
- avatar: string;
5
3
  };
package/lib/db.js CHANGED
@@ -1,7 +1,5 @@
1
1
  const BotMe = {
2
- id: '',
3
- name: '',
4
- avatar: ''
2
+ id: ''
5
3
  };
6
4
 
7
5
  export { BotMe };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { platform } from './config';
2
2
  export { OneBotAPI as API } from './sdk/api';
3
3
  export * from './hook';
4
- declare const main: () => void;
5
- export default main;
4
+ declare const _default: () => any;
5
+ export default _default;
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
1
+ import { definePlatform, cbpPlatform, createResult, ResultCode } from 'alemonjs';
2
2
  import { getBufferByURL } from 'alemonjs/utils';
3
3
  import { readFileSync } from 'fs';
4
4
  import { getOneBotConfig, getMaster, platform } from './config.js';
@@ -128,10 +128,54 @@ const main = () => {
128
128
  return empty;
129
129
  }
130
130
  else if (item.type === 'Image') {
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://'))) {
140
+ const res = await getBufferByURL(item.value);
141
+ return {
142
+ type: 'image',
143
+ data: {
144
+ file: `base64://${res.toString('base64')}`
145
+ }
146
+ };
147
+ }
148
+ else if (item.value.startsWith('base64://')) {
149
+ const base64Str = item.value.replace('base64://', '');
150
+ return {
151
+ type: 'image',
152
+ data: {
153
+ file: `base64://${base64Str}`
154
+ }
155
+ };
156
+ }
157
+ else if (item.value.startsWith('buffer://')) {
158
+ const base64Str = item.value.replace('buffer://', '');
159
+ return {
160
+ type: 'image',
161
+ data: {
162
+ file: `base64://${base64Str}`
163
+ }
164
+ };
165
+ }
166
+ else if (item.value.startsWith('file://')) {
167
+ const db = readFileSync(item.value.slice(7));
168
+ return {
169
+ type: 'image',
170
+ data: {
171
+ file: `base64://${db.toString('base64')}`
172
+ }
173
+ };
174
+ }
131
175
  return {
132
176
  type: 'image',
133
177
  data: {
134
- file: `base64://${item.value}`
178
+ file: `base64://${item.value.toString('base64')}`
135
179
  }
136
180
  };
137
181
  }
@@ -158,7 +202,7 @@ const main = () => {
158
202
  return message;
159
203
  };
160
204
  const sendGroup = async (ChannelId, val) => {
161
- if (val.length < 0) {
205
+ if (!val || val.length <= 0) {
162
206
  return [];
163
207
  }
164
208
  try {
@@ -174,7 +218,7 @@ const main = () => {
174
218
  }
175
219
  };
176
220
  const sendPrivate = async (UserId, val) => {
177
- if (val.length < 0) {
221
+ if (!val || val.length <= 0) {
178
222
  return [];
179
223
  }
180
224
  try {
@@ -202,8 +246,8 @@ const main = () => {
202
246
  },
203
247
  use: {
204
248
  send: (event, val) => {
205
- if (val.length < 0) {
206
- return Promise.all([]);
249
+ if (!val || val.length <= 0) {
250
+ return [];
207
251
  }
208
252
  if (event['name'] === 'private.message.create') {
209
253
  const UserId = Number(event.UserId);
@@ -320,21 +364,23 @@ const main = () => {
320
364
  return consume([res]);
321
365
  }
322
366
  case 'message.forward.channel': {
323
- const res = await api.use.forward
324
- .channel(data.payload.ChannelId, data.payload.params.map(i => ({
367
+ const params = await Promise.all(data.payload.params.map(async (i) => ({
325
368
  ...i,
326
- content: DataToMessage(i.content)
327
- })))
369
+ content: await DataToMessage(i.content)
370
+ })));
371
+ const res = await api.use.forward
372
+ .channel(data.payload.ChannelId, params)
328
373
  .then(res => createResult(ResultCode.Ok, data.action, res))
329
374
  .catch(err => createResult(ResultCode.Fail, data.action, err));
330
375
  return consume([res]);
331
376
  }
332
377
  case 'message.forward.user': {
333
- const res = await api.use.forward
334
- .user(data.payload.UserId, data.payload.params.map(i => ({
378
+ const params = await Promise.all(data.payload.params.map(async (i) => ({
335
379
  ...i,
336
- content: DataToMessage(i.content)
337
- })))
380
+ content: await DataToMessage(i.content)
381
+ })));
382
+ const res = await api.use.forward
383
+ .user(data.payload.UserId, params)
338
384
  .then(res => createResult(ResultCode.Ok, data.action, res))
339
385
  .catch(err => createResult(ResultCode.Fail, data.action, err));
340
386
  return consume([res]);
@@ -349,8 +395,13 @@ const main = () => {
349
395
  const key = data.payload?.key;
350
396
  if (client[key]) {
351
397
  const params = data.payload.params;
352
- const res = await client[key](...params);
353
- consume([createResult(ResultCode.Ok, '请求完成', res)]);
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
+ }
354
405
  }
355
406
  else {
356
407
  consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
@@ -358,32 +409,6 @@ const main = () => {
358
409
  };
359
410
  cbp.onapis((data, consume) => void onapis(data, consume));
360
411
  };
361
- const mainProcess = () => {
362
- ['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
363
- process?.on?.(sig, () => {
364
- logger.info?.(`[@alemonjs/onebot][${sig}] 收到信号,正在关闭...`);
365
- setImmediate(() => process.exit(0));
366
- });
367
- });
368
- process?.on?.('exit', code => {
369
- logger.info?.(`[@alemonjs/onebot][exit] 进程退出,code=${code}`);
370
- });
371
- process.on('message', msg => {
372
- try {
373
- const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
374
- if (data?.type === 'start') {
375
- main();
376
- }
377
- else if (data?.type === 'stop') {
378
- process.exit(0);
379
- }
380
- }
381
- catch { }
382
- });
383
- if (process.send) {
384
- process.send(JSON.stringify({ type: 'ready' }));
385
- }
386
- };
387
- mainProcess();
412
+ var index = definePlatform({ main });
388
413
 
389
- export { main as default, platform };
414
+ export { index as default, platform };
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "2.1.0-alpha.14",
3
+ "version": "2.1.0-alpha.17",
4
4
  "description": "oneBot v11",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",
9
- "types": "lib",
10
9
  "scripts": {
11
10
  "build": "lvy build"
12
11
  },
@@ -26,7 +25,7 @@
26
25
  "ws": "^8.18.1"
27
26
  },
28
27
  "peerDependencies": {
29
- "alemonjs": "^2.1.0-alpha.15"
28
+ "alemonjs": "^2.1.14"
30
29
  },
31
30
  "alemonjs": {
32
31
  "desktop": {