onebots 0.4.47 → 0.4.48

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 (42) hide show
  1. package/dist/assets/{index-yG7HG4Oa.css → index-2tNhvoZy.css} +1 -1
  2. package/dist/assets/index-_Kz1yWe8.js +19 -0
  3. package/dist/index.html +2 -2
  4. package/lib/adapter.js +6 -8
  5. package/lib/adapters/dingtalk/index.d.ts +4 -4
  6. package/lib/adapters/dingtalk/index.js +56 -49
  7. package/lib/adapters/dingtalk/utils.js +5 -20
  8. package/lib/adapters/icqq/index.d.ts +4 -3
  9. package/lib/adapters/icqq/index.js +128 -101
  10. package/lib/adapters/icqq/utils.js +2 -2
  11. package/lib/adapters/qq/index.d.ts +4 -4
  12. package/lib/adapters/qq/index.js +63 -52
  13. package/lib/adapters/qq/utils.js +5 -20
  14. package/lib/adapters/wechat/index.d.ts +3 -3
  15. package/lib/adapters/wechat/index.js +63 -52
  16. package/lib/adapters/wechat/utils.js +5 -20
  17. package/lib/bin.js +6 -6
  18. package/lib/db.js +10 -10
  19. package/lib/onebot.d.ts +12 -12
  20. package/lib/onebot.js +25 -16
  21. package/lib/server/app.d.ts +2 -2
  22. package/lib/server/app.js +71 -70
  23. package/lib/server/router.d.ts +1 -1
  24. package/lib/server/router.js +5 -5
  25. package/lib/service/V11/action/common.d.ts +1 -0
  26. package/lib/service/V11/action/common.js +24 -24
  27. package/lib/service/V11/action/friend.js +16 -8
  28. package/lib/service/V11/action/group.js +52 -22
  29. package/lib/service/V11/index.js +86 -50
  30. package/lib/service/V12/action/common.d.ts +3 -3
  31. package/lib/service/V12/action/common.js +33 -31
  32. package/lib/service/V12/action/friend.js +8 -4
  33. package/lib/service/V12/action/group.js +50 -20
  34. package/lib/service/V12/action/guild.js +110 -35
  35. package/lib/service/V12/index.d.ts +18 -18
  36. package/lib/service/V12/index.js +189 -147
  37. package/lib/service/shareMusicCustom.js +14 -9
  38. package/lib/service.js +29 -27
  39. package/lib/utils.d.ts +1 -1
  40. package/lib/utils.js +44 -32
  41. package/package.json +1 -1
  42. package/dist/assets/index-YN4djyjB.js +0 -19
@@ -22,21 +22,21 @@ class V12 extends service_1.Service {
22
22
  super(oneBot.adapter, config);
23
23
  this.oneBot = oneBot;
24
24
  this.config = config;
25
- this.version = 'V12';
25
+ this.version = "V12";
26
26
  this.timestamp = Date.now();
27
27
  this.wsr = new Set();
28
- this.db = new db_1.JsonDB((0, path_1.join)(app_1.App.configDir, 'data', `${this.oneBot.uin}_v12.jsondb`));
28
+ this.db = new db_1.JsonDB((0, path_1.join)(app_1.App.configDir, "data", `${this.oneBot.uin}_v12.jsondb`));
29
29
  this.action = new action_1.Action();
30
30
  this.logger = this.oneBot.adapter.getLogger(this.oneBot.uin, this.version);
31
31
  }
32
32
  addHistory(payload) {
33
- return this.db.push('eventBuffer', payload);
33
+ return this.db.push("eventBuffer", payload);
34
34
  }
35
35
  shiftHistory() {
36
- return this.db.shift('eventBuffer');
36
+ return this.db.shift("eventBuffer");
37
37
  }
38
38
  get history() {
39
- return this.db.get('eventBuffer', []);
39
+ return this.db.get("eventBuffer", []);
40
40
  }
41
41
  getFile(file_id) {
42
42
  return this.db.get(`files.${file_id}`);
@@ -50,36 +50,36 @@ class V12 extends service_1.Service {
50
50
  return file_id;
51
51
  }
52
52
  get files() {
53
- const files = this.db.get('files', {});
54
- return Object.keys(files).map((file_id) => {
53
+ const files = this.db.get("files", {});
54
+ return Object.keys(files).map(file_id => {
55
55
  return {
56
56
  file_id,
57
- ...files[file_id]
57
+ ...files[file_id],
58
58
  };
59
59
  });
60
60
  }
61
61
  set history(value) {
62
- this.db.set('eventBuffer', value);
62
+ this.db.set("eventBuffer", value);
63
63
  }
64
64
  start() {
65
65
  if (this.config.use_http) {
66
- const config = typeof this.config.use_http === 'boolean' ? {} : this.config.use_http || {};
66
+ const config = typeof this.config.use_http === "boolean" ? {} : this.config.use_http || {};
67
67
  this.startHttp({
68
68
  access_token: this.config.access_token,
69
69
  event_enabled: true,
70
70
  event_buffer_size: 10,
71
- ...config
71
+ ...config,
72
72
  });
73
73
  }
74
74
  if (this.config.use_ws) {
75
- const config = typeof this.config.use_ws === 'boolean' ? {} : this.config.use_ws || {};
75
+ const config = typeof this.config.use_ws === "boolean" ? {} : this.config.use_ws || {};
76
76
  this.startWs({
77
77
  access_token: this.config.access_token,
78
- ...config
78
+ ...config,
79
79
  });
80
80
  }
81
81
  this.config.webhook.forEach(config => {
82
- if (typeof config === 'string') {
82
+ if (typeof config === "string") {
83
83
  config = {
84
84
  url: config,
85
85
  access_token: this.config.access_token,
@@ -88,13 +88,13 @@ class V12 extends service_1.Service {
88
88
  else {
89
89
  config = {
90
90
  access_token: this.config.access_token,
91
- ...config
91
+ ...config,
92
92
  };
93
93
  }
94
94
  this.startWebhook(config);
95
95
  });
96
96
  this.config.ws_reverse.forEach(config => {
97
- if (typeof config === 'string') {
97
+ if (typeof config === "string") {
98
98
  config = {
99
99
  url: config,
100
100
  access_token: this.config.access_token,
@@ -103,15 +103,15 @@ class V12 extends service_1.Service {
103
103
  else {
104
104
  config = {
105
105
  access_token: this.config.access_token,
106
- ...config
106
+ ...config,
107
107
  };
108
108
  }
109
109
  this.startWsReverse(config);
110
110
  });
111
- this.on('dispatch', (unserialized) => {
111
+ this.on("dispatch", unserialized => {
112
112
  const serialized = JSON.stringify(unserialized);
113
113
  for (const ws of this.wss?.clients) {
114
- ws.send(serialized, (err) => {
114
+ ws.send(serialized, err => {
115
115
  if (err)
116
116
  this.logger.error(`正向WS(${ws.url})上报事件失败: ` + err.message);
117
117
  else
@@ -119,7 +119,7 @@ class V12 extends service_1.Service {
119
119
  });
120
120
  }
121
121
  for (const ws of this.wsr) {
122
- ws.send(serialized, (err) => {
122
+ ws.send(serialized, err => {
123
123
  if (err)
124
124
  this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
125
125
  else
@@ -129,36 +129,37 @@ class V12 extends service_1.Service {
129
129
  });
130
130
  if (this.config.heartbeat) {
131
131
  this.heartbeat = setInterval(() => {
132
- this.dispatch(V12.formatPayload(this.oneBot.uin, 'heartbeat', {
132
+ this.dispatch(V12.formatPayload(this.oneBot.uin, "heartbeat", {
133
133
  detail_type: "heartbeat",
134
134
  interval: new Date().getTime() + this.config.heartbeat * 1000,
135
- status: this.action.getStatus.apply(this)
135
+ status: this.action.getStatus.apply(this),
136
136
  }));
137
137
  }, this.config.heartbeat * 1000);
138
138
  }
139
- this.adapter.on('message.receive', (uin, event) => {
140
- const payload = this.adapter.formatEventPayload(uin, 'V12', 'message', event);
139
+ this.adapter.on("message.receive", (uin, event) => {
140
+ const payload = this.adapter.formatEventPayload(uin, "V12", "message", event);
141
141
  this.dispatch(payload);
142
142
  });
143
- this.adapter.on('notice.receive', (uin, event) => {
144
- const payload = this.adapter.formatEventPayload(uin, 'V12', 'notice', event);
143
+ this.adapter.on("notice.receive", (uin, event) => {
144
+ const payload = this.adapter.formatEventPayload(uin, "V12", "notice", event);
145
145
  this.dispatch(payload);
146
146
  });
147
- this.adapter.on('request.receive', (uin, event) => {
148
- const payload = this.adapter.formatEventPayload(uin, 'V12', 'request', event);
147
+ this.adapter.on("request.receive", (uin, event) => {
148
+ const payload = this.adapter.formatEventPayload(uin, "V12", "request", event);
149
149
  this.dispatch(payload);
150
150
  });
151
151
  }
152
152
  startHttp(config) {
153
- this.oneBot.app.router.all(this.path, (ctx) => this.httpRequestHandler(ctx, config));
154
- this.oneBot.app.router.all(new RegExp(`^${this.path}/(.*)$`), (ctx) => this._httpRequestHandler(ctx, config));
153
+ this.oneBot.app.router.all(this.path, ctx => this.httpRequestHandler(ctx, config));
154
+ this.oneBot.app.router.all(new RegExp(`^${this.path}/(.*)$`), ctx => this._httpRequestHandler(ctx, config));
155
155
  this.logger.mark(`开启http服务器成功,监听:http://127.0.0.1:${this.oneBot.app.config.port}${this.path}`);
156
- this.on('dispatch', (payload) => {
157
- if (!['message', 'notice', 'request', 'meta'].includes(payload.type))
156
+ this.on("dispatch", (payload) => {
157
+ if (!["message", "notice", "request", "meta"].includes(payload.type))
158
158
  return;
159
159
  if (config.event_enabled) {
160
160
  this.addHistory(payload);
161
- if (config.event_buffer_size !== 0 && this.history.length > config.event_buffer_size)
161
+ if (config.event_buffer_size !== 0 &&
162
+ this.history.length > config.event_buffer_size)
162
163
  this.shiftHistory();
163
164
  }
164
165
  });
@@ -175,24 +176,26 @@ class V12 extends service_1.Service {
175
176
  },
176
177
  };
177
178
  if (config.access_token) {
178
- options.headers['Authorization'] = `Bearer ${config.access_token}`;
179
+ options.headers["Authorization"] = `Bearer ${config.access_token}`;
179
180
  }
180
181
  const protocol = config.url.startsWith("https") ? https_1.default : http_1.default;
181
- this.on('dispatch', (unserialized) => {
182
+ this.on("dispatch", (unserialized) => {
182
183
  try {
183
184
  const serialized = JSON.stringify(unserialized);
184
- protocol.request(config.url, {
185
+ protocol
186
+ .request(config.url, {
185
187
  ...options,
186
188
  headers: {
187
189
  ...options.headers,
188
190
  "Content-Length": Buffer.byteLength(serialized),
189
- }
190
- }, (res) => {
191
+ },
192
+ }, res => {
191
193
  if (res.statusCode !== 200)
192
- return this.logger.warn(`Webhook(${config.url})上报事件收到非200响应:` + res.statusCode);
194
+ return this.logger.warn(`Webhook(${config.url})上报事件收到非200响应:` +
195
+ res.statusCode);
193
196
  let data = "";
194
197
  res.setEncoding("utf-8");
195
- res.on("data", (chunk) => data += chunk);
198
+ res.on("data", chunk => (data += chunk));
196
199
  res.on("end", () => {
197
200
  this.logger.debug(`收到Webhook响应 ${res.statusCode} :` + data);
198
201
  if (!data)
@@ -204,9 +207,11 @@ class V12 extends service_1.Service {
204
207
  this.logger.error(`快速操作遇到错误:` + e.message);
205
208
  }
206
209
  });
207
- }).on("error", (err) => {
210
+ })
211
+ .on("error", err => {
208
212
  this.logger.error(`Webhook(${config.url})上报事件失败:` + err.message);
209
- }).end(serialized, () => {
213
+ })
214
+ .end(serialized, () => {
210
215
  this.logger.debug(`Webhook(${config.url})上报事件成功: ` + serialized);
211
216
  });
212
217
  }
@@ -215,28 +220,30 @@ class V12 extends service_1.Service {
215
220
  }
216
221
  });
217
222
  if (config.get_latest_actions) {
218
- const interval = (config.get_latest_actions && typeof config.get_latest_actions === 'object') ?
219
- config.get_latest_actions.interval * 1000 :
220
- 1000 * 60;
223
+ const interval = config.get_latest_actions && typeof config.get_latest_actions === "object"
224
+ ? config.get_latest_actions.interval * 1000
225
+ : 1000 * 60;
221
226
  setInterval(() => {
222
227
  try {
223
- const actionPath = typeof config.get_latest_actions === 'string' ?
224
- config.get_latest_actions :
225
- typeof config.get_latest_actions === 'boolean' ?
226
- 'get_latest_actions' :
227
- config.get_latest_actions.path || '/get_latest_actions';
228
- protocol.request(`${config.url}${actionPath}`, {
228
+ const actionPath = typeof config.get_latest_actions === "string"
229
+ ? config.get_latest_actions
230
+ : typeof config.get_latest_actions === "boolean"
231
+ ? "get_latest_actions"
232
+ : config.get_latest_actions.path || "/get_latest_actions";
233
+ protocol
234
+ .request(`${config.url}${actionPath}`, {
229
235
  ...options,
230
- method: 'GET',
236
+ method: "GET",
231
237
  headers: {
232
238
  ...options.headers,
233
- }
234
- }, (res) => {
239
+ },
240
+ }, res => {
235
241
  if (res.statusCode !== 200)
236
- return this.logger.warn(`Webhook(${config.url})获取动作队列收到非200响应:` + res.statusCode);
242
+ return this.logger.warn(`Webhook(${config.url})获取动作队列收到非200响应:` +
243
+ res.statusCode);
237
244
  let data = "";
238
245
  res.setEncoding("utf-8");
239
- res.on("data", (chunk) => data += chunk);
246
+ res.on("data", chunk => (data += chunk));
240
247
  res.on("end", () => {
241
248
  this.logger.info(`获取动作队列响应 ${res.statusCode} :` + data);
242
249
  if (!data)
@@ -248,9 +255,11 @@ class V12 extends service_1.Service {
248
255
  this.logger.error(`执行动作报错:` + e.message);
249
256
  }
250
257
  });
251
- }).on("error", (err) => {
258
+ })
259
+ .on("error", err => {
252
260
  this.logger.error(`Webhook(${config.url})获取动作队列失败:` + err.message);
253
- }).end();
261
+ })
262
+ .end();
254
263
  }
255
264
  catch (e) {
256
265
  this.logger.error(`Webhook(${config.url})获取动作队列失败:` + e.message);
@@ -266,12 +275,12 @@ class V12 extends service_1.Service {
266
275
  startWs(config) {
267
276
  this.wss = this.oneBot.app.router.ws(this.path, this.oneBot.app.httpServer);
268
277
  this.logger.mark(`开启ws服务器成功,监听:ws://127.0.0.1:${this.oneBot.app.config.port}${this.path}`);
269
- this.wss.on("error", (err) => {
278
+ this.wss.on("error", err => {
270
279
  this.logger.error(err.message);
271
280
  });
272
281
  this.wss.on("connection", (ws, req) => {
273
282
  this.logger.info(`ws客户端(${req.url})已连接`);
274
- ws.on("error", (err) => {
283
+ ws.on("error", err => {
275
284
  this.logger.error(`ws客户端(${req.url})报错:${err.message}`);
276
285
  });
277
286
  ws.on("close", (code, reason) => {
@@ -279,10 +288,11 @@ class V12 extends service_1.Service {
279
288
  });
280
289
  if (config.access_token) {
281
290
  const url = new url_1.URL(req.url, "http://127.0.0.1");
282
- const token = url.searchParams.get('access_token');
291
+ const token = url.searchParams.get("access_token");
283
292
  if (token)
284
293
  req.headers["authorization"] = `Bearer ${token}`;
285
- if (!req.headers["authorization"] || req.headers["authorization"] !== `Bearer ${config.access_token}`)
294
+ if (!req.headers["authorization"] ||
295
+ req.headers["authorization"] !== `Bearer ${config.access_token}`)
286
296
  return ws.close(401, "wrong access token");
287
297
  }
288
298
  this._webSocketHandler(ws);
@@ -298,87 +308,95 @@ class V12 extends service_1.Service {
298
308
  }
299
309
  }
300
310
  format(event, ...args) {
301
- const data = (typeof args[0]) === 'object' ? args.shift() || {} : {};
311
+ const data = typeof args[0] === "object" ? args.shift() || {} : {};
302
312
  data.type = data.post_type;
303
313
  if (!data.type) {
304
- data.type = 'meta';
305
- data.detail_type = 'online';
314
+ data.type = "meta";
315
+ data.detail_type = "online";
306
316
  if (data.image) {
307
- data.type = 'login';
308
- data.detail_type = 'qrcode';
317
+ data.type = "login";
318
+ data.detail_type = "qrcode";
309
319
  }
310
320
  else if (data.url) {
311
- data.type = 'login';
312
- data.detail_type = 'slider';
321
+ data.type = "login";
322
+ data.detail_type = "slider";
313
323
  if (data.phone) {
314
- data.detail_type = 'device';
324
+ data.detail_type = "device";
315
325
  }
316
326
  }
317
327
  else if (data.message) {
318
- data.type = 'login';
319
- data.detial_type = 'error';
328
+ data.type = "login";
329
+ data.detial_type = "error";
320
330
  }
321
331
  }
322
- if (data.type === 'notice') {
332
+ if (data.type === "notice") {
323
333
  switch (data.detail_type) {
324
- case 'friend':
325
- if (['increase', 'decrease'].includes(data.sub_type))
326
- data.detail_type = 'friend_' + data.sub_type;
327
- else if (data.sub_type === 'recall')
328
- data.detail_type = 'private_message_delete';
334
+ case "friend":
335
+ if (["increase", "decrease"].includes(data.sub_type))
336
+ data.detail_type = "friend_" + data.sub_type;
337
+ else if (data.sub_type === "recall")
338
+ data.detail_type = "private_message_delete";
329
339
  break;
330
- case 'group':
331
- if (['increase', 'decrease'].includes(data.sub_type))
332
- data.detail_type = 'group_member_' + data.sub_type;
333
- else if (data.sub_type === 'recall')
334
- data.detail_type = 'group_message_delete';
340
+ case "group":
341
+ if (["increase", "decrease"].includes(data.sub_type))
342
+ data.detail_type = "group_member_" + data.sub_type;
343
+ else if (data.sub_type === "recall")
344
+ data.detail_type = "group_message_delete";
335
345
  }
336
346
  }
337
- if (data.type === 'system')
338
- data.type = 'meta';
347
+ if (data.type === "system")
348
+ data.type = "meta";
339
349
  data.alt_message = data.raw_message;
340
350
  data.self = this.action.getSelfInfo.apply(this);
341
351
  if (!data.detail_type)
342
- data.detail_type = data.message_type || data.notice_type || data.request_type || data.system_type;
343
- data.message = data.type === 'message' ? this.adapter.toSegment('V12', data.message) : data.message;
352
+ data.detail_type =
353
+ data.message_type || data.notice_type || data.request_type || data.system_type;
354
+ data.message =
355
+ data.type === "message" ? this.adapter.toSegment("V12", data.message) : data.message;
344
356
  if (data.source)
345
357
  data.source = {
346
358
  ...data.source,
347
- message_id: data.detail_type === 'private' ?
348
- (0, message_1.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.time) :
349
- (0, message_1.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time),
359
+ message_id: data.detail_type === "private"
360
+ ? (0, message_1.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.time)
361
+ : (0, message_1.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time),
350
362
  user_id: data.source.user_id,
351
363
  message: data.source.message,
352
364
  };
353
365
  return V12.formatPayload(this.oneBot.uin, event, data);
354
366
  }
355
- system_online(data) {
356
- }
367
+ system_online(data) { }
357
368
  async dispatch(data) {
358
369
  const payload = {
359
370
  id: (0, utils_2.uuid)(),
360
- impl: 'onebots',
371
+ impl: "onebots",
361
372
  version: 12,
362
373
  platform: this.oneBot.platform,
363
374
  self: {
364
375
  platform: this.oneBot.platform,
365
- user_id: `${this.oneBot.uin}`
376
+ user_id: `${this.oneBot.uin}`,
366
377
  },
367
378
  };
368
379
  Object.assign(payload, (0, utils_2.transformObj)(data, (key, value) => {
369
- if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key))
380
+ if (![
381
+ "user_id",
382
+ "group_id",
383
+ "discuss_id",
384
+ "member_id",
385
+ "channel_id",
386
+ "guild_id",
387
+ ].includes(key))
370
388
  return value;
371
- return value + '';
389
+ return value + "";
372
390
  }), {
373
391
  self_id: `${this.oneBot.uin}`,
374
392
  self: {
375
393
  platform: this.oneBot.platform,
376
- user_id: `${this.oneBot.uin}`
394
+ user_id: `${this.oneBot.uin}`,
377
395
  },
378
396
  });
379
397
  if (!this.filterFn(payload))
380
398
  return;
381
- this.emit('dispatch', payload);
399
+ this.emit("dispatch", payload);
382
400
  }
383
401
  async apply(req) {
384
402
  let { action = "", params = {}, echo } = req;
@@ -386,8 +404,8 @@ class V12 extends service_1.Service {
386
404
  let is_async = action.includes("_async");
387
405
  if (is_async)
388
406
  action = action.replace("_async", "");
389
- if (action === 'send_message') {
390
- if (["private", "group", "discuss", 'direct', 'guild'].includes(params.detail_type)) {
407
+ if (action === "send_message") {
408
+ if (["private", "group", "discuss", "direct", "guild"].includes(params.detail_type)) {
391
409
  action = "send_" + params.detail_type + "_msg";
392
410
  }
393
411
  else if (params.user_id)
@@ -399,35 +417,37 @@ class V12 extends service_1.Service {
399
417
  else if (params.channel_id)
400
418
  action = "send_guild_msg";
401
419
  else if (params.guild_id)
402
- action = 'send_direct_msg';
420
+ action = "send_direct_msg";
403
421
  else
404
- throw new Error('required detail_type or input (user_id/group_id/guild_id/channel_id)');
422
+ throw new Error("required detail_type or input (user_id/group_id/guild_id/channel_id)");
405
423
  }
406
424
  const method = (0, utils_2.toHump)(action);
407
425
  if (Reflect.has(this.action, method)) {
408
- const ARGS = String(Reflect.get(this.action, method)).match(/\(.*\)/)?.[0]
426
+ const ARGS = String(Reflect.get(this.action, method))
427
+ .match(/\(.*\)/)?.[0]
409
428
  .replace("(", "")
410
429
  .replace(")", "")
411
430
  .split(",")
412
- .filter(Boolean).map(v => v.replace(/=.+/, "").trim());
431
+ .filter(Boolean)
432
+ .map(v => v.replace(/=.+/, "").trim());
413
433
  const args = [];
414
434
  for (let k of ARGS) {
415
435
  if (Reflect.has(params, k)) {
416
436
  if (onebot_1.BOOLS.includes(k))
417
437
  params[k] = (0, utils_2.toBool)(params[k]);
418
- if (k === 'message') {
419
- if (typeof params[k] === 'string') {
438
+ if (k === "message") {
439
+ if (typeof params[k] === "string") {
420
440
  if (/[CQ:music,type=.+,id=.+]/.test(params[k])) {
421
- params[k] = params[k].replace(',type=', ',platform=');
441
+ params[k] = params[k].replace(",type=", ",platform=");
422
442
  }
423
- params[k] = this.adapter.fromCqcode('V12', params[k]);
443
+ params[k] = this.adapter.fromCqcode("V12", params[k]);
424
444
  }
425
445
  else {
426
- if (params[k][0].type == 'music' && params[k][0]?.data?.type) {
446
+ if (params[k][0].type == "music" && params[k][0]?.data?.type) {
427
447
  params[k][0].data.platform = params[k][0].data.type;
428
448
  delete params[k][0].data.type;
429
449
  }
430
- params[k] = this.adapter.fromSegment('V12', params[k]);
450
+ params[k] = this.adapter.fromSegment("V12", params[k]);
431
451
  }
432
452
  }
433
453
  args.push(params[k]);
@@ -455,7 +475,7 @@ class V12 extends service_1.Service {
455
475
  if (result.data instanceof Map)
456
476
  result.data = [...result.data.values()];
457
477
  if (result.data?.message)
458
- result.data.message = this.adapter.toSegment('V12', result.data.message);
478
+ result.data.message = this.adapter.toSegment("V12", result.data.message);
459
479
  if (echo) {
460
480
  result.echo = echo;
461
481
  }
@@ -465,12 +485,14 @@ class V12 extends service_1.Service {
465
485
  throw new onebot_1.NotFoundError();
466
486
  }
467
487
  async httpAuth(ctx, config) {
468
- if (ctx.method === 'OPTIONS') {
469
- return ctx.writeHead(200, {
470
- 'Access-Control-Allow-Origin': '*',
471
- 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
472
- 'Access-Control-Allow-Headers': 'Content-Type, authorization'
473
- }).end();
488
+ if (ctx.method === "OPTIONS") {
489
+ return ctx
490
+ .writeHead(200, {
491
+ "Access-Control-Allow-Origin": "*",
492
+ "Access-Control-Allow-Methods": "POST, GET, OPTIONS",
493
+ "Access-Control-Allow-Headers": "Content-Type, authorization",
494
+ })
495
+ .end();
474
496
  }
475
497
  const url = new url_1.URL(ctx.url, `http://127.0.0.1`);
476
498
  if (config.access_token) {
@@ -504,7 +526,10 @@ class V12 extends service_1.Service {
504
526
  }
505
527
  else if (ctx.method === "POST") {
506
528
  try {
507
- const params = { ...(ctx.request.query || {}), ...(ctx.request.body || {}) };
529
+ const params = {
530
+ ...(ctx.request.query || {}),
531
+ ...(ctx.request.body || {}),
532
+ };
508
533
  const ret = await this.apply(params);
509
534
  ctx.res.writeHead(200).end(ret);
510
535
  }
@@ -520,7 +545,7 @@ class V12 extends service_1.Service {
520
545
  if (await this.httpAuth(ctx, config))
521
546
  return;
522
547
  const url = new url_1.URL(ctx.url, `http://127.0.0.1`);
523
- const action = url.pathname.replace(`${this.path}`, '').slice(1);
548
+ const action = url.pathname.replace(`${this.path}`, "").slice(1);
524
549
  if (ctx.method === "GET") {
525
550
  try {
526
551
  const ret = await this.apply({ action, params: ctx.query });
@@ -532,7 +557,10 @@ class V12 extends service_1.Service {
532
557
  }
533
558
  else if (ctx.method === "POST") {
534
559
  try {
535
- const params = { ...(ctx.request.query || {}), ...(ctx.request.body || {}) };
560
+ const params = {
561
+ ...(ctx.request.query || {}),
562
+ ...(ctx.request.body || {}),
563
+ };
536
564
  const ret = await this.apply({ action, params });
537
565
  ctx.res.writeHead(200).end(ret);
538
566
  }
@@ -558,16 +586,29 @@ class V12 extends service_1.Service {
558
586
  }
559
587
  if (event.detail_type === "group") {
560
588
  if (res.delete)
561
- this.adapter.call(this.oneBot.uin, 'V12', 'deleteMsg', [event.message_id]);
589
+ this.adapter.call(this.oneBot.uin, "V12", "deleteMsg", [event.message_id]);
562
590
  if (res.kick && !event.anonymous)
563
- this.adapter.call(this.oneBot.uin, 'V12', 'setGroupKick', [event.group_id, event.user_id, res.reject_add_request]);
591
+ this.adapter.call(this.oneBot.uin, "V12", "setGroupKick", [
592
+ event.group_id,
593
+ event.user_id,
594
+ res.reject_add_request,
595
+ ]);
564
596
  if (res.ban)
565
- this.adapter.call(this.oneBot.uin, 'V12', 'setGroupBan', [event.group_id, event.user_id, res.ban_duration > 0 ? res.ban_duration : 1800]);
597
+ this.adapter.call(this.oneBot.uin, "V12", "setGroupBan", [
598
+ event.group_id,
599
+ event.user_id,
600
+ res.ban_duration > 0 ? res.ban_duration : 1800,
601
+ ]);
566
602
  }
567
603
  }
568
604
  if (event.type === "request" && "approve" in res) {
569
605
  const action = event.detail_type === "friend" ? "setFriendAddRequest" : "setGroupAddRequest";
570
- this.adapter.call(this.oneBot.uin, 'V12', action, [event.flag, res.approve, res.reason ? res.reason : "", !!res.block]);
606
+ this.adapter.call(this.oneBot.uin, "V12", action, [
607
+ event.flag,
608
+ res.approve,
609
+ res.reason ? res.reason : "",
610
+ !!res.block,
611
+ ]);
571
612
  }
572
613
  }
573
614
  /**
@@ -582,12 +623,12 @@ class V12 extends service_1.Service {
582
623
  "X-Self-ID": String(this.oneBot.uin),
583
624
  "X-Client-Role": "Universal",
584
625
  "User-Agent": `OneBot/12 (${this.oneBot.platform}) Node-onebots/V12`,
585
- "Sec-WebSocket-Protocol": "12.onebots.v" + utils_1.version
626
+ "Sec-WebSocket-Protocol": "12.onebots.v" + utils_1.version,
586
627
  };
587
628
  if (config.access_token)
588
629
  headers.Authorization = "Bearer " + config.access_token;
589
630
  const ws = new ws_1.WebSocket(remoteUrl, { headers });
590
- ws.on("error", (err) => {
631
+ ws.on("error", err => {
591
632
  this.logger.error(err.message);
592
633
  });
593
634
  ws.on("open", () => {
@@ -595,7 +636,7 @@ class V12 extends service_1.Service {
595
636
  this.wsr.add(ws);
596
637
  this._webSocketHandler(ws);
597
638
  });
598
- ws.on("close", (code) => {
639
+ ws.on("close", code => {
599
640
  this.wsr.delete(ws);
600
641
  if (timestmap < this.timestamp)
601
642
  return;
@@ -625,7 +666,7 @@ class V12 extends service_1.Service {
625
666
  status: "ok",
626
667
  data: null,
627
668
  message: null,
628
- echo: data.echo
669
+ echo: data.echo,
629
670
  });
630
671
  }
631
672
  else {
@@ -649,29 +690,30 @@ class V12 extends service_1.Service {
649
690
  status: "failed",
650
691
  data: null,
651
692
  error: {
652
- code, message
693
+ code,
694
+ message,
653
695
  },
654
- echo: data?.echo
696
+ echo: data?.echo,
655
697
  }));
656
698
  }
657
699
  });
658
700
  this.dispatch(V12.formatPayload(this.oneBot.uin, "connect", {
659
701
  detail_type: "connect",
660
- type: 'meta',
661
- version: this.action.getVersion.apply(this)
702
+ type: "meta",
703
+ version: this.action.getVersion.apply(this),
662
704
  }));
663
705
  this.dispatch(V12.formatPayload(this.oneBot.uin, "status_update", {
664
- detail_type: 'status_update',
665
- status: this.action.getStatus.apply(this)
706
+ detail_type: "status_update",
707
+ status: this.action.getStatus.apply(this),
666
708
  }));
667
709
  }
668
710
  }
669
711
  exports.V12 = V12;
670
712
  (function (V12) {
671
- const fileTypes = ['image', "file", 'record', 'video', 'flash'];
713
+ const fileTypes = ["image", "file", "record", "video", "flash"];
672
714
  V12.defaultConfig = {
673
715
  heartbeat: 3,
674
- access_token: '',
716
+ access_token: "",
675
717
  request_timeout: 15,
676
718
  reconnect_interval: 3,
677
719
  enable_cors: true,
@@ -679,25 +721,25 @@ exports.V12 = V12;
679
721
  use_http: true,
680
722
  use_ws: true,
681
723
  webhook: [],
682
- ws_reverse: []
724
+ ws_reverse: [],
683
725
  };
684
726
  function success(data, retcode = 0, echo) {
685
727
  return {
686
728
  retcode,
687
- status: retcode === 0 ? 'ok' : 'failed',
729
+ status: retcode === 0 ? "ok" : "failed",
688
730
  data,
689
- message: '',
690
- echo
731
+ message: "",
732
+ echo,
691
733
  };
692
734
  }
693
735
  V12.success = success;
694
736
  function error(message, retcode = 10001, echo) {
695
737
  return {
696
738
  retcode,
697
- status: 'failed',
739
+ status: "failed",
698
740
  data: null,
699
741
  message,
700
- echo
742
+ echo,
701
743
  };
702
744
  }
703
745
  V12.error = error;
@@ -706,12 +748,12 @@ exports.V12 = V12;
706
748
  self_id: uin,
707
749
  time: Math.floor(Date.now() / 1000),
708
750
  detail_type: type,
709
- type: 'meta',
710
- sub_type: '',
751
+ type: "meta",
752
+ sub_type: "",
711
753
  ...data,
712
- group: data['group']?.info,
713
- friend: data['friend']?.info,
714
- member: data['member']?.info,
754
+ group: data["group"]?.info,
755
+ friend: data["friend"]?.info,
756
+ member: data["member"]?.info,
715
757
  };
716
758
  }
717
759
  V12.formatPayload = formatPayload;