onebots 0.0.1 → 0.0.2
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 +3 -2
- package/lib/server/app.d.ts +1 -1
- package/lib/server/app.js +2 -2
- package/lib/service/V11/index.js +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +13 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
[](https://12.onebot.dev/)
|
|
8
8
|
[](https://nodejs.org)
|
|
9
9
|
[](https://jq.qq.com/?_wv=1027&k=B22VGXov)
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
[Type Docs](https://liucl-cn.github.io/onebots)
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
</p>
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
```shell
|
|
19
20
|
npm init -y
|
|
20
21
|
```
|
|
21
|
-
2.
|
|
22
|
+
2. 安装onebots
|
|
22
23
|
```shell
|
|
23
24
|
npm install onebots
|
|
24
25
|
```
|
package/lib/server/app.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare class App extends Koa {
|
|
|
35
35
|
createOneBot(uin: number, config: MayBeArray<OneBot.Config<OneBot.Version>>): OneBot<OneBot.Version>;
|
|
36
36
|
start(): void;
|
|
37
37
|
}
|
|
38
|
-
export declare function createApp
|
|
38
|
+
export declare function createApp(config?: App.Config | string): App;
|
|
39
39
|
export declare function defineConfig(config: App.Config): App.Config;
|
|
40
40
|
export declare namespace App {
|
|
41
41
|
type Config = {
|
package/lib/server/app.js
CHANGED
|
@@ -128,7 +128,7 @@ class App extends koa_1.default {
|
|
|
128
128
|
ctx.body = this.oneBots.map(bot => {
|
|
129
129
|
return {
|
|
130
130
|
uin: bot.uin,
|
|
131
|
-
config: bot.config,
|
|
131
|
+
config: bot.config.map(c => (0, utils_1.protectedFields)(c, 'password', "access_token")),
|
|
132
132
|
urls: bot.config.map(c => `/${c.version}/${bot.uin}`)
|
|
133
133
|
};
|
|
134
134
|
});
|
|
@@ -156,7 +156,7 @@ class App extends koa_1.default {
|
|
|
156
156
|
const oneBot = this.oneBots.find(bot => bot.uin === Number(uin));
|
|
157
157
|
ctx.body = {
|
|
158
158
|
uin,
|
|
159
|
-
config: oneBot.config,
|
|
159
|
+
config: oneBot.config.map(c => (0, utils_1.protectedFields)(c, 'password', "access_token")),
|
|
160
160
|
urls: oneBot.config.map(c => `/${uin}/${c.version}`)
|
|
161
161
|
};
|
|
162
162
|
});
|
package/lib/service/V11/index.js
CHANGED
|
@@ -228,7 +228,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
228
228
|
*/
|
|
229
229
|
_webSocketHandler(ws) {
|
|
230
230
|
ws.on("message", async (msg) => {
|
|
231
|
-
this.logger.
|
|
231
|
+
this.logger.info(" 收到ws消息:" + msg);
|
|
232
232
|
var data;
|
|
233
233
|
try {
|
|
234
234
|
data = JSON.parse(String(msg));
|
package/lib/utils.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export declare function toHump(action: string): string;
|
|
|
10
10
|
export declare function toLine(name: string): string;
|
|
11
11
|
export declare function toBool(v: any): boolean;
|
|
12
12
|
export declare function uuid(): string;
|
|
13
|
+
export declare function protectedFields<T>(source: T, ...keys: (keyof T)[]): T;
|
|
13
14
|
export declare function getProperties(obj: any): any;
|
package/lib/utils.js
CHANGED
|
@@ -23,9 +23,9 @@ 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.uuid = exports.toBool = exports.toLine = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.deepMerge = void 0;
|
|
27
|
-
// 合并对象/数组
|
|
26
|
+
exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.deepMerge = void 0;
|
|
28
27
|
const crypto = __importStar(require("crypto"));
|
|
28
|
+
// 合并对象/数组
|
|
29
29
|
function deepMerge(base, ...from) {
|
|
30
30
|
if (from.length === 0) {
|
|
31
31
|
return base;
|
|
@@ -40,13 +40,16 @@ function deepMerge(base, ...from) {
|
|
|
40
40
|
for (const key in item) {
|
|
41
41
|
if (base.hasOwnProperty(key)) {
|
|
42
42
|
if (typeof base[key] === 'object') {
|
|
43
|
+
// @ts-ignore
|
|
43
44
|
base[key] = deepMerge(base[key], item[key]);
|
|
44
45
|
}
|
|
45
46
|
else {
|
|
47
|
+
// @ts-ignore
|
|
46
48
|
base[key] = item[key];
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
else {
|
|
52
|
+
// @ts-ignore
|
|
50
53
|
base[key] = item[key];
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -130,6 +133,14 @@ function uuid() {
|
|
|
130
133
|
return hex.substr(0, 8) + "-" + hex.substr(8, 4) + "-" + hex.substr(12, 4) + "-" + hex.substr(16, 4) + "-" + hex.substr(20);
|
|
131
134
|
}
|
|
132
135
|
exports.uuid = uuid;
|
|
136
|
+
function protectedFields(source, ...keys) {
|
|
137
|
+
if (!source || typeof source !== 'object')
|
|
138
|
+
throw new Error('source must is object');
|
|
139
|
+
return Object.fromEntries(Object.entries(source).map(([key, value]) => {
|
|
140
|
+
return [key, keys.includes(key) ? value.split('').map(c => '*').join('') : value];
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
exports.protectedFields = protectedFields;
|
|
133
144
|
function getProperties(obj) {
|
|
134
145
|
if (obj.__proto__ === null) { //说明该对象已经是最顶层的对象
|
|
135
146
|
return [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "基于icqq的多例oneBot实现",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/liucl-cn/
|
|
18
|
+
"url": "git+https://github.com/liucl-cn/onebots.git"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"onebot",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"author": "凉菜",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/liucl-cn/
|
|
28
|
+
"url": "https://github.com/liucl-cn/onebots/issues"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://github.com/liucl-cn/
|
|
30
|
+
"homepage": "https://github.com/liucl-cn/onebots#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/koa": "^2.13.4",
|
|
33
33
|
"@types/koa__router": "^8.0.11",
|