onebots 0.4.0 → 0.4.1
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/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 +6 -5
- 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 = {}));
|
|
@@ -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);
|
|
@@ -380,7 +380,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
380
380
|
action = "send_" + params.detail_type + "_msg";
|
|
381
381
|
}
|
|
382
382
|
else if (params.user_id)
|
|
383
|
-
action = "
|
|
383
|
+
action = "send_private_Msg";
|
|
384
384
|
else if (params.group_id)
|
|
385
385
|
action = "send_group_msg";
|
|
386
386
|
else if (params.discuss_id)
|
|
@@ -407,6 +407,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
407
407
|
}
|
|
408
408
|
let ret, result;
|
|
409
409
|
try {
|
|
410
|
+
console.log(method, args);
|
|
410
411
|
ret = this.action[method].apply(this, args);
|
|
411
412
|
}
|
|
412
413
|
catch (e) {
|
|
@@ -541,7 +542,6 @@ class V12 extends events_1.EventEmitter {
|
|
|
541
542
|
this.startWsReverse(config);
|
|
542
543
|
}, this.config.reconnect_interval * 1000);
|
|
543
544
|
});
|
|
544
|
-
return ws;
|
|
545
545
|
}
|
|
546
546
|
/**
|
|
547
547
|
* 处理ws消息
|
|
@@ -657,6 +657,7 @@ exports.V12 = V12;
|
|
|
657
657
|
request_timeout: 15,
|
|
658
658
|
reconnect_interval: 3,
|
|
659
659
|
enable_cors: true,
|
|
660
|
+
enable_reissue: false,
|
|
660
661
|
use_http: true,
|
|
661
662
|
use_ws: true,
|
|
662
663
|
webhook: [],
|
|
@@ -693,4 +694,4 @@ exports.V12 = V12;
|
|
|
693
694
|
};
|
|
694
695
|
}
|
|
695
696
|
V12.formatPayload = formatPayload;
|
|
696
|
-
})(V12
|
|
697
|
+
})(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);
|