onebots 0.4.40 → 0.4.41
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/server/app.js +2 -2
- package/lib/service/V12/index.js +4 -4
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +21 -1
- package/package.json +1 -1
package/lib/server/app.js
CHANGED
|
@@ -180,7 +180,7 @@ class App extends koa_1.default {
|
|
|
180
180
|
process_1.default.on('disconnect', () => {
|
|
181
181
|
fs.unwatchFile(App.logFile, fileListener);
|
|
182
182
|
});
|
|
183
|
-
this.ws.on('connection', (client) => {
|
|
183
|
+
this.ws.on('connection', async (client) => {
|
|
184
184
|
client.send(JSON.stringify({
|
|
185
185
|
event: 'system.sync',
|
|
186
186
|
data: {
|
|
@@ -189,7 +189,7 @@ class App extends koa_1.default {
|
|
|
189
189
|
return adapter.info;
|
|
190
190
|
}),
|
|
191
191
|
app: this.info,
|
|
192
|
-
logs: fs.existsSync(App.logFile) ?
|
|
192
|
+
logs: fs.existsSync(App.logFile) ? await (0, utils_1.readLine)(100, App.logFile, 'utf8') : ''
|
|
193
193
|
}
|
|
194
194
|
}));
|
|
195
195
|
client.on('message', async (raw) => {
|
package/lib/service/V12/index.js
CHANGED
|
@@ -359,9 +359,9 @@ class V12 extends service_1.Service {
|
|
|
359
359
|
id: (0, utils_2.uuid)(),
|
|
360
360
|
impl: 'onebots',
|
|
361
361
|
version: 12,
|
|
362
|
-
platform:
|
|
362
|
+
platform: this.oneBot.platform,
|
|
363
363
|
self: {
|
|
364
|
-
platform:
|
|
364
|
+
platform: this.oneBot.platform,
|
|
365
365
|
user_id: `${this.oneBot.uin}`
|
|
366
366
|
},
|
|
367
367
|
};
|
|
@@ -372,7 +372,7 @@ class V12 extends service_1.Service {
|
|
|
372
372
|
}), {
|
|
373
373
|
self_id: `${this.oneBot.uin}`,
|
|
374
374
|
self: {
|
|
375
|
-
platform:
|
|
375
|
+
platform: this.oneBot.platform,
|
|
376
376
|
user_id: `${this.oneBot.uin}`
|
|
377
377
|
},
|
|
378
378
|
});
|
|
@@ -579,7 +579,7 @@ class V12 extends service_1.Service {
|
|
|
579
579
|
const headers = {
|
|
580
580
|
"X-Self-ID": String(this.oneBot.uin),
|
|
581
581
|
"X-Client-Role": "Universal",
|
|
582
|
-
"User-Agent":
|
|
582
|
+
"User-Agent": `OneBot/12 (${this.oneBot.platform}) Node-onebots/V12`,
|
|
583
583
|
"Sec-WebSocket-Protocol": "12.onebots.v" + utils_1.version
|
|
584
584
|
};
|
|
585
585
|
if (config.access_token)
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Dict } from "@zhinjs/shared";
|
|
3
|
+
import * as fs from "fs";
|
|
2
4
|
export declare const version: any;
|
|
5
|
+
export declare function readLine(maxLen: number, ...params: Parameters<typeof fs.createReadStream>): Promise<string[]>;
|
|
3
6
|
export declare function deepMerge(base: any, ...from: any[]): any;
|
|
4
7
|
export declare function transformObj(obj: any, callback: any): any;
|
|
5
8
|
export declare function deepClone<T extends any>(obj: T): T;
|
package/lib/utils.js
CHANGED
|
@@ -23,10 +23,30 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.stringifyObj = exports.parseObjFromStr = exports.getDataKeyOfObj = exports.getValueOfObj = exports.setValueToObj = exports.getProperties = exports.protectedFields = exports.randomInt = exports.uuid = exports.toBool = exports.remove = exports.toHump = exports.Mixin = exports.toLine = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = exports.version = void 0;
|
|
26
|
+
exports.stringifyObj = exports.parseObjFromStr = exports.getDataKeyOfObj = exports.getValueOfObj = exports.setValueToObj = exports.getProperties = exports.protectedFields = exports.randomInt = exports.uuid = exports.toBool = exports.remove = exports.toHump = exports.Mixin = exports.toLine = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = exports.readLine = exports.version = void 0;
|
|
27
27
|
const crypto = __importStar(require("crypto"));
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const readline = __importStar(require("readline"));
|
|
28
30
|
const packageJson = require('../package.json');
|
|
29
31
|
exports.version = packageJson.version;
|
|
32
|
+
function readLine(maxLen, ...params) {
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
const result = [];
|
|
35
|
+
const rl = readline.createInterface({
|
|
36
|
+
input: fs.createReadStream(...params),
|
|
37
|
+
crlfDelay: Infinity
|
|
38
|
+
});
|
|
39
|
+
rl.on('line', (line) => {
|
|
40
|
+
result.push(line);
|
|
41
|
+
if (result.length > maxLen)
|
|
42
|
+
result.shift();
|
|
43
|
+
});
|
|
44
|
+
rl.on('close', () => {
|
|
45
|
+
resolve(result);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.readLine = readLine;
|
|
30
50
|
// 合并对象/数组
|
|
31
51
|
function deepMerge(base, ...from) {
|
|
32
52
|
if (base === null || base === undefined)
|