onebots 0.1.4 → 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 +3 -4
- package/lib/service/V12/action/common.d.ts +1 -1
- package/lib/service/V12/action/common.js +5 -4
- package/lib/service/V12/action/group.d.ts +10 -0
- package/lib/service/V12/action/group.js +14 -0
- package/lib/service/V12/index.js +11 -10
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +6 -5
- package/package.json +2 -2
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
|
-
|
|
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
|
}
|
|
@@ -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,7 +52,7 @@ class CommonAction {
|
|
|
51
52
|
return {
|
|
52
53
|
impl: 'onebots',
|
|
53
54
|
platform: 'qq',
|
|
54
|
-
version:
|
|
55
|
+
version: utils_1.version,
|
|
55
56
|
onebot_version: '12'
|
|
56
57
|
};
|
|
57
58
|
}
|
|
@@ -114,9 +115,9 @@ class CommonAction {
|
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
getSupportedActions() {
|
|
117
|
-
return [...new Set((0,
|
|
118
|
+
return [...new Set((0, utils_2.getProperties)(this.action))].filter(key => {
|
|
118
119
|
return key !== 'constructor';
|
|
119
|
-
}).map(
|
|
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
|
package/lib/service/V12/index.js
CHANGED
|
@@ -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
|
|
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/
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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/
|
|
488
|
-
"Sec-WebSocket-Protocol": "12.onebots.
|
|
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.
|
|
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
|
|
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
|
+
"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-
|
|
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",
|