onebots 0.4.23 → 0.4.25

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.
Files changed (77) hide show
  1. package/README.md +25 -3
  2. package/lib/adapter.d.ts +55 -0
  3. package/lib/adapter.js +60 -0
  4. package/lib/adapters/icqq/index.d.ts +36 -0
  5. package/lib/adapters/icqq/index.js +300 -0
  6. package/lib/adapters/qq/bot.d.ts +24 -0
  7. package/lib/adapters/qq/bot.js +20 -0
  8. package/lib/adapters/qq/constans.d.ts +69 -0
  9. package/lib/adapters/qq/constans.js +128 -0
  10. package/lib/adapters/qq/elements.d.ts +125 -0
  11. package/lib/adapters/qq/elements.js +8 -0
  12. package/lib/adapters/qq/entries/channel.d.ts +17 -0
  13. package/lib/adapters/qq/entries/channel.js +2 -0
  14. package/lib/adapters/qq/entries/friend.d.ts +8 -0
  15. package/lib/adapters/qq/entries/friend.js +2 -0
  16. package/lib/adapters/qq/entries/group.d.ts +6 -0
  17. package/lib/adapters/qq/entries/group.js +2 -0
  18. package/lib/adapters/qq/entries/groupMember.d.ts +7 -0
  19. package/lib/adapters/qq/entries/groupMember.js +2 -0
  20. package/lib/adapters/qq/entries/guild.d.ts +21 -0
  21. package/lib/adapters/qq/entries/guild.js +2 -0
  22. package/lib/adapters/qq/entries/guildMember.d.ts +9 -0
  23. package/lib/adapters/qq/entries/guildMember.js +2 -0
  24. package/lib/adapters/qq/entries/user.d.ts +9 -0
  25. package/lib/adapters/qq/entries/user.js +2 -0
  26. package/lib/adapters/qq/event.d.ts +28 -0
  27. package/lib/adapters/qq/event.js +24 -0
  28. package/lib/adapters/qq/index.d.ts +35 -0
  29. package/lib/adapters/qq/index.js +170 -0
  30. package/lib/adapters/qq/message.d.ts +83 -0
  31. package/lib/adapters/qq/message.js +272 -0
  32. package/lib/adapters/qq/qqBot.d.ts +122 -0
  33. package/lib/adapters/qq/qqBot.js +438 -0
  34. package/lib/adapters/qq/sessionManager.d.ts +33 -0
  35. package/lib/adapters/qq/sessionManager.js +257 -0
  36. package/lib/adapters/qq/types.d.ts +45 -0
  37. package/lib/adapters/qq/types.js +2 -0
  38. package/lib/adapters/qq/utils.d.ts +12 -0
  39. package/lib/adapters/qq/utils.js +86 -0
  40. package/lib/bin.js +17 -2
  41. package/lib/config.sample.yaml +11 -5
  42. package/lib/onebot.d.ts +32 -24
  43. package/lib/onebot.js +51 -188
  44. package/lib/server/app.d.ts +22 -12
  45. package/lib/server/app.js +97 -71
  46. package/lib/service/V11/action/common.d.ts +9 -11
  47. package/lib/service/V11/action/common.js +27 -64
  48. package/lib/service/V11/action/friend.d.ts +5 -13
  49. package/lib/service/V11/action/friend.js +6 -16
  50. package/lib/service/V11/action/group.d.ts +19 -22
  51. package/lib/service/V11/action/group.js +20 -30
  52. package/lib/service/V11/action/index.d.ts +1 -1
  53. package/lib/service/V11/db_entities.d.ts +1 -1
  54. package/lib/service/V11/db_entities.js +1 -1
  55. package/lib/service/V11/db_sqlite.d.ts +1 -1
  56. package/lib/service/V11/index.d.ts +47 -16
  57. package/lib/service/V11/index.js +142 -164
  58. package/lib/service/V12/action/common.d.ts +3 -67
  59. package/lib/service/V12/action/common.js +9 -63
  60. package/lib/service/V12/action/friend.d.ts +4 -10
  61. package/lib/service/V12/action/friend.js +4 -12
  62. package/lib/service/V12/action/group.d.ts +19 -21
  63. package/lib/service/V12/action/group.js +19 -27
  64. package/lib/service/V12/action/guild.d.ts +40 -13
  65. package/lib/service/V12/action/guild.js +99 -11
  66. package/lib/service/V12/action/index.d.ts +1 -1
  67. package/lib/service/V12/index.d.ts +37 -13
  68. package/lib/service/V12/index.js +44 -72
  69. package/lib/service.d.ts +7 -2
  70. package/lib/service.js +32 -30
  71. package/lib/utils.d.ts +7 -4
  72. package/lib/utils.js +33 -28
  73. package/package.json +5 -4
  74. package/lib/service/V12/utils.d.ts +0 -8
  75. package/lib/service/V12/utils.js +0 -47
  76. /package/lib/{service/V11 → adapters/icqq}/utils.d.ts +0 -0
  77. /package/lib/{service/V11 → adapters/icqq}/utils.js +0 -0
@@ -28,7 +28,7 @@ __decorate([
28
28
  ], MsgEntry.prototype, "seq", void 0);
29
29
  __decorate([
30
30
  (0, typeorm_1.Column)(),
31
- __metadata("design:type", Number)
31
+ __metadata("design:type", String)
32
32
  ], MsgEntry.prototype, "user_id", void 0);
33
33
  __decorate([
34
34
  (0, typeorm_1.Column)(),
@@ -38,7 +38,7 @@ export declare class Database {
38
38
  * @param group_id
39
39
  * @param seq
40
40
  */
41
- getMsgByParams(user_id: number, group_id: number, seq: number): Promise<MsgEntry | null>;
41
+ getMsgByParams(user_id: string, group_id: number, seq: number): Promise<MsgEntry | null>;
42
42
  /**
43
43
  * 将一条消息标记为 recalled
44
44
  * @param base64_id
@@ -1,21 +1,20 @@
1
1
  /// <reference types="node" />
2
- import { OneBot } from "../../onebot";
3
- import { Service } from "../../service";
4
- import { Dispose } from "../../types";
5
- import { Client } from "icqq";
2
+ import { Config } from "./config";
3
+ import { Action } from "./action";
4
+ import { OneBot, OneBotStatus } from "../../onebot";
6
5
  import { Logger } from "log4js";
7
6
  import { WebSocket, WebSocketServer } from "ws";
8
- import { Action } from "./action";
9
- import { Config } from "./config";
7
+ import { Dispose } from "../../types";
10
8
  import { Database } from "./db_sqlite";
9
+ import { Service } from "../../service";
10
+ import { Dict } from "@zhinjs/shared";
11
11
  export declare class V11 extends Service<"V11"> implements OneBot.Base {
12
- oneBot: OneBot<"V11">;
13
- client: Client;
12
+ oneBot: OneBot<'V11'>;
13
+ config: OneBot.Config<'V11'>;
14
14
  action: Action;
15
- version: string;
15
+ version: OneBot.Version;
16
16
  protected timestamp: number;
17
17
  protected heartbeat?: NodeJS.Timeout;
18
- private path;
19
18
  db: Database;
20
19
  disposes: Dispose[];
21
20
  protected _queue: Array<{
@@ -26,15 +25,14 @@ export declare class V11 extends Service<"V11"> implements OneBot.Base {
26
25
  logger: Logger;
27
26
  wss?: WebSocketServer;
28
27
  wsr: Set<WebSocket>;
29
- constructor(oneBot: OneBot<"V11">, client: Client, config: OneBot.Config<"V11">);
30
- start(path?: string): void;
28
+ constructor(oneBot: OneBot<'V11'>, config: OneBot.Config<'V11'>);
29
+ start(): void;
31
30
  private startHttp;
32
31
  private startHttpReverse;
33
32
  private startWs;
34
33
  private startWsReverse;
35
34
  stop(force?: boolean): Promise<void>;
36
35
  format(_: any, data: any): any;
37
- system_online(data: any): void;
38
36
  dispatch(data: any): Promise<void>;
39
37
  private _formatEvent;
40
38
  private addMsgToDB;
@@ -68,7 +66,7 @@ export declare class V11 extends Service<"V11"> implements OneBot.Base {
68
66
  /**
69
67
  * 限速队列调用
70
68
  */
71
- protected _runQueue(): Promise<void>;
69
+ _runQueue(): Promise<void>;
72
70
  }
73
71
  export declare namespace V11 {
74
72
  interface Result<T extends any> {
@@ -81,8 +79,8 @@ export declare namespace V11 {
81
79
  function ok<T extends any>(data: T, retcode?: number, pending?: boolean): Result<T>;
82
80
  function error(error: string, retcode?: number): Result<any>;
83
81
  const defaultConfig: Config;
84
- function genMetaEvent(uin: number, type: string): {
85
- self_id: number;
82
+ function genMetaEvent(uin: string, type: string): {
83
+ self_id: string | number;
86
84
  time: number;
87
85
  post_type: string;
88
86
  meta_event_type: string;
@@ -108,4 +106,37 @@ export declare namespace V11 {
108
106
  http_reverse?: (string | Config.HttpReverseConfig)[];
109
107
  ws_reverse?: string[];
110
108
  }
109
+ type Payload<T = Dict> = {
110
+ [P in string | symbol]: any;
111
+ } & T;
112
+ type SelfInfo = {
113
+ status: OneBotStatus;
114
+ nickname: string;
115
+ };
116
+ interface GroupInfo {
117
+ group_id: number;
118
+ group_name: string;
119
+ }
120
+ interface UserInfo {
121
+ user_id: number;
122
+ user_name: string;
123
+ }
124
+ interface GroupMemberInfo {
125
+ group_id: number;
126
+ user_id: number;
127
+ user_name: string;
128
+ }
129
+ interface Message {
130
+ }
131
+ interface Segment {
132
+ type: string;
133
+ data: Dict;
134
+ }
135
+ interface MessageElement {
136
+ type: string;
137
+ data: Dict;
138
+ }
139
+ interface MessageRet {
140
+ message_id: number;
141
+ }
111
142
  }
@@ -1,68 +1,49 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
6
  exports.V11 = void 0;
7
+ const action_1 = require("./action");
30
8
  const onebot_1 = require("../../onebot");
31
- const app_1 = require("../../server/app");
32
- const service_1 = require("../../service");
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ const ws_1 = require("ws");
11
+ const url_1 = require("url");
33
12
  const utils_1 = require("../../utils");
34
- const crypto = __importStar(require("crypto"));
35
- const fs_1 = require("fs");
13
+ const onebot_2 = require("../../onebot");
36
14
  const http_1 = __importDefault(require("http"));
37
15
  const https_1 = __importDefault(require("https"));
38
- const icqq_1 = require("icqq");
39
- const icqq_cq_enable_1 = require("icqq-cq-enable");
16
+ const db_sqlite_1 = require("./db_sqlite");
40
17
  const path_1 = require("path");
41
- const url_1 = require("url");
42
- const ws_1 = require("ws");
43
- const action_1 = require("./action");
18
+ const app_1 = require("../../server/app");
44
19
  const db_entities_1 = require("./db_entities");
45
- const db_sqlite_1 = require("./db_sqlite");
20
+ const service_1 = require("../../service");
46
21
  const sendMsgTypes = ["private", "group", "discuss"];
47
22
  const sendMsgMethodRegex = new RegExp(`send_(${sendMsgTypes.join("|")})_msg`);
48
23
  class V11 extends service_1.Service {
49
- constructor(oneBot, client, config) {
50
- super(config);
24
+ constructor(oneBot, config) {
25
+ super(oneBot.adapter, config);
51
26
  this.oneBot = oneBot;
52
- this.client = client;
53
- this.version = "V11";
27
+ this.config = config;
28
+ this.version = 'V11';
54
29
  this.timestamp = Date.now();
55
30
  this._queue = [];
56
31
  this.queue_running = false;
57
32
  this.wsr = new Set();
58
33
  this.action = new action_1.Action();
59
- this.logger = this.oneBot.app.getLogger(this.oneBot.uin, this.version);
60
- this.db = new db_sqlite_1.Database((0, path_1.join)(app_1.App.configDir, "data", this.oneBot.uin + ".db"), this.logger);
34
+ this.logger = this.oneBot.adapter.getLogger(this.oneBot.uin, this.version);
35
+ this.db = new db_sqlite_1.Database((0, path_1.join)(app_1.App.configDir, 'data', this.oneBot.uin + '.db'), this.logger);
36
+ this.oneBot.on('online', async () => {
37
+ this.logger.info("【好友列表】");
38
+ const friendList = await this.oneBot.getFriendList('V11');
39
+ friendList.forEach((item) => this.logger.info(`\t${item.user_name}(${item.user_id})`));
40
+ this.logger.info("【群列表】");
41
+ const groupList = await this.oneBot.getGroupList('V11');
42
+ groupList.forEach(item => this.logger.info(`\t${item.group_name}(${item.group_id})`));
43
+ this.logger.info('');
44
+ });
61
45
  }
62
- start(path) {
63
- this.path = `/${this.oneBot.uin}`;
64
- if (path)
65
- this.path += path;
46
+ start() {
66
47
  if (this.config.use_http)
67
48
  this.startHttp();
68
49
  if (this.config.use_ws)
@@ -106,13 +87,32 @@ class V11 extends service_1.Service {
106
87
  });
107
88
  }
108
89
  });
90
+ this.on("dispatch", (serialized) => {
91
+ for (const ws of this.wss.clients) {
92
+ ws.send(serialized, (err) => {
93
+ if (err)
94
+ this.logger.error(`正向WS(${ws.url})上报事件失败: ` + err.message);
95
+ else
96
+ this.logger.debug(`正向WS(${ws.url})上报事件成功: ` + serialized);
97
+ });
98
+ }
99
+ for (const ws of this.wsr) {
100
+ ws.send(serialized, (err) => {
101
+ if (err) {
102
+ this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
103
+ }
104
+ else
105
+ this.logger.debug(`反向WS(${ws.url})上报事件成功: ` + serialized);
106
+ });
107
+ }
108
+ });
109
109
  if (this.config.heartbeat) {
110
110
  this.heartbeat = setInterval(() => {
111
111
  this.dispatch({
112
112
  self_id: this.oneBot.uin,
113
113
  status: {
114
- online: this.client.status === icqq_1.OnlineStatus.Online,
115
- good: this.oneBot.status === onebot_1.OneBotStatus.Good,
114
+ online: this.adapter.getSelfInfo(this.oneBot.uin, 'V11').status === onebot_1.OneBotStatus.Online,
115
+ good: this.oneBot.status === onebot_1.OneBotStatus.Good
116
116
  },
117
117
  time: Math.floor(Date.now() / 1000),
118
118
  post_type: "meta_event",
@@ -121,14 +121,25 @@ class V11 extends service_1.Service {
121
121
  });
122
122
  }, this.config.heartbeat * 1000);
123
123
  }
124
+ this.adapter.on('message.receive', (uin, event) => {
125
+ const payload = this.adapter.formatEventPayload('V11', 'message', event);
126
+ this.dispatch(payload);
127
+ });
128
+ this.adapter.on('notice.receive', (uin, event) => {
129
+ const payload = this.adapter.formatEventPayload('V11', 'notice', event);
130
+ this.dispatch(payload);
131
+ });
132
+ this.adapter.on('request.receive', (uin, event) => {
133
+ const payload = this.adapter.formatEventPayload('V11', 'request', event);
134
+ this.dispatch(payload);
135
+ });
124
136
  }
125
137
  startHttp() {
126
138
  this.oneBot.app.router.all(new RegExp(`^${this.path}/(.*)$`), this._httpRequestHandler.bind(this));
127
139
  this.logger.mark(`开启http服务器成功,监听:http://127.0.0.1:${this.oneBot.app.config.port}${this.path}`);
128
140
  }
129
141
  startHttpReverse(config) {
130
- this.on("dispatch", (unserialized) => {
131
- const serialized = JSON.stringify(unserialized);
142
+ this.on("dispatch", (serialized) => {
132
143
  const options = {
133
144
  method: "POST",
134
145
  timeout: this.config.post_timeout * 1000,
@@ -142,7 +153,7 @@ class V11 extends service_1.Service {
142
153
  if (this.config.secret) {
143
154
  //@ts-ignore
144
155
  options.headers["X-Signature"] =
145
- "sha1=" + crypto.createHmac("sha1", String(this.config.secret)).update(serialized).digest("hex");
156
+ "sha1=" + crypto_1.default.createHmac("sha1", String(this.config.secret)).update(serialized).digest("hex");
146
157
  }
147
158
  const protocol = config.url.startsWith("https") ? https_1.default : http_1.default;
148
159
  try {
@@ -158,7 +169,7 @@ class V11 extends service_1.Service {
158
169
  if (!data)
159
170
  return;
160
171
  try {
161
- this._quickOperate(unserialized, JSON.parse(data));
172
+ this._quickOperate(JSON.parse(serialized), JSON.parse(data));
162
173
  }
163
174
  catch (e) {
164
175
  this.logger.error(`快速操作遇到错误:` + e.message);
@@ -207,43 +218,29 @@ class V11 extends service_1.Service {
207
218
  this._createWsr(url);
208
219
  }
209
220
  async stop(force) {
210
- if (this.client.status === icqq_1.OnlineStatus.Online) {
211
- await this.client.terminate();
221
+ for (const ws of this.wss.clients) {
222
+ ws.close();
212
223
  }
213
- if (force) {
214
- (0, fs_1.rmSync)(this.client.dir, { force: true, recursive: true });
224
+ this.wss.close();
225
+ for (const ws of this.wsr) {
226
+ ws.close();
215
227
  }
216
228
  }
217
229
  format(_, data) {
218
230
  return data;
219
231
  }
220
- system_online(data) {
221
- this.logger.info("【好友列表】");
222
- this.client.fl.forEach((item) => this.logger.info(`\t${item.nickname}(${item.user_id})`));
223
- this.logger.info("【群列表】");
224
- this.client.gl.forEach((item) => this.logger.info(`\t${item.group_name}(${item.group_id})`));
225
- this.logger.info("");
226
- }
227
232
  async dispatch(data) {
228
- data.post_type = data.post_type || "system";
229
- if (data.message && data.post_type === "message") {
230
- if (this.config.post_message_format === "array") {
231
- data.message = (0, icqq_cq_enable_1.toSegment)(data.message);
232
- if (data.source) {
233
- // reply
233
+ data.post_type = data.post_type || 'system';
234
+ if (data.message && data.post_type === 'message') {
235
+ if (this.config.post_message_format === 'array') {
236
+ data.message = this.adapter.toSegment('V11', data.message);
237
+ if (data.source) { // reply
234
238
  let msg0 = data.message[0];
235
239
  msg0.data["id"] = await this.getReplyMsgIdFromDB(data);
236
240
  }
237
241
  }
238
242
  else {
239
- if (data.source) {
240
- data.message.shift();
241
- // segment 更好用, cq 一般只用来显示,就不存储真实id了, 有需求的自己去改
242
- data.message = (0, icqq_cq_enable_1.toCqcode)(data).replace(/^(\[CQ:reply,id=)(.+?)\]/, `$1${data.source.seq}]`);
243
- }
244
- else {
245
- data.message = (0, icqq_cq_enable_1.toCqcode)(data);
246
- }
243
+ data.message = this.adapter.toCqcode("V11", data.message);
247
244
  }
248
245
  }
249
246
  if (data.message_id) {
@@ -265,20 +262,15 @@ class V11 extends service_1.Service {
265
262
  this.emit("dispatch", this._formatEvent(data));
266
263
  }
267
264
  _formatEvent(data) {
268
- if (data.post_type === "notice") {
265
+ if (data.post_type === 'notice') {
269
266
  // console.log(JSON.stringify(data))
270
267
  const data1 = { ...data };
271
268
  if (data.notice_type === "group") {
272
269
  delete data1.group;
273
270
  delete data1.member;
274
271
  switch (data.sub_type) {
275
- case "decrease":
276
- data1.sub_type =
277
- data.operator_id === data.user_id
278
- ? "leave"
279
- : data.user_id === this.client.uin
280
- ? "kick_me"
281
- : "kick";
272
+ case 'decrease':
273
+ data1.sub_type = data.operator_id === data.user_id ? 'leave' : data.user_id === this.oneBot.uin ? 'kick_me' : 'kick';
282
274
  data1.notice_type = `${data.notice_type}_${data.sub_type}`;
283
275
  break;
284
276
  case "increase":
@@ -343,7 +335,7 @@ class V11 extends service_1.Service {
343
335
  msg.group_id = 0;
344
336
  msg.group_name = "";
345
337
  }
346
- msg.content = data.cqCode;
338
+ msg.content = data.cqCode || data.message;
347
339
  return await this.db.addOrUpdateMsg(msg);
348
340
  }
349
341
  /**
@@ -453,7 +445,7 @@ class V11 extends service_1.Service {
453
445
  }
454
446
  catch (e) {
455
447
  let code, message;
456
- if (e instanceof onebot_1.NotFoundError) {
448
+ if (e instanceof onebot_2.NotFoundError) {
457
449
  code = 1404;
458
450
  message = "不支持的api";
459
451
  }
@@ -521,20 +513,20 @@ class V11 extends service_1.Service {
521
513
  return;
522
514
  const action = event.message_type === "private" ? "sendPrivateMsg" : "sendGroupMsg";
523
515
  const id = event.message_type === "private" ? event.user_id : event.group_id;
524
- this.client[action](id, res.reply, res.auto_escape);
516
+ this.action[action].apply(this, [id, res.reply, res.auto_escape]);
525
517
  }
526
518
  if (event.message_type === "group") {
527
519
  if (res.delete)
528
- this.client.deleteMsg(event.message_id);
520
+ this.adapter.deleteMessage(this.oneBot.uin, 'V11', [event.message_id]);
529
521
  if (res.kick && !event.anonymous)
530
- this.client.setGroupKick(event.group_id, event.user_id, res.reject_add_request);
522
+ this.adapter.call(this.oneBot.uin, 'V11', 'setGroupKick', [event.group_id, event.user_id, res.reject_add_request]);
531
523
  if (res.ban)
532
- this.client.setGroupBan(event.group_id, event.user_id, res.ban_duration > 0 ? res.ban_duration : 1800);
524
+ this.adapter.call(this.oneBot.uin, 'V11', 'setGroupBan', [event.group_id, event.user_id, res.ban_duration > 0 ? res.ban_duration : 1800]);
533
525
  }
534
526
  }
535
527
  if (event.post_type === "request" && "approve" in res) {
536
528
  const action = event.request_type === "friend" ? "setFriendAddRequest" : "setGroupAddRequest";
537
- this.client[action](event.flag, res.approve, res.reason ? res.reason : "", !!res.block);
529
+ this.adapter.call(this.oneBot.uin, 'V11', action, [event.flag, res.approve, res.reason ? res.reason : "", !!res.block]);
538
530
  }
539
531
  }
540
532
  /**
@@ -565,89 +557,75 @@ class V11 extends service_1.Service {
565
557
  action = "send_user_like";
566
558
  }
567
559
  const method = (0, utils_1.toHump)(action);
568
- if (!Reflect.has(this.action, method))
569
- throw new onebot_1.NotFoundError();
570
- const processOBMessage = (message) => {
571
- if (typeof message === "string")
572
- message = (0, icqq_cq_enable_1.fromCqcode)(message);
573
- const [firstSeg] = message;
574
- if (firstSeg.type == "music" && firstSeg?.data?.type) {
575
- firstSeg.data.platform = firstSeg.data.type;
576
- delete firstSeg.data.type;
577
- }
578
- return (0, icqq_cq_enable_1.fromSegment)(message);
579
- };
580
- for (const key of Object.keys(params)) {
581
- if (onebot_1.BOOLS.includes(key))
582
- params[key] = (0, utils_1.toBool)(params[key]);
583
- else if (key === "message") {
584
- const message = processOBMessage(params[key]);
585
- const replyFilter = (e) => e.type === "reply";
586
- const replyElem = message.find(replyFilter);
587
- const messageId = replyElem?.id ?? replyElem?.message_id;
588
- if (messageId)
589
- params.message_id = messageId;
590
- params.message = message.filter((e) => !replyFilter(e));
591
- }
592
- }
593
- if (action === "get_msg")
594
- params.onebot_id = params.message_id;
595
- if (typeof params.message_id === "number" || /^\d+$/.test(params.message_id)) {
596
- params.message_id = (await this.db.getMsgById(params.message_id)).base64_id; // 调用api时把本地的数字id转为base64发给icqq
597
- }
598
- // this.logger.info(`处理过后的请求 params: `, params)
599
- const orgArgNameList = String(Reflect.get(this.action, method))
600
- .match(/\(.*\)/)?.[0]
601
- .replace("(", "")
602
- .replace(")", "")
603
- .split(",")
604
- .filter(Boolean)
605
- .map((v) => v.replace(/=.+/, "").trim());
606
- const args = orgArgNameList.map((k) => params[k]);
607
- // this.logger.info(`Action 原参数名列表: `, orgArgNameList)
608
- // this.logger.info(`处理后的 Action 参数列表: `, args)
609
- let ret, result;
610
- if (is_queue) {
611
- this._queue.push({ method, args });
612
- this._runQueue();
613
- result = V11.ok(null, 0, true);
614
- }
615
- else {
616
- try {
617
- ret = await this.action[method].apply(this, args);
560
+ if (Reflect.has(this.action, method)) {
561
+ const ARGS = String(Reflect.get(this.action, method)).match(/\(.*\)/)?.[0]
562
+ .replace("(", "")
563
+ .replace(")", "")
564
+ .split(",")
565
+ .filter(Boolean).map(v => v.replace(/=.+/, "").trim());
566
+ const args = [];
567
+ for (let k of ARGS) {
568
+ if (Reflect.has(params, k)) {
569
+ if (onebot_2.BOOLS.includes(k))
570
+ params[k] = (0, utils_1.toBool)(params[k]);
571
+ if (k === 'message') {
572
+ if (typeof params[k] === 'string') {
573
+ if (/[CQ:music,type=.+,id=.+]/.test(params[k])) {
574
+ params[k] = params[k].replace(',type=', ',platform=');
575
+ }
576
+ params[k] = this.adapter.fromCqcode('V11', params[k]);
577
+ }
578
+ else {
579
+ if (params[k][0].type == 'music' && params[k][0]?.data?.type) {
580
+ params[k][0].data.platform = params[k][0].data.type;
581
+ delete params[k][0].data.type;
582
+ }
583
+ params[k] = this.adapter.fromSegment('V11', params[k]);
584
+ }
585
+ params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
586
+ }
587
+ args.push(params[k]);
588
+ }
618
589
  }
619
- catch (e) {
620
- this.logger.error(e);
621
- const err = V11.error(e.message);
622
- if (echo)
623
- err.echo = echo;
624
- return JSON.stringify(err);
590
+ let ret, result;
591
+ if (is_queue) {
592
+ this._queue.push({ method, args });
593
+ this._runQueue();
594
+ result = V11.ok(null, 0, true);
625
595
  }
626
- if (ret instanceof Promise) {
627
- if (is_async) {
628
- result = V11.ok(null, 0, true);
596
+ else {
597
+ try {
598
+ ret = await this.action[method].apply(this, args);
599
+ }
600
+ catch (e) {
601
+ return JSON.stringify(V11.error(e.message));
602
+ }
603
+ if (ret instanceof Promise) {
604
+ if (is_async) {
605
+ result = V11.ok(null, 0, true);
606
+ }
607
+ else {
608
+ result = V11.ok(await ret, 0, false);
609
+ }
629
610
  }
630
611
  else {
631
612
  result = V11.ok(await ret, 0, false);
632
613
  }
633
614
  }
634
- else {
635
- result = V11.ok(await ret, 0, false);
615
+ if (result.data instanceof Map)
616
+ result.data = [...result.data.values()];
617
+ if (result.data?.message)
618
+ result.data.message = this.adapter.toSegment('V11', result.data.message);
619
+ // send_msg_xxx 时提前把数据写入数据库(也有可能来的比message慢,后来的话会被数据库忽略)
620
+ if (result.status === "ok" && action.match(sendMsgMethodRegex) && result.data?.message_id && result.data?.seq) {
621
+ result.data.message_id = await this.addMsgToDBFromSendMsgResult(this.oneBot.uin, // msg send resp uin is always bot uin
622
+ params.group_id || 0, result.data.seq, result.data.message_id);
636
623
  }
624
+ if (echo) {
625
+ result.echo = echo;
626
+ }
627
+ return JSON.stringify(result);
637
628
  }
638
- if (result.data instanceof Map)
639
- result.data = [...result.data.values()];
640
- if (result.data?.message)
641
- result.data.message = (0, icqq_cq_enable_1.toSegment)(result.data.message);
642
- // send_msg_xxx 时提前把数据写入数据库(也有可能来的比message慢,后来的话会被数据库忽略)
643
- if (result.status === "ok" && action.match(sendMsgMethodRegex) && result.data?.message_id && result.data?.seq) {
644
- result.data.message_id = await this.addMsgToDBFromSendMsgResult(this.client.uin, // msg send resp uin is always bot uin
645
- params.group_id || 0, result.data.seq, result.data.message_id);
646
- }
647
- if (echo) {
648
- result.echo = echo;
649
- }
650
- return JSON.stringify(result);
651
629
  }
652
630
  /**
653
631
  * 限速队列调用
@@ -704,7 +682,7 @@ exports.V11 = V11;
704
682
  };
705
683
  function genMetaEvent(uin, type) {
706
684
  return {
707
- self_id: uin,
685
+ self_id: Number.isNaN(parseInt(uin)) ? uin : parseInt(uin),
708
686
  time: Math.floor(Date.now() / 1000),
709
687
  post_type: "meta_event",
710
688
  meta_event_type: "lifecycle",