onebots 0.1.3 → 0.1.5

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/onebot.js CHANGED
@@ -22,8 +22,7 @@ class OneBot extends events_1.EventEmitter {
22
22
  super();
23
23
  this.app = app;
24
24
  this.uin = uin;
25
- if (!Array.isArray(config))
26
- config = new Array(config);
25
+ config = [].concat(config);
27
26
  this.config = config.map(c => {
28
27
  if (c.password)
29
28
  this.password = c.password;
@@ -31,9 +30,9 @@ class OneBot extends events_1.EventEmitter {
31
30
  c.version = 'V11';
32
31
  switch (c.version) {
33
32
  case 'V11':
34
- return (0, utils_1.deepMerge)(this.app.config.general.V11, c);
33
+ return (0, utils_1.deepMerge)((0, utils_1.deepClone)(this.app.config.general.V11), c);
35
34
  case 'V12':
36
- return (0, utils_1.deepMerge)(this.app.config.general.V12, c);
35
+ return (0, utils_1.deepMerge)((0, utils_1.deepClone)(this.app.config.general.V12), c);
37
36
  default:
38
37
  throw new Error('不支持的oneBot版本:' + c.version);
39
38
  }
@@ -83,17 +83,17 @@ class CommonAction {
83
83
  callLogin(func, ...args) {
84
84
  return new Promise(async (resolve) => {
85
85
  const receiveResult = (event) => {
86
- this.client.off('system.login.qrcode', receiveResult);
87
- this.client.off('system.login.device', receiveResult);
88
- this.client.off('system.login.slider', receiveResult);
89
- this.client.off('system.login.error', receiveResult);
86
+ this.client.offTrap('system.login.qrcode', receiveResult);
87
+ this.client.offTrap('system.login.device', receiveResult);
88
+ this.client.offTrap('system.login.slider', receiveResult);
89
+ this.client.offTrap('system.login.error', receiveResult);
90
90
  resolve(event);
91
91
  };
92
- this.client.on('system.login.qrcode', receiveResult);
93
- this.client.on('system.login.device', receiveResult);
94
- this.client.on('system.login.slider', receiveResult);
95
- this.client.on('system.login.error', receiveResult);
96
- this.client.once('system.online', receiveResult);
92
+ this.client.trap('system.login.qrcode', receiveResult);
93
+ this.client.trap('system.login.device', receiveResult);
94
+ this.client.trap('system.login.slider', receiveResult);
95
+ this.client.trap('system.login.error', receiveResult);
96
+ this.client.trapOnce('system.online', receiveResult);
97
97
  try {
98
98
  await this.client[func](...args);
99
99
  }
@@ -112,16 +112,16 @@ class CommonAction {
112
112
  return new Promise(resolve => {
113
113
  const receiveResult = (e) => {
114
114
  const callback = (data) => {
115
- this.client.off('internal.verbose', receiveResult);
116
- this.client.off('system.login.error', receiveResult);
115
+ this.client.offTrap('internal.verbose', receiveResult);
116
+ this.client.offTrap('system.login.error', receiveResult);
117
117
  resolve(data);
118
118
  };
119
119
  if ((typeof e === 'string' && e.includes('已发送')) || typeof e !== 'string') {
120
120
  callback(e);
121
121
  }
122
122
  };
123
- this.client.on('internal.verbose', receiveResult);
124
- this.client.on('system.login.error', receiveResult);
123
+ this.client.trap('internal.verbose', receiveResult);
124
+ this.client.trap('system.login.error', receiveResult);
125
125
  this.client.sendSmsCode();
126
126
  });
127
127
  }
@@ -131,10 +131,10 @@ class CommonAction {
131
131
  logout(keepalive) {
132
132
  return new Promise(async (resolve) => {
133
133
  const receiveResult = (e) => {
134
- this.client.off('system.offline', receiveResult);
134
+ this.client.offTrap('system.offline', receiveResult);
135
135
  resolve(e);
136
136
  };
137
- this.client.on('system.offline', receiveResult);
137
+ this.client.trap('system.offline', receiveResult);
138
138
  await this.client.logout(keepalive);
139
139
  });
140
140
  }
@@ -19,7 +19,7 @@ export declare class CommonAction {
19
19
  * 获取 Cookies
20
20
  * @param domain {string} 域名
21
21
  */
22
- getCookies(this: V11, domain: string): any;
22
+ getCookies(this: V11, domain: string): string;
23
23
  getStatus(this: V12): {
24
24
  good: boolean;
25
25
  bots: {
@@ -31,14 +31,14 @@ export declare class CommonAction {
31
31
  getVersion(this: V12): {
32
32
  impl: string;
33
33
  platform: string;
34
- version: string;
34
+ version: any;
35
35
  onebot_version: string;
36
36
  };
37
37
  callLogin(this: V12, func: string, ...args: any[]): Promise<unknown>;
38
38
  submitSlider(this: V12, ticket: string): Promise<any>;
39
39
  submitSmsCode(this: V12, code: string): Promise<any>;
40
40
  sendSmsCode(this: V12): Promise<any>;
41
- login(this: V12, password?: string): any;
41
+ login(this: V12, password?: string): Promise<unknown>;
42
42
  logout(this: V12, keepalive?: boolean): Promise<unknown>;
43
43
  getSupportedActions(this: V12): string[];
44
44
  }
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonAction = void 0;
4
4
  const icqq_1 = require("icqq");
5
- const onebot_1 = require("../../../onebot");
6
5
  const utils_1 = require("../../../utils");
6
+ const onebot_1 = require("../../../onebot");
7
+ const utils_2 = require("../../../utils");
7
8
  class CommonAction {
8
9
  sendMessage() { }
9
10
  /**
@@ -51,24 +52,24 @@ class CommonAction {
51
52
  return {
52
53
  impl: 'onebots',
53
54
  platform: 'qq',
54
- version: '0.0.15',
55
+ version: utils_1.version,
55
56
  onebot_version: '12'
56
57
  };
57
58
  }
58
59
  callLogin(func, ...args) {
59
60
  return new Promise(async (resolve) => {
60
61
  const receiveResult = (event) => {
61
- this.client.off('system.login.qrcode', receiveResult);
62
- this.client.off('system.login.device', receiveResult);
63
- this.client.off('system.login.slider', receiveResult);
64
- this.client.off('system.login.error', receiveResult);
62
+ this.client.offTrap('system.login.qrcode', receiveResult);
63
+ this.client.offTrap('system.login.device', receiveResult);
64
+ this.client.offTrap('system.login.slider', receiveResult);
65
+ this.client.offTrap('system.login.error', receiveResult);
65
66
  resolve(event);
66
67
  };
67
- this.client.on('system.login.qrcode', receiveResult);
68
- this.client.on('system.login.device', receiveResult);
69
- this.client.on('system.login.slider', receiveResult);
70
- this.client.on('system.login.error', receiveResult);
71
- this.client.once('system.online', receiveResult);
68
+ this.client.trap('system.login.qrcode', receiveResult);
69
+ this.client.trap('system.login.device', receiveResult);
70
+ this.client.trap('system.login.slider', receiveResult);
71
+ this.client.trap('system.login.error', receiveResult);
72
+ this.client.trapOnce('system.online', receiveResult);
72
73
  try {
73
74
  await this.client[func](...args);
74
75
  }
@@ -87,16 +88,16 @@ class CommonAction {
87
88
  return new Promise(resolve => {
88
89
  const receiveResult = (e) => {
89
90
  const callback = (data) => {
90
- this.client.off('internal.verbose', receiveResult);
91
- this.client.off('system.login.error', receiveResult);
91
+ this.client.offTrap('internal.verbose', receiveResult);
92
+ this.client.offTrap('system.login.error', receiveResult);
92
93
  resolve(data);
93
94
  };
94
95
  if ((typeof e === 'string' && e.includes('已发送')) || typeof e !== 'string') {
95
96
  callback(e);
96
97
  }
97
98
  };
98
- this.client.on('internal.verbose', receiveResult);
99
- this.client.on('system.login.error', receiveResult);
99
+ this.client.trap('internal.verbose', receiveResult);
100
+ this.client.trap('system.login.error', receiveResult);
100
101
  this.client.sendSmsCode();
101
102
  });
102
103
  }
@@ -106,7 +107,7 @@ class CommonAction {
106
107
  logout(keepalive) {
107
108
  return new Promise(async (resolve) => {
108
109
  const receiveResult = (e) => {
109
- this.client.off('system.offline', receiveResult);
110
+ this.client.offTrap('system.offline', receiveResult);
110
111
  resolve(e);
111
112
  };
112
113
  this.client.on('system.offline', receiveResult);
@@ -114,9 +115,9 @@ class CommonAction {
114
115
  });
115
116
  }
116
117
  getSupportedActions() {
117
- return [...new Set((0, utils_1.getProperties)(this.action))].filter(key => {
118
+ return [...new Set((0, utils_2.getProperties)(this.action))].filter(key => {
118
119
  return key !== 'constructor';
119
- }).map(utils_1.toLine);
120
+ }).map(utils_2.toLine);
120
121
  }
121
122
  }
122
123
  exports.CommonAction = CommonAction;
@@ -14,6 +14,16 @@ export declare class GroupAction {
14
14
  * @param reject_add_request {boolean} 是否禁止此人加群请求
15
15
  */
16
16
  setGroupKick(this: V12, group_id: number, user_id: number, reject_add_request?: boolean): Promise<boolean>;
17
+ /**
18
+ * 设置群精华
19
+ * @param message_id
20
+ */
21
+ setEssenceMessage(this: V12, message_id: string): Promise<string>;
22
+ /**
23
+ * 移除群精华
24
+ * @param message_id
25
+ */
26
+ deleteEssenceMessage(this: V12, message_id: string): Promise<string>;
17
27
  /**
18
28
  * 群禁言指定人
19
29
  * @param group_id {number} 群id
@@ -40,6 +40,20 @@ class GroupAction {
40
40
  setGroupKick(group_id, user_id, reject_add_request) {
41
41
  return this.client.setGroupKick(group_id, user_id, reject_add_request);
42
42
  }
43
+ /**
44
+ * 设置群精华
45
+ * @param message_id
46
+ */
47
+ setEssenceMessage(message_id) {
48
+ return this.client.setEssenceMessage(message_id);
49
+ }
50
+ /**
51
+ * 移除群精华
52
+ * @param message_id
53
+ */
54
+ deleteEssenceMessage(message_id) {
55
+ return this.client.removeEssenceMessage(message_id);
56
+ }
43
57
  /**
44
58
  * 群禁言指定人
45
59
  * @param group_id {number} 群id
@@ -1,2 +1,20 @@
1
+ import { V12 } from "../../../service/V12";
2
+ import SegmentElem = V12.SegmentElem;
1
3
  export declare class GuildAction {
4
+ getGuildList(this: V12): {
5
+ guild_id: string;
6
+ guild_name: string;
7
+ }[];
8
+ getChannelList(this: V12, guild_id: string): {
9
+ guild_id: string;
10
+ channel_id: string;
11
+ channel_name: string;
12
+ channel_type: import("icqq/lib/channel").ChannelType;
13
+ }[];
14
+ getGuildMemberList(this: V12, guild_id: string): never[] | Promise<import("icqq/lib/guild").GuildMember[]>;
15
+ sendGuildMsg(this: V12, guild_id: string, channel_id: string, message: SegmentElem[]): Promise<{
16
+ seq: number;
17
+ rand: number;
18
+ time: number;
19
+ }>;
2
20
  }
@@ -1,6 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildAction = void 0;
4
+ const V12_1 = require("../../../service/V12");
5
+ const utils_1 = require("../../../utils");
4
6
  class GuildAction {
7
+ getGuildList() {
8
+ return this.client.getGuildList();
9
+ }
10
+ getChannelList(guild_id) {
11
+ return this.client.getChannelList(guild_id);
12
+ }
13
+ getGuildMemberList(guild_id) {
14
+ return this.client.getGuildMemberList(guild_id);
15
+ }
16
+ async sendGuildMsg(guild_id, channel_id, message) {
17
+ const forward = message.find(e => e.type === 'node');
18
+ if (forward)
19
+ (0, utils_1.remove)(message, forward);
20
+ let quote = message.find(e => e.type === 'reply');
21
+ if (quote)
22
+ (0, utils_1.remove)(message, quote);
23
+ const element = V12_1.V12.fromSegment(message);
24
+ // if(forward) element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment=>{
25
+ // return {
26
+ // message:V12.fromSegment([segment]),
27
+ // user_id:forward.data.user_id,
28
+ // nickname:forward.data.user_name,
29
+ // time:forward.data.time
30
+ // }
31
+ // })))
32
+ // if(quote && !message_id) message_id=quote.data.message_id
33
+ return await this.client.sendGuildMsg(guild_id, channel_id, element);
34
+ }
5
35
  }
6
36
  exports.GuildAction = GuildAction;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.V12 = void 0;
7
7
  const icqq_1 = require("icqq");
8
+ const utils_1 = require("../../utils");
8
9
  const path_1 = require("path");
9
10
  const onebot_1 = require("../../onebot");
10
11
  const action_1 = require("./action");
@@ -13,7 +14,7 @@ const url_1 = require("url");
13
14
  const http_1 = __importDefault(require("http"));
14
15
  const https_1 = __importDefault(require("https"));
15
16
  const ws_1 = require("ws");
16
- const utils_1 = require("../../utils");
17
+ const utils_2 = require("../../utils");
17
18
  const db_1 = require("../../db");
18
19
  const app_1 = require("../../server/app");
19
20
  const fs_1 = require("fs");
@@ -116,7 +117,7 @@ class V12 extends events_1.EventEmitter {
116
117
  timeout: config.timeout || this.config.request_timeout,
117
118
  headers: {
118
119
  "Content-Type": "application/json",
119
- "User-Agent": "OneBot/12 (qq) Node-onebots/0.0.15",
120
+ "User-Agent": "OneBot/12 (qq) Node-onebots/" + utils_1.version,
120
121
  "X-OneBot-Version": 12,
121
122
  "X-Impl": "icqq_onebot",
122
123
  },
@@ -317,7 +318,7 @@ class V12 extends events_1.EventEmitter {
317
318
  }
318
319
  dispatch(data) {
319
320
  const payload = {
320
- id: (0, utils_1.uuid)(),
321
+ id: (0, utils_2.uuid)(),
321
322
  impl: 'icqq_onebot',
322
323
  version: 12,
323
324
  platform: 'qq',
@@ -325,7 +326,7 @@ class V12 extends events_1.EventEmitter {
325
326
  platform: 'qq',
326
327
  user_id: `${this.oneBot.uin}`
327
328
  },
328
- ...(0, utils_1.transformObj)(data, (key, value) => {
329
+ ...(0, utils_2.transformObj)(data, (key, value) => {
329
330
  if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key))
330
331
  return value;
331
332
  return value + '';
@@ -335,7 +336,7 @@ class V12 extends events_1.EventEmitter {
335
336
  }
336
337
  async apply(req) {
337
338
  let { action, params, echo } = req;
338
- action = (0, utils_1.toLine)(action);
339
+ action = (0, utils_2.toLine)(action);
339
340
  let is_async = action.includes("_async");
340
341
  if (is_async)
341
342
  action = action.replace("_async", "");
@@ -354,7 +355,7 @@ class V12 extends events_1.EventEmitter {
354
355
  else
355
356
  throw new Error('required detail_type or input (user_id/group_id/(guild_id and channel_id))');
356
357
  }
357
- const method = (0, utils_1.toHump)(action);
358
+ const method = (0, utils_2.toHump)(action);
358
359
  if (Reflect.has(this.action, method)) {
359
360
  const ARGS = String(Reflect.get(this.action, method)).match(/\(.*\)/)?.[0]
360
361
  .replace("(", "")
@@ -365,7 +366,7 @@ class V12 extends events_1.EventEmitter {
365
366
  for (let k of ARGS) {
366
367
  if (Reflect.has(params, k)) {
367
368
  if (onebot_1.BOOLS.includes(k))
368
- params[k] = (0, utils_1.toBool)(params[k]);
369
+ params[k] = (0, utils_2.toBool)(params[k]);
369
370
  if (k === 'message') {
370
371
  params[k] = V12.fromSegment(params[k]);
371
372
  params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
@@ -484,12 +485,12 @@ class V12 extends events_1.EventEmitter {
484
485
  const headers = {
485
486
  "X-Self-ID": String(this.oneBot.uin),
486
487
  "X-Client-Role": "Universal",
487
- "User-Agent": "OneBot/12 (qq) Node-onebots/0.0.15",
488
- "Sec-WebSocket-Protocol": "12.onebots.v0.0.15"
488
+ "User-Agent": "OneBot/12 (qq) Node-onebots/" + utils_1.version,
489
+ "Sec-WebSocket-Protocol": "12.onebots.v" + utils_1.version
489
490
  };
490
491
  if (config.access_token)
491
492
  headers.Authorization = "Bearer " + config.access_token;
492
- const ws = new ws_1.WebSocket(url, '12.onebots.v0.0.15', { headers });
493
+ const ws = new ws_1.WebSocket(url, '12.onebots.v' + utils_1.version, { headers });
493
494
  ws.on("error", (err) => {
494
495
  this.logger.error(err.message);
495
496
  });
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export declare function deepMerge<T extends any>(base: T, ...from: T[]): T;
1
+ export declare const version: any;
2
+ export declare function deepMerge(base: any, ...from: any[]): any;
2
3
  export declare function transformObj(obj: any, callback: any): any;
3
4
  export declare function deepClone<T extends any>(obj: T): T;
4
5
  export declare function pick<T extends object, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean): Pick<T, K>;
package/lib/utils.js CHANGED
@@ -23,10 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.remove = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = void 0;
26
+ exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.remove = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = exports.version = void 0;
27
27
  const crypto = __importStar(require("crypto"));
28
+ const packageJson = require('../package.json');
29
+ exports.version = packageJson.version;
28
30
  // 合并对象/数组
29
31
  function deepMerge(base, ...from) {
32
+ if (base === null || base === undefined)
33
+ base = from.shift();
30
34
  if (from.length === 0) {
31
35
  return base;
32
36
  }
@@ -34,22 +38,19 @@ function deepMerge(base, ...from) {
34
38
  return base;
35
39
  }
36
40
  if (Array.isArray(base)) {
37
- return base.concat(...from);
41
+ return Array.from(new Set(base.concat(...from)));
38
42
  }
39
43
  for (const item of from) {
40
44
  for (const key in item) {
41
45
  if (base.hasOwnProperty(key)) {
42
46
  if (typeof base[key] === 'object') {
43
- // @ts-ignore
44
47
  base[key] = deepMerge(base[key], item[key]);
45
48
  }
46
49
  else {
47
- // @ts-ignore
48
50
  base[key] = item[key];
49
51
  }
50
52
  }
51
53
  else {
52
- // @ts-ignore
53
54
  base[key] = item[key];
54
55
  }
55
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@koa/router": "^10.1.1",
53
- "icqq": "^0.0.13-4",
53
+ "icqq": "^0.0.13-7",
54
54
  "icqq-cq-enable": "^1.0.0",
55
55
  "js-yaml": "^4.1.0",
56
56
  "koa": "^2.13.4",