onebots 0.4.0 → 0.4.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/lib/onebot.js +1 -1
- package/lib/server/app.js +2 -3
- package/lib/server/router.d.ts +1 -1
- package/lib/service/V11/index.d.ts +2 -1
- package/lib/service/V11/index.js +6 -5
- package/lib/service/V11/utils.js +16 -8
- package/lib/service/V12/index.d.ts +2 -1
- package/lib/service/V12/index.js +13 -13
- package/lib/service/V12/utils.js +2 -0
- package/package.json +1 -1
package/lib/onebot.js
CHANGED
|
@@ -196,5 +196,5 @@ var OneBotStatus;
|
|
|
196
196
|
(function (OneBotStatus) {
|
|
197
197
|
OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
|
|
198
198
|
OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
|
|
199
|
-
})(OneBotStatus
|
|
199
|
+
})(OneBotStatus || (exports.OneBotStatus = OneBotStatus = {}));
|
|
200
200
|
exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
|
package/lib/server/app.js
CHANGED
|
@@ -202,10 +202,10 @@ class App extends koa_1.default {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
+
exports.App = App;
|
|
205
206
|
_a = App;
|
|
206
207
|
App.configDir = path.join(os.homedir(), '.onebots');
|
|
207
208
|
App.configPath = path.join(_a.configDir, 'config.yaml');
|
|
208
|
-
exports.App = App;
|
|
209
209
|
function createApp(config = 'config.yaml') {
|
|
210
210
|
if (typeof config === 'string') {
|
|
211
211
|
config = path.resolve(process.cwd(), config);
|
|
@@ -241,5 +241,4 @@ exports.defineConfig = defineConfig;
|
|
|
241
241
|
},
|
|
242
242
|
log_level: 'info',
|
|
243
243
|
};
|
|
244
|
-
})(App
|
|
245
|
-
exports.App = App;
|
|
244
|
+
})(App || (exports.App = App = {}));
|
package/lib/server/router.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { WebSocketServer } from "ws";
|
|
|
5
5
|
import http from "http";
|
|
6
6
|
export declare class Router extends KoaRouter {
|
|
7
7
|
wsStack: WebSocketServer[];
|
|
8
|
-
ws(path: string, server: http.Server): import("ws").Server<import("ws").
|
|
8
|
+
ws(path: string, server: http.Server): import("ws").Server<typeof import("ws"), typeof http.IncomingMessage>;
|
|
9
9
|
}
|
|
@@ -43,7 +43,7 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
|
|
|
43
43
|
/**
|
|
44
44
|
* 创建反向ws
|
|
45
45
|
*/
|
|
46
|
-
protected _createWsr(url: string):
|
|
46
|
+
protected _createWsr(url: string): void;
|
|
47
47
|
/**
|
|
48
48
|
* 快速操作
|
|
49
49
|
*/
|
|
@@ -83,6 +83,7 @@ export declare namespace V11 {
|
|
|
83
83
|
access_token?: string;
|
|
84
84
|
post_timeout?: number;
|
|
85
85
|
enable_cors?: boolean;
|
|
86
|
+
enable_reissue?: boolean;
|
|
86
87
|
rate_limit_interval?: number;
|
|
87
88
|
post_message_format?: 'string' | 'array';
|
|
88
89
|
heartbeat?: number;
|
package/lib/service/V11/index.js
CHANGED
|
@@ -161,12 +161,13 @@ class V11 extends events_1.EventEmitter {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
startWsReverse(url) {
|
|
164
|
-
|
|
164
|
+
this._createWsr(url);
|
|
165
165
|
this.on('dispatch', (serialized) => {
|
|
166
|
-
|
|
166
|
+
for (const ws of this.wsr) {
|
|
167
167
|
ws.send(serialized, (err) => {
|
|
168
|
-
if (err)
|
|
168
|
+
if (err) {
|
|
169
169
|
this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
|
|
170
|
+
}
|
|
170
171
|
else
|
|
171
172
|
this.logger.debug(`反向WS(${ws.url})上报事件成功: ` + serialized);
|
|
172
173
|
});
|
|
@@ -331,7 +332,6 @@ class V11 extends events_1.EventEmitter {
|
|
|
331
332
|
this._createWsr(url);
|
|
332
333
|
}, this.config.reconnect_interval * 1000);
|
|
333
334
|
});
|
|
334
|
-
return ws;
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
337
337
|
* 快速操作
|
|
@@ -491,6 +491,7 @@ exports.V11 = V11;
|
|
|
491
491
|
reconnect_interval: 3,
|
|
492
492
|
use_http: true,
|
|
493
493
|
enable_cors: true,
|
|
494
|
+
enable_reissue: false,
|
|
494
495
|
use_ws: true,
|
|
495
496
|
http_reverse: [],
|
|
496
497
|
ws_reverse: []
|
|
@@ -505,4 +506,4 @@ exports.V11 = V11;
|
|
|
505
506
|
};
|
|
506
507
|
}
|
|
507
508
|
V11.genMetaEvent = genMetaEvent;
|
|
508
|
-
})(V11
|
|
509
|
+
})(V11 || (exports.V11 = V11 = {}));
|
package/lib/service/V11/utils.js
CHANGED
|
@@ -4,16 +4,24 @@ exports.processMessage = void 0;
|
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const utils_2 = require("icqq-cq-enable/lib/utils");
|
|
6
6
|
async function processMessage(message, source) {
|
|
7
|
-
const
|
|
8
|
-
let quote =
|
|
7
|
+
const elements = typeof message === 'string' ? (0, utils_2.fromCqcode)(message) : (0, utils_2.fromSegment)(message);
|
|
8
|
+
let quote = elements.find(e => e.type === 'reply');
|
|
9
9
|
if (quote)
|
|
10
|
-
(0, utils_1.remove)(
|
|
11
|
-
let music =
|
|
10
|
+
(0, utils_1.remove)(elements, quote);
|
|
11
|
+
let music = elements.find(e => e.type === 'music');
|
|
12
12
|
if (music)
|
|
13
|
-
(0, utils_1.remove)(
|
|
14
|
-
let share =
|
|
13
|
+
(0, utils_1.remove)(elements, music);
|
|
14
|
+
let share = elements.find(e => e.type === 'share');
|
|
15
15
|
if (share)
|
|
16
|
-
(0, utils_1.remove)(
|
|
17
|
-
|
|
16
|
+
(0, utils_1.remove)(elements, share);
|
|
17
|
+
for (const element of elements) {
|
|
18
|
+
if (['image', 'video', 'audio'].includes(element.type)) {
|
|
19
|
+
if (element['file_id']?.startsWith('base64://'))
|
|
20
|
+
element['file_id'] = Buffer.from(element['file_id'].slice(9), 'base64');
|
|
21
|
+
if (element['file']?.startsWith('base64://'))
|
|
22
|
+
element['file'] = Buffer.from(element['file'].slice(9), 'base64');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { element: elements, quote: quote || source, share, music };
|
|
18
26
|
}
|
|
19
27
|
exports.processMessage = processMessage;
|
|
@@ -53,7 +53,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
53
53
|
/**
|
|
54
54
|
* 创建反向ws
|
|
55
55
|
*/
|
|
56
|
-
protected _createWsr(url: string, config: V12.WsReverseConfig):
|
|
56
|
+
protected _createWsr(url: string, config: V12.WsReverseConfig): void;
|
|
57
57
|
/**
|
|
58
58
|
* 处理ws消息
|
|
59
59
|
*/
|
|
@@ -138,6 +138,7 @@ export declare namespace V12 {
|
|
|
138
138
|
request_timeout?: number;
|
|
139
139
|
reconnect_interval?: number;
|
|
140
140
|
enable_cors?: boolean;
|
|
141
|
+
enable_reissue?: boolean;
|
|
141
142
|
use_http?: boolean | HttpConfig;
|
|
142
143
|
webhook?: (string | WebhookConfig)[];
|
|
143
144
|
use_ws?: boolean | WsConfig;
|
package/lib/service/V12/index.js
CHANGED
|
@@ -270,10 +270,10 @@ class V12 extends events_1.EventEmitter {
|
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
272
|
startWsReverse(config) {
|
|
273
|
-
|
|
273
|
+
this._createWsr(config.url, config);
|
|
274
274
|
this.on('dispatch', (unserialized) => {
|
|
275
275
|
const serialized = JSON.stringify(unserialized);
|
|
276
|
-
|
|
276
|
+
for (const ws of this.wsr) {
|
|
277
277
|
ws.send(serialized, (err) => {
|
|
278
278
|
if (err)
|
|
279
279
|
this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
|
|
@@ -340,14 +340,13 @@ class V12 extends events_1.EventEmitter {
|
|
|
340
340
|
data.detail_type = data.message_type || data.notice_type || data.request_type || data.system_type;
|
|
341
341
|
data.message = data.type === 'message' ? V12.toSegment(data.message) : data.message;
|
|
342
342
|
if (data.source)
|
|
343
|
-
data.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
343
|
+
data.source = {
|
|
344
|
+
...data.source,
|
|
345
|
+
message_id: data.detail_type === 'private' ?
|
|
346
|
+
(0, message_1.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.time) :
|
|
347
|
+
(0, message_1.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time),
|
|
348
|
+
user_id: data.source.user_id,
|
|
349
|
+
message: data.source.message,
|
|
351
350
|
};
|
|
352
351
|
return V12.formatPayload(this.oneBot.uin, event, data);
|
|
353
352
|
}
|
|
@@ -380,7 +379,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
380
379
|
action = "send_" + params.detail_type + "_msg";
|
|
381
380
|
}
|
|
382
381
|
else if (params.user_id)
|
|
383
|
-
action = "
|
|
382
|
+
action = "send_private_Msg";
|
|
384
383
|
else if (params.group_id)
|
|
385
384
|
action = "send_group_msg";
|
|
386
385
|
else if (params.discuss_id)
|
|
@@ -407,6 +406,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
407
406
|
}
|
|
408
407
|
let ret, result;
|
|
409
408
|
try {
|
|
409
|
+
console.log(method, args);
|
|
410
410
|
ret = this.action[method].apply(this, args);
|
|
411
411
|
}
|
|
412
412
|
catch (e) {
|
|
@@ -541,7 +541,6 @@ class V12 extends events_1.EventEmitter {
|
|
|
541
541
|
this.startWsReverse(config);
|
|
542
542
|
}, this.config.reconnect_interval * 1000);
|
|
543
543
|
});
|
|
544
|
-
return ws;
|
|
545
544
|
}
|
|
546
545
|
/**
|
|
547
546
|
* 处理ws消息
|
|
@@ -657,6 +656,7 @@ exports.V12 = V12;
|
|
|
657
656
|
request_timeout: 15,
|
|
658
657
|
reconnect_interval: 3,
|
|
659
658
|
enable_cors: true,
|
|
659
|
+
enable_reissue: false,
|
|
660
660
|
use_http: true,
|
|
661
661
|
use_ws: true,
|
|
662
662
|
webhook: [],
|
|
@@ -693,4 +693,4 @@ exports.V12 = V12;
|
|
|
693
693
|
};
|
|
694
694
|
}
|
|
695
695
|
V12.formatPayload = formatPayload;
|
|
696
|
-
})(V12
|
|
696
|
+
})(V12 || (exports.V12 = V12 = {}));
|
package/lib/service/V12/utils.js
CHANGED
|
@@ -31,6 +31,8 @@ async function processMessage(message, source) {
|
|
|
31
31
|
const fileInfo = this.getFile(file_id);
|
|
32
32
|
if (fileInfo)
|
|
33
33
|
seg.data['file_id'] = fileInfo.url || fileInfo.path || `base64://${fileInfo.data}`;
|
|
34
|
+
if (seg.data['file_id']?.startsWith('base64://'))
|
|
35
|
+
seg.data['file_id'] = Buffer.from(seg.data['file_id'].slice(9), 'base64');
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
38
|
const element = V12_1.V12.fromSegment(segments);
|