onebots 0.0.13 → 0.0.14
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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OnlineStatus } from "oicq";
|
|
2
1
|
import { V11 } from "../../../service/V11";
|
|
3
2
|
export declare class CommonAction {
|
|
4
3
|
/**
|
|
@@ -54,7 +53,7 @@ export declare class CommonAction {
|
|
|
54
53
|
*/
|
|
55
54
|
setRestart(this: V11, delay: number): boolean;
|
|
56
55
|
getStatus(this: V11): {
|
|
57
|
-
online:
|
|
56
|
+
online: boolean;
|
|
58
57
|
good: boolean;
|
|
59
58
|
};
|
|
60
59
|
callLogin(this: V11, func: string, ...args: any[]): Promise<unknown>;
|
|
@@ -59,11 +59,11 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
|
|
|
59
59
|
export declare namespace V11 {
|
|
60
60
|
interface Result<T extends any> {
|
|
61
61
|
retcode: number;
|
|
62
|
-
status: "
|
|
62
|
+
status: "ok" | 'async' | 'error';
|
|
63
63
|
data: T;
|
|
64
64
|
error: string;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function ok<T extends any>(data: T, retcode?: number, pending?: boolean): Result<T>;
|
|
67
67
|
function error(error: string, retcode?: number): Result<any>;
|
|
68
68
|
const defaultConfig: Config;
|
|
69
69
|
function genMetaEvent(uin: number, type: string): {
|
package/lib/service/V11/index.js
CHANGED
|
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.V11 = void 0;
|
|
7
7
|
const oicq_1 = require("oicq");
|
|
8
8
|
const action_1 = require("./action");
|
|
9
|
+
const onebot_1 = require("../../onebot");
|
|
9
10
|
const ws_1 = require("ws");
|
|
10
11
|
const url_1 = require("url");
|
|
11
12
|
const utils_1 = require("../../utils");
|
|
12
13
|
const oicq2_cq_enable_1 = require("oicq2-cq-enable");
|
|
13
|
-
const
|
|
14
|
+
const onebot_2 = require("../../onebot");
|
|
14
15
|
const http_1 = __importDefault(require("http"));
|
|
15
16
|
const https_1 = __importDefault(require("https"));
|
|
16
17
|
const events_1 = require("events");
|
|
@@ -61,6 +62,10 @@ class V11 extends events_1.EventEmitter {
|
|
|
61
62
|
this.heartbeat = setInterval(() => {
|
|
62
63
|
this.dispatch({
|
|
63
64
|
self_id: this.client.uin,
|
|
65
|
+
status: {
|
|
66
|
+
online: this.client.status === oicq_1.OnlineStatus.Online,
|
|
67
|
+
good: this.oneBot.status === onebot_1.OneBotStatus.Good
|
|
68
|
+
},
|
|
64
69
|
time: Math.floor(Date.now() / 1000),
|
|
65
70
|
post_type: "meta_event",
|
|
66
71
|
meta_event_type: "heartbeat",
|
|
@@ -157,9 +162,14 @@ class V11 extends events_1.EventEmitter {
|
|
|
157
162
|
}
|
|
158
163
|
startWsReverse(url) {
|
|
159
164
|
const ws = this._createWsr(url);
|
|
160
|
-
this.on('dispatch', (
|
|
165
|
+
this.on('dispatch', (serialized) => {
|
|
161
166
|
if (this.wsr.has(ws)) {
|
|
162
|
-
ws.send(
|
|
167
|
+
ws.send(serialized, (err) => {
|
|
168
|
+
if (err)
|
|
169
|
+
this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
|
|
170
|
+
else
|
|
171
|
+
this.logger.debug(`反向WS(${ws.url})上报事件成功: ` + serialized);
|
|
172
|
+
});
|
|
163
173
|
}
|
|
164
174
|
});
|
|
165
175
|
}
|
|
@@ -179,6 +189,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
179
189
|
if (data.message && data.post_type === 'message') {
|
|
180
190
|
data.message = this.config.post_message_format === 'array' ? (0, oicq2_cq_enable_1.toSegment)(data.message) : (0, oicq2_cq_enable_1.toCqcode)(data);
|
|
181
191
|
}
|
|
192
|
+
data.time = Math.floor(Date.now() / 1000);
|
|
182
193
|
this.emit('dispatch', JSON.stringify(data));
|
|
183
194
|
}
|
|
184
195
|
async _httpRequestHandler(ctx) {
|
|
@@ -258,7 +269,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
258
269
|
}
|
|
259
270
|
catch (e) {
|
|
260
271
|
let code, message;
|
|
261
|
-
if (e instanceof
|
|
272
|
+
if (e instanceof onebot_2.NotFoundError) {
|
|
262
273
|
code = 1404;
|
|
263
274
|
message = "不支持的api";
|
|
264
275
|
}
|
|
@@ -375,7 +386,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
375
386
|
const args = [];
|
|
376
387
|
for (let k of ARGS) {
|
|
377
388
|
if (Reflect.has(params, k)) {
|
|
378
|
-
if (
|
|
389
|
+
if (onebot_2.BOOLS.includes(k))
|
|
379
390
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
380
391
|
if (k === 'message') {
|
|
381
392
|
if (typeof params[k] === 'string') {
|
|
@@ -392,7 +403,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
392
403
|
if (is_queue) {
|
|
393
404
|
this._queue.push({ method, args });
|
|
394
405
|
this._runQueue();
|
|
395
|
-
result = V11.
|
|
406
|
+
result = V11.ok(null, 0, true);
|
|
396
407
|
}
|
|
397
408
|
else {
|
|
398
409
|
try {
|
|
@@ -403,14 +414,14 @@ class V11 extends events_1.EventEmitter {
|
|
|
403
414
|
}
|
|
404
415
|
if (ret instanceof Promise) {
|
|
405
416
|
if (is_async) {
|
|
406
|
-
result = V11.
|
|
417
|
+
result = V11.ok(null, 0, true);
|
|
407
418
|
}
|
|
408
419
|
else {
|
|
409
|
-
result = V11.
|
|
420
|
+
result = V11.ok(await ret, 0, false);
|
|
410
421
|
}
|
|
411
422
|
}
|
|
412
423
|
else {
|
|
413
|
-
result = V11.
|
|
424
|
+
result = V11.ok(await ret, 0, false);
|
|
414
425
|
}
|
|
415
426
|
}
|
|
416
427
|
if (result.data instanceof Map)
|
|
@@ -421,7 +432,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
421
432
|
return JSON.stringify(result);
|
|
422
433
|
}
|
|
423
434
|
else
|
|
424
|
-
throw new
|
|
435
|
+
throw new onebot_2.NotFoundError();
|
|
425
436
|
}
|
|
426
437
|
/**
|
|
427
438
|
* 限速队列调用
|
|
@@ -443,15 +454,15 @@ class V11 extends events_1.EventEmitter {
|
|
|
443
454
|
}
|
|
444
455
|
exports.V11 = V11;
|
|
445
456
|
(function (V11) {
|
|
446
|
-
function
|
|
457
|
+
function ok(data, retcode = 0, pending) {
|
|
447
458
|
return {
|
|
448
459
|
retcode,
|
|
449
|
-
status: pending ? 'async' : '
|
|
460
|
+
status: pending ? 'async' : 'ok',
|
|
450
461
|
data,
|
|
451
462
|
error: null
|
|
452
463
|
};
|
|
453
464
|
}
|
|
454
|
-
V11.
|
|
465
|
+
V11.ok = ok;
|
|
455
466
|
function error(error, retcode = 1) {
|
|
456
467
|
return {
|
|
457
468
|
retcode,
|
package/lib/service/V12/index.js
CHANGED
|
@@ -455,7 +455,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
455
455
|
this._quickOperate(event, res);
|
|
456
456
|
ret = JSON.stringify({
|
|
457
457
|
retcode: 0,
|
|
458
|
-
status: "
|
|
458
|
+
status: "success",
|
|
459
459
|
data: null,
|
|
460
460
|
message: null,
|
|
461
461
|
echo: data.echo
|
|
@@ -507,7 +507,7 @@ exports.V12 = V12;
|
|
|
507
507
|
function success(data, retcode = 0, echo) {
|
|
508
508
|
return {
|
|
509
509
|
retcode,
|
|
510
|
-
status: retcode === 0 ? '
|
|
510
|
+
status: retcode === 0 ? 'success' : 'failed',
|
|
511
511
|
data,
|
|
512
512
|
message: '',
|
|
513
513
|
echo
|