onebots 0.4.15 → 0.4.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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
  <h1>基于icqq的oneBot实现</h1>
3
3
  <p>
4
4
 
5
+ [![npm](https://img.shields.io/npm/v/onebots)](https://www.npmjs.com/package/onebots)
6
+ [![Release and Publish](https://github.com/icqqjs/onebots/actions/workflows/release.yml/badge.svg?branch=master&event=push)](https://github.com/icqqjs/onebots/actions/workflows/release.yml)
5
7
  [![dm](https://shields.io/npm/dm/onebots)](https://www.npmjs.com/package/onebots)
6
8
  [![oneBot V11](https://img.shields.io/badge/OneBot-11-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://onebot.dev/)
7
9
  [![oneBot V12](https://img.shields.io/badge/OneBot-12-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://12.onebot.dev/)
package/lib/onebot.js CHANGED
@@ -202,5 +202,5 @@ var OneBotStatus;
202
202
  (function (OneBotStatus) {
203
203
  OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
204
204
  OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
205
- })(OneBotStatus || (exports.OneBotStatus = OneBotStatus = {}));
205
+ })(OneBotStatus = exports.OneBotStatus || (exports.OneBotStatus = {}));
206
206
  exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
package/lib/server/app.js CHANGED
@@ -47,7 +47,7 @@ class App extends koa_1.default {
47
47
  constructor(config = {}) {
48
48
  super(config);
49
49
  this.oneBots = [];
50
- this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(_a.defaultConfig), config);
50
+ this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
51
51
  this.logger = (0, log4js_1.getLogger)('[icqq-OneBot]');
52
52
  this.logger.level = this.config.log_level;
53
53
  this.router = new router_1.Router({ prefix: config.path });
@@ -86,7 +86,7 @@ class App extends koa_1.default {
86
86
  this.config[uin] = config;
87
87
  const oneBot = this.createOneBot(uin, config);
88
88
  oneBot.startListen();
89
- (0, fs_1.writeFileSync)(_a.configPath, js_yaml_1.default.dump((0, utils_1.deepClone)(this.config)));
89
+ (0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump((0, utils_1.deepClone)(this.config)));
90
90
  }
91
91
  updateAccount(uin, config) {
92
92
  if (typeof uin !== "number")
@@ -112,7 +112,7 @@ class App extends koa_1.default {
112
112
  oneBot.stop(force);
113
113
  delete this.config[uin];
114
114
  this.oneBots.splice(currentIdx, 1);
115
- (0, fs_1.writeFileSync)(_a.configPath, js_yaml_1.default.dump(this.config));
115
+ (0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(this.config));
116
116
  }
117
117
  createOneBot(uin, config) {
118
118
  const oneBot = new onebot_1.OneBot(this, uin, config);
@@ -132,11 +132,11 @@ class App extends koa_1.default {
132
132
  });
133
133
  this.router.get('/qrcode', (ctx) => {
134
134
  const { uin } = ctx.query;
135
- const uinUrl = path.join(_a.configDir, 'data', uin);
135
+ const uinUrl = path.join(App.configDir, 'data', uin);
136
136
  if (!(0, fs_1.existsSync)(uinUrl)) {
137
137
  return ctx.res.writeHead(400).end('未登录');
138
138
  }
139
- const qrcodePath = path.join(_a.configDir, 'data', uin, 'qrcode.png');
139
+ const qrcodePath = path.join(App.configDir, 'data', uin, 'qrcode.png');
140
140
  let file = null;
141
141
  try {
142
142
  file = (0, fs_2.readFileSync)(qrcodePath); //读取文件
@@ -243,4 +243,4 @@ exports.defineConfig = defineConfig;
243
243
  },
244
244
  log_level: 'info',
245
245
  };
246
- })(App || (exports.App = App = {}));
246
+ })(App = exports.App || (exports.App = {}));
@@ -5,5 +5,5 @@ import { WebSocketServer } from "ws";
5
5
  import http from "http";
6
6
  export declare class Router extends KoaRouter {
7
7
  wsStack: WebSocketServer[];
8
- ws(path: string, server: http.Server): import("ws").Server<typeof import("ws"), typeof http.IncomingMessage>;
8
+ ws(path: string, server: http.Server): import("ws").Server<import("ws").WebSocket>;
9
9
  }
@@ -16,7 +16,7 @@ export declare class CommonAction {
16
16
  * 获取消息
17
17
  * @param message_id {string} 消息id
18
18
  */
19
- getMsg(this: V11, message_id: number): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
19
+ getMsg(this: V11, message_id: string): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
20
20
  /**
21
21
  * 获取合并消息
22
22
  * @param id {string} 合并id
@@ -25,8 +25,7 @@ class CommonAction {
25
25
  * @param message_id {string} 消息id
26
26
  */
27
27
  getMsg(message_id) {
28
- const messageId = this.db.get(`KVMap.${message_id}`);
29
- return this.client.getMsg(messageId);
28
+ return this.client.getMsg(message_id);
30
29
  }
31
30
  /**
32
31
  * 获取合并消息
@@ -8,7 +8,7 @@ export declare class FriendAction {
8
8
  * @param message {import('icqq').Sendable} 发送的消息
9
9
  * @param message_id {string} 引用的消息ID
10
10
  */
11
- sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<import("icqq").MessageRet>;
11
+ sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<void | import("icqq").MessageRet>;
12
12
  /**
13
13
  * 获取好友列表
14
14
  */
@@ -13,9 +13,9 @@ class FriendAction {
13
13
  const msg = message_id ? await this.client.getMsg(message_id) : undefined;
14
14
  const { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, msg]);
15
15
  if (music)
16
- await this.client.pickFriend(user_id).shareMusic(music.data.platform, music.data.id);
16
+ return await this.client.pickFriend(user_id).shareMusic(music.platform, music.id);
17
17
  if (share)
18
- await this.client.pickFriend(user_id).shareUrl(music.data);
18
+ return await this.client.pickFriend(user_id).shareUrl(music.data);
19
19
  if (element.length) {
20
20
  return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
21
21
  }
@@ -7,7 +7,7 @@ export declare class GroupAction {
7
7
  * @param message {import('icqq').Sendable} 消息
8
8
  * @param message_id {string} 引用的消息ID
9
9
  */
10
- sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<import("icqq").MessageRet>;
10
+ sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<void | import("icqq").MessageRet>;
11
11
  /**
12
12
  * 群组踢人
13
13
  * @param group_id {number} 群id
@@ -13,9 +13,9 @@ class GroupAction {
13
13
  const msg = message_id ? await this.client.getMsg(message_id) : undefined;
14
14
  const { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, msg]);
15
15
  if (music)
16
- await this.client.pickGroup(group_id).shareMusic(music.data.platform, music.data.id);
16
+ return await this.client.pickGroup(group_id).shareMusic(music.platform, music.id);
17
17
  if (share)
18
- await this.client.pickGroup(group_id).shareUrl(music.data);
18
+ return await this.client.pickGroup(group_id).shareUrl(music.data);
19
19
  if (element.length) {
20
20
  return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
21
21
  }
@@ -42,6 +42,7 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
42
42
  stop(force?: boolean): Promise<void>;
43
43
  format(_: any, data: any): any;
44
44
  dispatch(data: any): void;
45
+ private _formatEvent;
45
46
  private _httpRequestHandler;
46
47
  /**
47
48
  * 处理ws消息
@@ -224,7 +224,63 @@ class V11 extends events_1.EventEmitter {
224
224
  // if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key)) return value
225
225
  // return value + ''
226
226
  // })
227
- this.emit('dispatch', JSON.stringify(data));
227
+ this.emit('dispatch', this._formatEvent(data));
228
+ }
229
+ _formatEvent(data) {
230
+ if (data.post_type === 'notice') {
231
+ // console.log(JSON.stringify(data))
232
+ const data1 = { ...data };
233
+ if (data.notice_type === 'group') {
234
+ delete data1.group;
235
+ delete data1.member;
236
+ switch (data.sub_type) {
237
+ case 'decrease':
238
+ data1.sub_type = data.operator_id === data.user_id ? 'leave' : data.user_id === this.client.uin ? 'kick_me' : 'kick';
239
+ data1.notice_type = `${data.notice_type}_${data.sub_type}`;
240
+ break;
241
+ case 'increase':
242
+ data1.notice_type = `${data.notice_type}_${data.sub_type}`;
243
+ data1.sub_type = 'approve'; // todo 尚未实现
244
+ data1.operator_id = data1.user_id; // todo 尚未实现
245
+ break;
246
+ case 'ban':
247
+ data1.notice_type = `${data.notice_type}_${data.sub_type}`;
248
+ data1.subtype = data.duration ? 'ban' : 'lift_ban';
249
+ break;
250
+ case 'recall':
251
+ data1.notice_type = `${data.notice_type}_${data.sub_type}`;
252
+ delete data1.sub_type;
253
+ break;
254
+ case 'admin':
255
+ data1.notice_type = `${data.notice_type}_${data.sub_type}`;
256
+ data1.sub_type = data.set ? 'set' : 'unset';
257
+ break;
258
+ case 'poke':
259
+ data1.notice_type = 'notify';
260
+ data1.user_id = data.operator_id;
261
+ break;
262
+ default:
263
+ break;
264
+ }
265
+ }
266
+ else {
267
+ delete data1.friend;
268
+ switch (data.sub_type) {
269
+ case 'increase':
270
+ data1.notice_type = `friend_add`;
271
+ break;
272
+ case 'recall':
273
+ data1.notice_type = `friend_recall`;
274
+ break;
275
+ default:
276
+ break;
277
+ }
278
+ }
279
+ return JSON.stringify(data1);
280
+ }
281
+ else {
282
+ return JSON.stringify(data);
283
+ }
228
284
  }
229
285
  async _httpRequestHandler(ctx) {
230
286
  if (ctx.method === 'OPTIONS') {
@@ -412,6 +468,8 @@ class V11 extends events_1.EventEmitter {
412
468
  else
413
469
  throw new Error('required message_type or input (user_id/group_id)');
414
470
  }
471
+ if (action === 'send_like')
472
+ action = 'send_user_like';
415
473
  const method = (0, utils_1.toHump)(action);
416
474
  if (Reflect.has(this.action, method)) {
417
475
  const ARGS = String(Reflect.get(this.action, method)).match(/\(.*\)/)?.[0]
@@ -426,9 +484,16 @@ class V11 extends events_1.EventEmitter {
426
484
  params[k] = (0, utils_1.toBool)(params[k]);
427
485
  if (k === 'message') {
428
486
  if (typeof params[k] === 'string') {
487
+ if (/[CQ:music,type=.+,id=.+]/.test(params[k])) {
488
+ params[k] = params[k].replace(',type=', ',platform=');
489
+ }
429
490
  params[k] = (0, icqq_cq_enable_1.fromCqcode)(params[k]);
430
491
  }
431
492
  else {
493
+ if (params[k][0].type == 'music' && params[k][0]?.data?.type) {
494
+ params[k][0].data.platform = params[k][0].data.type;
495
+ delete params[k][0].data.type;
496
+ }
432
497
  params[k] = (0, icqq_cq_enable_1.fromSegment)(params[k]);
433
498
  }
434
499
  params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
@@ -540,4 +605,4 @@ exports.V11 = V11;
540
605
  };
541
606
  }
542
607
  V11.genMetaEvent = genMetaEvent;
543
- })(V11 || (exports.V11 = V11 = {}));
608
+ })(V11 = exports.V11 || (exports.V11 = {}));
@@ -728,4 +728,4 @@ exports.V12 = V12;
728
728
  };
729
729
  }
730
730
  V12.formatPayload = formatPayload;
731
- })(V12 || (exports.V12 = V12 = {}));
731
+ })(V12 = exports.V12 || (exports.V12 = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.15",
3
+ "version": "0.4.17",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"