@kotori-bot/core 1.4.2-beta.1 → 1.5.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/README.md +17 -17
- package/lib/components/config.js +76 -33
- package/lib/components/core.d.ts +2 -0
- package/lib/components/core.js +70 -28
- package/lib/components/index.js +33 -16
- package/lib/components/message.d.ts +9 -2
- package/lib/components/message.js +188 -128
- package/lib/global/constants.js +64 -17
- package/lib/global/index.js +33 -16
- package/lib/global/symbols.d.ts +2 -0
- package/lib/global/symbols.js +46 -9
- package/lib/index.js +55 -34
- package/lib/service/adapter.d.ts +2 -5
- package/lib/service/adapter.js +122 -137
- package/lib/service/api.js +77 -42
- package/lib/service/cache.js +65 -32
- package/lib/service/elements.js +70 -36
- package/lib/service/index.js +37 -18
- package/lib/types/adapter.js +26 -1
- package/lib/types/config.js +26 -1
- package/lib/types/index.js +35 -17
- package/lib/types/message.d.ts +19 -6
- package/lib/types/message.js +68 -14
- package/lib/utils/command.d.ts +18 -10
- package/lib/utils/command.js +205 -200
- package/lib/utils/commandError.js +46 -11
- package/lib/utils/container.js +56 -18
- package/lib/utils/error.js +64 -26
- package/lib/utils/factory.d.ts +11 -3
- package/lib/utils/factory.js +132 -37
- package/lib/utils/jsxFactory.js +26 -1
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# @kotori-bot/core
|
|
2
|
-
|
|
3
|
-
- Context
|
|
4
|
-
- Symbols
|
|
5
|
-
- Service
|
|
6
|
-
- Modules
|
|
7
|
-
- Core
|
|
8
|
-
- Config
|
|
9
|
-
- Message
|
|
10
|
-
- Adapter
|
|
11
|
-
- Api
|
|
12
|
-
- Elements
|
|
13
|
-
- Cache
|
|
14
|
-
|
|
15
|
-
## Reference
|
|
16
|
-
|
|
17
|
-
- [Kotori Docs](https://kotori.js.org/)
|
|
1
|
+
# @kotori-bot/core
|
|
2
|
+
|
|
3
|
+
- Context
|
|
4
|
+
- Symbols
|
|
5
|
+
- Service
|
|
6
|
+
- Modules
|
|
7
|
+
- Core
|
|
8
|
+
- Config
|
|
9
|
+
- Message
|
|
10
|
+
- Adapter
|
|
11
|
+
- Api
|
|
12
|
+
- Elements
|
|
13
|
+
- Cache
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
- [Kotori Docs](https://kotori.js.org/)
|
package/lib/components/config.js
CHANGED
|
@@ -1,39 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.5.0
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/7 11:22:22
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
22
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
+
var config_exports = {};
|
|
41
|
+
__export(config_exports, {
|
|
42
|
+
Config: () => Config,
|
|
43
|
+
default: () => config_default
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(config_exports);
|
|
46
|
+
var import_tsukiko = __toESM(require("tsukiko"));
|
|
47
|
+
var import_node_path = require("node:path");
|
|
48
|
+
var import_tools = require("@kotori-bot/tools");
|
|
49
|
+
var import_global = require("../global");
|
|
50
|
+
const packageInfoSchema = import_tsukiko.default.Object({
|
|
51
|
+
name: import_tsukiko.default.String(),
|
|
52
|
+
version: import_tsukiko.default.String(),
|
|
53
|
+
description: import_tsukiko.default.String(),
|
|
54
|
+
main: import_tsukiko.default.String(),
|
|
55
|
+
license: import_tsukiko.default.Literal("GPL-3.0"),
|
|
56
|
+
author: import_tsukiko.default.String()
|
|
18
57
|
});
|
|
19
58
|
class Config {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const result = packageInfoSchema.parseSafe(info);
|
|
31
|
-
if (!result.value) {
|
|
32
|
-
process.stderr.write(`File package.json format error: ${result.error.message}\n`);
|
|
33
|
-
process.exit();
|
|
34
|
-
}
|
|
35
|
-
this.pkg = result.data;
|
|
59
|
+
config;
|
|
60
|
+
pkg;
|
|
61
|
+
constructor(config = import_global.DEFAULT_CORE_CONFIG) {
|
|
62
|
+
this.config = config;
|
|
63
|
+
const info = (0, import_tools.loadConfig)((0, import_node_path.resolve)(__dirname, "../../package.json"));
|
|
64
|
+
if (!info || Object.values(info).length === 0) {
|
|
65
|
+
process.stderr.write(`Cannot find kotori-bot package.json
|
|
66
|
+
`);
|
|
67
|
+
process.exit();
|
|
36
68
|
}
|
|
69
|
+
const result = packageInfoSchema.parseSafe(info);
|
|
70
|
+
if (!result.value) {
|
|
71
|
+
process.stderr.write(`File package.json format error: ${result.error.message}
|
|
72
|
+
`);
|
|
73
|
+
process.exit();
|
|
74
|
+
}
|
|
75
|
+
this.pkg = result.data;
|
|
76
|
+
}
|
|
37
77
|
}
|
|
38
|
-
|
|
39
|
-
|
|
78
|
+
var config_default = Config;
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
Config
|
|
82
|
+
});
|
package/lib/components/core.d.ts
CHANGED
package/lib/components/core.js
CHANGED
|
@@ -1,31 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.5.0
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/7 11:22:22
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
22
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
+
var core_exports = {};
|
|
41
|
+
__export(core_exports, {
|
|
42
|
+
Core: () => Core,
|
|
43
|
+
default: () => core_default
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(core_exports);
|
|
46
|
+
var import_tools = require("@kotori-bot/tools");
|
|
47
|
+
var import_i18n = __toESM(require("@kotori-bot/i18n"));
|
|
48
|
+
var import_fluoro = require("fluoro");
|
|
49
|
+
var import_config = __toESM(require("./config"));
|
|
50
|
+
var import_message = __toESM(require("./message"));
|
|
51
|
+
var import_service = require("../service");
|
|
52
|
+
var import_global = require("../global");
|
|
53
|
+
class Core extends import_fluoro.Context {
|
|
54
|
+
[import_global.Symbols.adapter] = /* @__PURE__ */ new Map();
|
|
55
|
+
[import_global.Symbols.bot] = /* @__PURE__ */ new Map();
|
|
56
|
+
constructor(config) {
|
|
57
|
+
super();
|
|
58
|
+
this.provide("config", new import_config.default(config));
|
|
59
|
+
this.mixin("config", ["config", "pkg"]);
|
|
60
|
+
this.provide("message", new import_message.default(this));
|
|
61
|
+
this.mixin("message", ["midware", "command", "regexp", "notify", "task"]);
|
|
62
|
+
this.provide("http", new import_tools.Http({ validateStatus: () => true }));
|
|
63
|
+
this.inject("http");
|
|
64
|
+
this.provide("i18n", new import_i18n.default({ lang: this.config.global.lang }));
|
|
65
|
+
this.inject("i18n");
|
|
66
|
+
this.service("cache", new import_service.Cache(this.extends()));
|
|
67
|
+
}
|
|
29
68
|
}
|
|
30
|
-
|
|
31
|
-
|
|
69
|
+
var core_default = Core;
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
Core
|
|
73
|
+
});
|
package/lib/components/index.js
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.5.0
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/7 11:22:22
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
15
24
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var components_exports = {};
|
|
28
|
+
module.exports = __toCommonJS(components_exports);
|
|
29
|
+
__reExport(components_exports, require("./core"), module.exports);
|
|
30
|
+
__reExport(components_exports, require("../global"), module.exports);
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
...require("./core"),
|
|
34
|
+
...require("../global")
|
|
35
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Context } from 'fluoro';
|
|
2
|
-
import {
|
|
2
|
+
import { CronJob } from 'cron';
|
|
3
|
+
import { type CommandConfig, type MidwareCallback, type RegexpCallback, MessageQuick, TaskCallback } from '../types';
|
|
3
4
|
import { Command } from '../utils/command';
|
|
4
5
|
import { Symbols } from '../global';
|
|
5
6
|
interface MidwareData {
|
|
@@ -20,7 +21,13 @@ export declare class Message {
|
|
|
20
21
|
private readonly ctx;
|
|
21
22
|
constructor(ctx: Context);
|
|
22
23
|
midware(callback: MidwareCallback, priority?: number): () => boolean;
|
|
23
|
-
command(template:
|
|
24
|
+
command<T extends string>(template: T, config?: CommandConfig): Command<T, {}>;
|
|
24
25
|
regexp(match: RegExp, callback: RegexpCallback): () => boolean;
|
|
26
|
+
notify(message: MessageQuick): void;
|
|
27
|
+
task(options: string | {
|
|
28
|
+
cron: string;
|
|
29
|
+
start?: boolean;
|
|
30
|
+
timeZone?: string;
|
|
31
|
+
}, callback: TaskCallback): CronJob<null, null>;
|
|
25
32
|
}
|
|
26
33
|
export default Message;
|