@kotori-bot/loader 1.6.3 → 1.6.4
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/class/loader.js +2 -2
- package/lib/class/runner.js +2 -2
- package/lib/constants.js +2 -2
- package/lib/decorators/index.js +2 -2
- package/lib/decorators/plugin.js +2 -2
- package/lib/decorators/utils.js +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -2
- package/lib/service/{adapter.d.ts → adapters.d.ts} +6 -4
- package/lib/service/{adapter.js → adapters.js} +41 -14
- package/lib/service/database.js +2 -2
- package/lib/service/file.js +2 -2
- package/lib/service/server.js +9 -6
- package/lib/types/index.js +2 -2
- package/lib/types/internal.js +2 -2
- package/lib/types/server.js +2 -2
- package/lib/utils/log.js +2 -2
- package/lib/utils/logger.js +2 -2
- package/package.json +1 -1
package/lib/class/loader.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/class/runner.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/constants.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/decorators/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/decorators/plugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/decorators/utils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -30,6 +30,7 @@ __reExport(src_exports, require("./class/loader"), module.exports);
|
|
|
30
30
|
__reExport(src_exports, require("./constants"), module.exports);
|
|
31
31
|
__reExport(src_exports, require("./decorators"), module.exports);
|
|
32
32
|
__reExport(src_exports, require("./types"), module.exports);
|
|
33
|
+
__reExport(src_exports, require("./service/adapters"), module.exports);
|
|
33
34
|
__reExport(src_exports, require("@kotori-bot/logger"), module.exports);
|
|
34
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
36
|
0 && (module.exports = {
|
|
@@ -37,5 +38,6 @@ __reExport(src_exports, require("@kotori-bot/logger"), module.exports);
|
|
|
37
38
|
...require("./constants"),
|
|
38
39
|
...require("./decorators"),
|
|
39
40
|
...require("./types"),
|
|
41
|
+
...require("./service/adapters"),
|
|
40
42
|
...require("@kotori-bot/logger")
|
|
41
43
|
});
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Api, Adapter as OriginAdapter } from '@kotori-bot/core';
|
|
2
2
|
import { WsRouteHandler } from '../types/server';
|
|
3
|
-
export declare namespace
|
|
4
|
-
abstract class WebSocket<T extends Api = Api> extends OriginAdapter<T> {
|
|
3
|
+
export declare namespace Adapters {
|
|
4
|
+
abstract class WebSocket<T extends Api = Api, D extends object = object> extends OriginAdapter<T> {
|
|
5
5
|
private isSetup;
|
|
6
6
|
private destroyFn?;
|
|
7
|
+
private wssPath;
|
|
8
|
+
private wssAddress;
|
|
7
9
|
protected destroy(): void;
|
|
8
10
|
protected setup(): void;
|
|
9
|
-
abstract handle
|
|
11
|
+
abstract handle(data: D): void;
|
|
10
12
|
connection?: (ws: Parameters<WsRouteHandler>[0], req: Parameters<WsRouteHandler>[1]) => void;
|
|
11
13
|
start(): void;
|
|
12
14
|
stop(): void;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
|
-
export default
|
|
17
|
+
export default Adapters;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -27,18 +27,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
27
27
|
return to;
|
|
28
28
|
};
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
32
|
-
|
|
33
|
-
default: () =>
|
|
30
|
+
var adapters_exports = {};
|
|
31
|
+
__export(adapters_exports, {
|
|
32
|
+
Adapters: () => Adapters,
|
|
33
|
+
default: () => adapters_default
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(adapters_exports);
|
|
36
36
|
var import_core = require("@kotori-bot/core");
|
|
37
|
-
var
|
|
38
|
-
((
|
|
37
|
+
var Adapters;
|
|
38
|
+
((Adapters2) => {
|
|
39
39
|
class WebSocket extends import_core.Adapter {
|
|
40
40
|
isSetup = false;
|
|
41
41
|
destroyFn;
|
|
42
|
+
wssPath = `/adapter/${this.identity}`;
|
|
43
|
+
wssAddress = `ws://127.0.0.1:${this.ctx.config.global.port}${this.wssPath}`;
|
|
42
44
|
destroy() {
|
|
43
45
|
if (!this.destroyFn) return;
|
|
44
46
|
this.destroyFn();
|
|
@@ -47,7 +49,7 @@ var Adapter;
|
|
|
47
49
|
setup() {
|
|
48
50
|
if (this.isSetup) return;
|
|
49
51
|
this.ctx.inject("server");
|
|
50
|
-
this.destroyFn = this.ctx.server.wss(
|
|
52
|
+
this.destroyFn = this.ctx.server.wss(this.wssPath, (ws, req) => {
|
|
51
53
|
if (this.connection) this.connection(ws, req);
|
|
52
54
|
ws.on("message", (raw) => {
|
|
53
55
|
let data;
|
|
@@ -58,8 +60,25 @@ var Adapter;
|
|
|
58
60
|
}
|
|
59
61
|
if (data) this.handle(data);
|
|
60
62
|
});
|
|
63
|
+
ws.on("close", () => {
|
|
64
|
+
this.offline();
|
|
65
|
+
this.ctx.emit("connect", {
|
|
66
|
+
type: "disconnect",
|
|
67
|
+
mode: "ws-reverse",
|
|
68
|
+
adapter: this,
|
|
69
|
+
normal: false,
|
|
70
|
+
address: this.wssAddress
|
|
71
|
+
});
|
|
72
|
+
});
|
|
61
73
|
});
|
|
62
74
|
this.isSetup = true;
|
|
75
|
+
this.ctx.emit("connect", {
|
|
76
|
+
type: "connect",
|
|
77
|
+
mode: "ws-reverse",
|
|
78
|
+
adapter: this,
|
|
79
|
+
normal: true,
|
|
80
|
+
address: this.wssAddress
|
|
81
|
+
});
|
|
63
82
|
}
|
|
64
83
|
connection;
|
|
65
84
|
start() {
|
|
@@ -67,12 +86,20 @@ var Adapter;
|
|
|
67
86
|
}
|
|
68
87
|
stop() {
|
|
69
88
|
this.destroy();
|
|
89
|
+
this.offline();
|
|
90
|
+
this.ctx.emit("connect", {
|
|
91
|
+
type: "disconnect",
|
|
92
|
+
mode: "ws-reverse",
|
|
93
|
+
adapter: this,
|
|
94
|
+
normal: false,
|
|
95
|
+
address: this.wssAddress
|
|
96
|
+
});
|
|
70
97
|
}
|
|
71
98
|
}
|
|
72
|
-
|
|
73
|
-
})(
|
|
74
|
-
var
|
|
99
|
+
Adapters2.WebSocket = WebSocket;
|
|
100
|
+
})(Adapters || (Adapters = {}));
|
|
101
|
+
var adapters_default = Adapters;
|
|
75
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
103
|
0 && (module.exports = {
|
|
77
|
-
|
|
104
|
+
Adapters
|
|
78
105
|
});
|
package/lib/service/database.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/service/file.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/service/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -76,8 +76,8 @@ class Server extends import_core.Service {
|
|
|
76
76
|
this.server = (0, import_node_http.createServer)(this.app);
|
|
77
77
|
this.wsServer = new import_ws.default.Server({ noServer: true });
|
|
78
78
|
this.server.on("upgrade", (req, socket, head) => {
|
|
79
|
-
this.wsServer.handleUpgrade(req, socket, head, (ws) => {
|
|
80
|
-
this.wsServer.emit("connection", ws,
|
|
79
|
+
this.wsServer.handleUpgrade(req, socket, head, (ws, req2) => {
|
|
80
|
+
this.wsServer.emit("connection", ws, req2);
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
this.wsServer.on("connection", (ws, req) => {
|
|
@@ -86,12 +86,15 @@ class Server extends import_core.Service {
|
|
|
86
86
|
if (!req.url) continue;
|
|
87
87
|
const result = (0, import_path_to_regexp.match)(template, { decode: decodeURIComponent })(req.url);
|
|
88
88
|
if (!result) continue;
|
|
89
|
-
|
|
89
|
+
triggered = true;
|
|
90
90
|
list.forEach((callback) => {
|
|
91
91
|
callback(ws, Object.assign(req, { params: result.params }));
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
if (!triggered)
|
|
94
|
+
if (!triggered) {
|
|
95
|
+
ws.close(1003);
|
|
96
|
+
req.destroy();
|
|
97
|
+
}
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
start() {
|
package/lib/types/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/types/internal.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/types/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/utils/log.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
package/lib/utils/logger.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/loader
|
|
4
|
-
* @Version 1.6.
|
|
4
|
+
* @Version 1.6.4
|
|
5
5
|
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/6/7
|
|
9
|
+
* @Date 2024/6/7 21:36:21
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|