onebots 0.4.6 → 0.4.8

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.
@@ -49,6 +49,8 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
49
49
  };
50
50
  dispatch(data: Record<string, any>): void;
51
51
  apply(req: V12.RequestAction): Promise<string>;
52
+ private httpAuth;
53
+ private httpRequestHandler;
52
54
  private _httpRequestHandler;
53
55
  /**
54
56
  * 快速操作
@@ -121,6 +121,7 @@ class V12 extends events_1.EventEmitter {
121
121
  }
122
122
  }
123
123
  startHttp(config) {
124
+ this.oneBot.app.router.all(this.path, (ctx) => this.httpRequestHandler(ctx, config));
124
125
  this.oneBot.app.router.all(new RegExp(`^${this.path}/(.*)$`), (ctx) => this._httpRequestHandler(ctx, config));
125
126
  this.logger.mark(`开启http服务器成功,监听:http://127.0.0.1:${this.oneBot.app.config.port}${this.path}`);
126
127
  this.on('dispatch', (payload) => {
@@ -433,7 +434,7 @@ class V12 extends events_1.EventEmitter {
433
434
  else
434
435
  throw new onebot_1.NotFoundError();
435
436
  }
436
- async _httpRequestHandler(ctx, config) {
437
+ async httpAuth(ctx, config) {
437
438
  if (ctx.method === 'OPTIONS') {
438
439
  return ctx.writeHead(200, {
439
440
  'Access-Control-Allow-Origin': '*',
@@ -458,6 +459,37 @@ class V12 extends events_1.EventEmitter {
458
459
  ctx.res.setHeader("Content-Type", "application/json; charset=utf-8");
459
460
  if (this.config.enable_cors)
460
461
  ctx.res.setHeader("Access-Control-Allow-Origin", "*");
462
+ }
463
+ async httpRequestHandler(ctx, config) {
464
+ if (await this.httpAuth(ctx, config))
465
+ return;
466
+ if (ctx.method === "GET") {
467
+ try {
468
+ const ret = await this.apply(ctx.query);
469
+ ctx.res.writeHead(200).end(ret);
470
+ }
471
+ catch (e) {
472
+ ctx.res.writeHead(500).end(e.message);
473
+ }
474
+ }
475
+ else if (ctx.method === "POST") {
476
+ try {
477
+ const params = { ...(ctx.request.query || {}), ...(ctx.request.body || {}) };
478
+ const ret = await this.apply(params);
479
+ ctx.res.writeHead(200).end(ret);
480
+ }
481
+ catch (e) {
482
+ ctx.res.writeHead(500).end(e.message);
483
+ }
484
+ }
485
+ else {
486
+ ctx.res.writeHead(405).end();
487
+ }
488
+ }
489
+ async _httpRequestHandler(ctx, config) {
490
+ if (await this.httpAuth(ctx, config))
491
+ return;
492
+ const url = new url_1.URL(ctx.url, `http://127.0.0.1`);
461
493
  const action = url.pathname.replace(`${this.path}`, '').slice(1);
462
494
  if (ctx.method === "GET") {
463
495
  try {
@@ -25,7 +25,7 @@ async function processMessage(message, source) {
25
25
  'forward', 'node',
26
26
  'music', 'share', 'xml', 'json', 'location', // 分享类
27
27
  ].includes(n.type));
28
- segments.forEach(seg => {
28
+ for (const seg of segments) {
29
29
  if (['image', 'video', 'audio'].includes(seg.type)) {
30
30
  const { file_id } = seg.data;
31
31
  const fileInfo = this.getFile(file_id);
@@ -34,7 +34,13 @@ async function processMessage(message, source) {
34
34
  if (seg.data['file_id']?.startsWith('base64://'))
35
35
  seg.data['file_id'] = Buffer.from(seg.data['file_id'].slice(9), 'base64');
36
36
  }
37
- });
37
+ else if (['mention', 'mention_all'].includes(seg.type)) {
38
+ seg.data['qq'] = seg.data['user_id'];
39
+ }
40
+ else if (seg.type === 'node') {
41
+ seg.data['message'] = (await processMessage.call(this, seg.data['message'])).element;
42
+ }
43
+ }
38
44
  const element = V12_1.V12.fromSegment(segments);
39
45
  return { element, quote: quote || source, share, music };
40
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "@koa/router": "^10.1.1",
57
57
  "@zhinjs/shared": "^0.0.9",
58
- "icqq": "^0.4.1",
58
+ "icqq": "^0.4.6",
59
59
  "icqq-cq-enable": "^1.0.1",
60
60
  "js-yaml": "^4.1.0",
61
61
  "koa": "^2.13.4",