@kotori-bot/core 1.4.0 → 1.4.2-beta.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 +2 -2
- package/lib/global/constants.d.ts +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/service/adapter.js +2 -21
- package/lib/utils/factory.d.ts +3 -0
- package/lib/utils/factory.js +21 -1
- package/package.json +4 -4
- package/lib/components/modules.d.ts +0 -12
- package/lib/components/modules.js +0 -127
- package/lib/constants.d.ts +0 -15
- package/lib/constants.js +0 -19
- package/lib/consts.d.ts +0 -15
- package/lib/consts.js +0 -19
- package/lib/context/context.d.ts +0 -36
- package/lib/context/context.js +0 -115
- package/lib/context/events.d.ts +0 -18
- package/lib/context/events.js +0 -2
- package/lib/context/index.d.ts +0 -5
- package/lib/context/index.js +0 -21
- package/lib/context/modules.d.ts +0 -39
- package/lib/context/modules.js +0 -65
- package/lib/context/service.d.ts +0 -16
- package/lib/context/service.js +0 -22
- package/lib/context/symbols.d.ts +0 -12
- package/lib/context/symbols.js +0 -18
- package/lib/context/test.d.ts +0 -6
- package/lib/context/test.js +0 -12
- package/lib/global/tokens.d.ts +0 -8
- package/lib/global/tokens.js +0 -12
- package/lib/service/service.d.ts +0 -16
- package/lib/service/service.js +0 -22
- package/lib/types/core.d.ts +0 -7
- package/lib/types/core.js +0 -2
- package/lib/types/modules.d.ts +0 -39
- package/lib/types/modules.js +0 -2
- package/lib/types/service.d.ts +0 -23
- package/lib/types/service.js +0 -2
- package/lib/utils/errror.d.ts +0 -24
- package/lib/utils/errror.js +0 -29
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
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Config = void 0;
|
|
7
7
|
const tsukiko_1 = __importDefault(require("tsukiko"));
|
|
8
|
-
const
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
9
|
const tools_1 = require("@kotori-bot/tools");
|
|
10
10
|
const global_1 = require("../global");
|
|
11
11
|
const packageInfoSchema = tsukiko_1.default.Object({
|
|
@@ -22,7 +22,7 @@ class Config {
|
|
|
22
22
|
constructor(config = global_1.DEFAULT_CORE_CONFIG) {
|
|
23
23
|
this.config = config;
|
|
24
24
|
/* load package.json */
|
|
25
|
-
const info = (0, tools_1.loadConfig)((0,
|
|
25
|
+
const info = (0, tools_1.loadConfig)((0, node_path_1.join)(__dirname, '../../package.json'));
|
|
26
26
|
if (!info || Object.values(info).length === 0) {
|
|
27
27
|
process.stderr.write(`Cannot find kotori-bot package.json\n`);
|
|
28
28
|
process.exit();
|
|
@@ -6,7 +6,7 @@ export declare const CUSTOM_PREFIX = "kotori-plugin-custom-";
|
|
|
6
6
|
export declare const DEFAULT_PORT = 720;
|
|
7
7
|
export declare const DEFAULT_CORE_CONFIG: {
|
|
8
8
|
global: {
|
|
9
|
-
lang: "en_US" | "en_GB" | "en_AU" | "zh_CN" | "zh_HK" | "zh_TW" | "zh_SG" | "es_ES" | "es_MX" | "ar_EG" | "ar_AE" | "ru_RU" | "fr_FR" | "fr_CA" | "de_DE" | "de_CH" | "it_IT" | "it_CH" | "hi_IN" | "pt_BR" | "pt_PT" | "tr_TR" | "ja_JP" | "id_ID" | "uk_UA" | "vi_VN" | "th_TH" | "sv_SE" | "nb_NO" | "da_DK" | "fi_FI" | "he_IL" | "sk_SK" | "bg_BG" | "lt_LT" | "sl_SI" | "sr_RS" | "mk_MK" | "sq_AL" | "et_EE" | "mt_MT";
|
|
9
|
+
lang: "common" | "en_US" | "en_GB" | "en_AU" | "zh_CN" | "zh_HK" | "zh_TW" | "zh_SG" | "es_ES" | "es_MX" | "ar_EG" | "ar_AE" | "ru_RU" | "fr_FR" | "fr_CA" | "de_DE" | "de_CH" | "it_IT" | "it_CH" | "hi_IN" | "pt_BR" | "pt_PT" | "tr_TR" | "ja_JP" | "id_ID" | "uk_UA" | "vi_VN" | "th_TH" | "sv_SE" | "nb_NO" | "da_DK" | "fi_FI" | "he_IL" | "sk_SK" | "bg_BG" | "lt_LT" | "sl_SI" | "sr_RS" | "mk_MK" | "sq_AL" | "et_EE" | "mt_MT";
|
|
10
10
|
'command-prefix': string;
|
|
11
11
|
port: number;
|
|
12
12
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './utils/command';
|
|
|
5
5
|
export * from './utils/error';
|
|
6
6
|
export * from './utils/commandError';
|
|
7
7
|
export * from './utils/container';
|
|
8
|
+
export * from './utils/factory';
|
|
8
9
|
export * from './global';
|
|
9
10
|
export * from './types';
|
|
10
11
|
export * from '@kotori-bot/tools';
|
package/lib/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __exportStar(require("./utils/command"), exports);
|
|
|
28
28
|
__exportStar(require("./utils/error"), exports);
|
|
29
29
|
__exportStar(require("./utils/commandError"), exports);
|
|
30
30
|
__exportStar(require("./utils/container"), exports);
|
|
31
|
+
__exportStar(require("./utils/factory"), exports);
|
|
31
32
|
__exportStar(require("./global"), exports);
|
|
32
33
|
__exportStar(require("./types"), exports);
|
|
33
34
|
__exportStar(require("@kotori-bot/tools"), exports);
|
package/lib/service/adapter.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Adapter = void 0;
|
|
7
|
-
const tools_1 = require("@kotori-bot/tools");
|
|
8
7
|
const types_1 = require("../types");
|
|
9
8
|
const elements_1 = __importDefault(require("./elements"));
|
|
10
9
|
const factory_1 = require("../utils/factory");
|
|
@@ -44,24 +43,6 @@ function sendMessageFactory(adapter, type, data) {
|
|
|
44
43
|
adapter.api.sendPrivateMsg(message, data.userId, data.extra);
|
|
45
44
|
};
|
|
46
45
|
}
|
|
47
|
-
function formatFactory(i18n) {
|
|
48
|
-
return (template, data) => {
|
|
49
|
-
const params = data;
|
|
50
|
-
if (Array.isArray(params)) {
|
|
51
|
-
let str = i18n.locale(template);
|
|
52
|
-
params.forEach((value, index) => {
|
|
53
|
-
str = str.replaceAll(`{${index}}`, i18n.locale(typeof value === 'string' ? value : String(value)));
|
|
54
|
-
});
|
|
55
|
-
return str;
|
|
56
|
-
}
|
|
57
|
-
Object.keys(params).forEach((key) => {
|
|
58
|
-
if (typeof params[key] !== 'string')
|
|
59
|
-
params[key] = String(params[key]);
|
|
60
|
-
params[key] = i18n.locale(params[key]);
|
|
61
|
-
});
|
|
62
|
-
return (0, tools_1.stringTemp)(i18n.locale(template), params);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
46
|
function quickFactory(send, i18n) {
|
|
66
47
|
return async (message) => {
|
|
67
48
|
const msg = await message;
|
|
@@ -71,7 +52,7 @@ function quickFactory(send, i18n) {
|
|
|
71
52
|
send(i18n.locale(msg));
|
|
72
53
|
return;
|
|
73
54
|
}
|
|
74
|
-
send(formatFactory(i18n)(...msg));
|
|
55
|
+
send((0, factory_1.formatFactory)(i18n)(...msg));
|
|
75
56
|
};
|
|
76
57
|
}
|
|
77
58
|
function isSameSender(adapter, data, session) {
|
|
@@ -138,7 +119,7 @@ class Adapter {
|
|
|
138
119
|
session(type, data) {
|
|
139
120
|
const i18n = this.ctx.i18n.extends(this.config.lang);
|
|
140
121
|
const send = sendMessageFactory(this, type, data);
|
|
141
|
-
const format = formatFactory(i18n);
|
|
122
|
+
const format = (0, factory_1.formatFactory)(i18n);
|
|
142
123
|
const quick = quickFactory(send, i18n);
|
|
143
124
|
const prompt = promptFactory(quick, this, data);
|
|
144
125
|
const confirm = confirmFactory(quick, this, data);
|
package/lib/utils/factory.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import I18n from '@kotori-bot/i18n/src/common';
|
|
1
2
|
import type { Context } from 'fluoro';
|
|
3
|
+
import { CommandArgType } from '..';
|
|
2
4
|
export declare function disposeFactory(ctx: Context, dispose: () => void): void;
|
|
3
5
|
export declare function cancelFactory(): {
|
|
4
6
|
get(): () => void;
|
|
5
7
|
fn(): void;
|
|
6
8
|
value: boolean;
|
|
7
9
|
};
|
|
10
|
+
export declare function formatFactory(i18n: I18n): (template: string, data: Record<string, unknown> | CommandArgType[]) => string;
|
package/lib/utils/factory.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cancelFactory = exports.disposeFactory = void 0;
|
|
3
|
+
exports.formatFactory = exports.cancelFactory = exports.disposeFactory = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
4
5
|
function disposeFactory(ctx, dispose) {
|
|
5
6
|
ctx.once('dispose_module', (data) => {
|
|
6
7
|
if ((typeof data.instance === 'object' ? data.instance.name : data.instance) !== ctx.identity) {
|
|
@@ -23,3 +24,22 @@ function cancelFactory() {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
exports.cancelFactory = cancelFactory;
|
|
27
|
+
function formatFactory(i18n) {
|
|
28
|
+
return (template, data) => {
|
|
29
|
+
const params = data;
|
|
30
|
+
if (Array.isArray(params)) {
|
|
31
|
+
let str = i18n.locale(template);
|
|
32
|
+
params.forEach((value, index) => {
|
|
33
|
+
str = str.replaceAll(`{${index}}`, i18n.locale(typeof value === 'string' ? value : String(value)));
|
|
34
|
+
});
|
|
35
|
+
return str;
|
|
36
|
+
}
|
|
37
|
+
Object.keys(params).forEach((key) => {
|
|
38
|
+
if (typeof params[key] !== 'string')
|
|
39
|
+
params[key] = String(params[key]);
|
|
40
|
+
params[key] = i18n.locale(params[key]);
|
|
41
|
+
});
|
|
42
|
+
return (0, __1.stringTemp)(i18n.locale(template), params);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.formatFactory = formatFactory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kotori-bot/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2-beta.1",
|
|
4
4
|
"description": "Kotori Core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@types/minimist": "^1.2.5",
|
|
28
28
|
"minimist": "^1.2.8",
|
|
29
29
|
"tsukiko": "^1.2.1",
|
|
30
|
-
"@kotori-bot/i18n": "^1.
|
|
31
|
-
"@kotori-bot/tools": "^1.3.
|
|
32
|
-
"fluoro": "^1.0.
|
|
30
|
+
"@kotori-bot/i18n": "^1.3.0",
|
|
31
|
+
"@kotori-bot/tools": "^1.3.1",
|
|
32
|
+
"fluoro": "^1.0.1"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsc --build"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ModuleInstance, ModuleConfig } from '../types';
|
|
2
|
-
import { type Context } from '../context';
|
|
3
|
-
type ModuleInstanceClass = new (ctx: Context, config: ModuleConfig) => void;
|
|
4
|
-
type ModuleInstanceFunction = (ctx: Context, config: ModuleConfig) => void;
|
|
5
|
-
export declare class Modules {
|
|
6
|
-
private handleExports;
|
|
7
|
-
private readonly ctx;
|
|
8
|
-
constructor(ctx: Context);
|
|
9
|
-
use(modules: ModuleInstance | string | ModuleInstanceFunction | ModuleInstanceClass, config: ModuleConfig): Promise<void>;
|
|
10
|
-
dispose(modules: ModuleInstance | string): void;
|
|
11
|
-
}
|
|
12
|
-
export default Modules;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Modules = void 0;
|
|
4
|
-
const tools_1 = require("@kotori-bot/tools");
|
|
5
|
-
const tsukiko_1 = require("tsukiko");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const errror_1 = require("../utils/errror");
|
|
8
|
-
const context_1 = require("../context");
|
|
9
|
-
const service_1 = require("../service");
|
|
10
|
-
const consts_1 = require("../consts");
|
|
11
|
-
const factory_1 = require("../utils/factory");
|
|
12
|
-
function isServiceConsructor(Fn) {
|
|
13
|
-
return service_1.Service.isPrototypeOf.call(service_1.Service, Fn);
|
|
14
|
-
}
|
|
15
|
-
function isAdapterClass(Fn) {
|
|
16
|
-
return service_1.Adapter.isPrototypeOf.call(service_1.Adapter, Fn);
|
|
17
|
-
}
|
|
18
|
-
/* static isDatabaseClass(Obj: object): Obj is DatabaseClass {
|
|
19
|
-
return Database.isPrototypeOf.call(Database, Obj);
|
|
20
|
-
} */
|
|
21
|
-
function handleFunction(func, ctx, config) {
|
|
22
|
-
func(ctx, config);
|
|
23
|
-
}
|
|
24
|
-
function handleCconstructor(Class, ctx, config) {
|
|
25
|
-
(0, tools_1.none)(new Class(ctx, config));
|
|
26
|
-
}
|
|
27
|
-
function checkConfig(schema, config) {
|
|
28
|
-
if (!(schema instanceof tsukiko_1.Parser))
|
|
29
|
-
return config;
|
|
30
|
-
const result = schema.parseSafe(config);
|
|
31
|
-
if (result && !result.value)
|
|
32
|
-
return result.error;
|
|
33
|
-
return result.data;
|
|
34
|
-
}
|
|
35
|
-
class Modules {
|
|
36
|
-
handleExports(identity, ctx, exports, config) {
|
|
37
|
-
/* before handle */
|
|
38
|
-
const { lang, inject, config: schema, default: defaults, main, Main } = exports.default;
|
|
39
|
-
if (lang)
|
|
40
|
-
this.ctx.i18n.use(Array.isArray(lang) ? (0, path_1.resolve)(...lang) : (0, path_1.resolve)(lang));
|
|
41
|
-
/* handle */
|
|
42
|
-
/* service */
|
|
43
|
-
if (isServiceConsructor(defaults)) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
/* adapter */
|
|
47
|
-
if (isAdapterClass(defaults)) {
|
|
48
|
-
const adapterName = identity.split(consts_1.ADAPTER_PREFIX)[1];
|
|
49
|
-
if (adapterName)
|
|
50
|
-
this.ctx[context_1.Symbols.adapter].set(adapterName, [defaults, schema]);
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
/* plugin */
|
|
54
|
-
if (inject && Array.isArray(inject)) {
|
|
55
|
-
inject.forEach((identity) => {
|
|
56
|
-
ctx[context_1.Symbols.container].forEach((service, name) => {
|
|
57
|
-
if (!(service instanceof service_1.Service) || service.identity !== identity)
|
|
58
|
-
return;
|
|
59
|
-
ctx.inject(name);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const moduleConfig = checkConfig(schema, config);
|
|
64
|
-
if (moduleConfig instanceof tsukiko_1.TsuError)
|
|
65
|
-
return new errror_1.ModuleError(`Config format of module ${identity} is error: ${moduleConfig.message}`);
|
|
66
|
-
if (defaults !== undefined) {
|
|
67
|
-
if ((0, tools_1.isClass)(defaults)) {
|
|
68
|
-
return handleCconstructor(defaults, ctx, moduleConfig);
|
|
69
|
-
}
|
|
70
|
-
if (defaults instanceof Function) {
|
|
71
|
-
return handleFunction(defaults, ctx, moduleConfig);
|
|
72
|
-
}
|
|
73
|
-
return new errror_1.DevError(`Module instance of default export is not function or constructor at ${identity}`);
|
|
74
|
-
}
|
|
75
|
-
if (main instanceof Function) {
|
|
76
|
-
if ((0, tools_1.isClass)(main)) {
|
|
77
|
-
return new errror_1.DevError(`Module instance is constructor,export name should be 'Main' not 'main' at ${identity}`);
|
|
78
|
-
}
|
|
79
|
-
return handleFunction(main, ctx, moduleConfig);
|
|
80
|
-
}
|
|
81
|
-
if (Main instanceof Function) {
|
|
82
|
-
if (!(0, tools_1.isClass)(Main)) {
|
|
83
|
-
return new errror_1.DevError(`Module instance is function,export name should be 'main' not 'Main' at ${identity}`);
|
|
84
|
-
}
|
|
85
|
-
return handleCconstructor(Main, ctx, moduleConfig);
|
|
86
|
-
}
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
ctx;
|
|
90
|
-
constructor(ctx) {
|
|
91
|
-
this.ctx = ctx;
|
|
92
|
-
}
|
|
93
|
-
async use(modules, config) {
|
|
94
|
-
const isObject = typeof modules === 'object';
|
|
95
|
-
const ctx = this.ctx.extends({}, !this.ctx.identity && isObject ? modules.pkg.name : this.ctx.identity);
|
|
96
|
-
if (modules instanceof Function) {
|
|
97
|
-
if ((0, tools_1.isClass)(modules))
|
|
98
|
-
handleCconstructor(modules, ctx, config);
|
|
99
|
-
else
|
|
100
|
-
handleFunction(modules, ctx, config);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
(0, factory_1.disposeFactory)(this.ctx, () => this.dispose(modules));
|
|
104
|
-
const identity = isObject ? modules.pkg.name : modules;
|
|
105
|
-
try {
|
|
106
|
-
const exports = await import(`file://${isObject ? modules.main : (0, path_1.resolve)(modules)}`);
|
|
107
|
-
const error = this.handleExports(identity, ctx, exports, config);
|
|
108
|
-
if (error)
|
|
109
|
-
throw error;
|
|
110
|
-
this.ctx.emit('ready_module', { module: modules });
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
this.ctx.emit('ready_module', { module: modules, error });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
dispose(modules) {
|
|
117
|
-
if (typeof modules === 'object') {
|
|
118
|
-
modules.files.forEach((file) => delete require.cache[require.resolve(file)]);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
delete require.cache[require.resolve(modules)];
|
|
122
|
-
}
|
|
123
|
-
this.ctx.emit('dispose_module', { module: modules });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.Modules = Modules;
|
|
127
|
-
exports.default = Modules;
|
package/lib/constants.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const OFFICIAL_MODULES_SCOPE = "@kotori-bot/";
|
|
2
|
-
export declare const PLUGIN_PREFIX = "kotori-plugin-";
|
|
3
|
-
export declare const DATABASE_PREFIX = "kotori-plugin-database-";
|
|
4
|
-
export declare const ADAPTER_PREFIX = "kotori-plugin-adapter-";
|
|
5
|
-
export declare const CUSTOM_PREFIX = "kotori-plugin-custom-";
|
|
6
|
-
export declare const DEFAULT_PORT = 720;
|
|
7
|
-
export declare const DEFAULT_CORE_CONFIG: {
|
|
8
|
-
global: {
|
|
9
|
-
lang: "en_US" | "en_GB" | "en_AU" | "zh_CN" | "zh_HK" | "zh_TW" | "zh_SG" | "es_ES" | "es_MX" | "ar_EG" | "ar_AE" | "ru_RU" | "fr_FR" | "fr_CA" | "de_DE" | "de_CH" | "it_IT" | "it_CH" | "hi_IN" | "pt_BR" | "pt_PT" | "tr_TR" | "ja_JP" | "id_ID" | "uk_UA" | "vi_VN" | "th_TH" | "sv_SE" | "nb_NO" | "da_DK" | "fi_FI" | "he_IL" | "sk_SK" | "bg_BG" | "lt_LT" | "sl_SI" | "sr_RS" | "mk_MK" | "sq_AL" | "et_EE" | "mt_MT";
|
|
10
|
-
'command-prefix': string;
|
|
11
|
-
port: number;
|
|
12
|
-
};
|
|
13
|
-
adapter: {};
|
|
14
|
-
plugin: {};
|
|
15
|
-
};
|
package/lib/constants.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_CORE_CONFIG = exports.DEFAULT_PORT = exports.CUSTOM_PREFIX = exports.ADAPTER_PREFIX = exports.DATABASE_PREFIX = exports.PLUGIN_PREFIX = exports.OFFICIAL_MODULES_SCOPE = void 0;
|
|
4
|
-
const i18n_1 = require("@kotori-bot/i18n");
|
|
5
|
-
exports.OFFICIAL_MODULES_SCOPE = '@kotori-bot/';
|
|
6
|
-
exports.PLUGIN_PREFIX = 'kotori-plugin-';
|
|
7
|
-
exports.DATABASE_PREFIX = `${exports.PLUGIN_PREFIX}database-`;
|
|
8
|
-
exports.ADAPTER_PREFIX = `${exports.PLUGIN_PREFIX}adapter-`;
|
|
9
|
-
exports.CUSTOM_PREFIX = `${exports.PLUGIN_PREFIX}custom-`;
|
|
10
|
-
exports.DEFAULT_PORT = 720;
|
|
11
|
-
exports.DEFAULT_CORE_CONFIG = {
|
|
12
|
-
global: {
|
|
13
|
-
lang: i18n_1.DEFAULT_LANG,
|
|
14
|
-
'command-prefix': '/',
|
|
15
|
-
port: exports.DEFAULT_PORT
|
|
16
|
-
},
|
|
17
|
-
adapter: {},
|
|
18
|
-
plugin: {}
|
|
19
|
-
};
|
package/lib/consts.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const OFFICIAL_MODULES_SCOPE = "@kotori-bot/";
|
|
2
|
-
export declare const PLUGIN_PREFIX = "kotori-plugin-";
|
|
3
|
-
export declare const DATABASE_PREFIX = "kotori-plugin-database-";
|
|
4
|
-
export declare const ADAPTER_PREFIX = "kotori-plugin-adapter-";
|
|
5
|
-
export declare const CUSTOM_PREFIX = "kotori-plugin-custom-";
|
|
6
|
-
export declare const DEFAULT_PORT = 720;
|
|
7
|
-
export declare const DEFAULT_CORE_CONFIG: {
|
|
8
|
-
global: {
|
|
9
|
-
lang: "en_US" | "en_GB" | "en_AU" | "zh_CN" | "zh_HK" | "zh_TW" | "zh_SG" | "es_ES" | "es_MX" | "ar_EG" | "ar_AE" | "ru_RU" | "fr_FR" | "fr_CA" | "de_DE" | "de_CH" | "it_IT" | "it_CH" | "hi_IN" | "pt_BR" | "pt_PT" | "tr_TR" | "ja_JP" | "id_ID" | "uk_UA" | "vi_VN" | "th_TH" | "sv_SE" | "nb_NO" | "da_DK" | "fi_FI" | "he_IL" | "sk_SK" | "bg_BG" | "lt_LT" | "sl_SI" | "sr_RS" | "mk_MK" | "sq_AL" | "et_EE" | "mt_MT";
|
|
10
|
-
'command-prefix': string;
|
|
11
|
-
port: number;
|
|
12
|
-
};
|
|
13
|
-
adapter: {};
|
|
14
|
-
plugin: {};
|
|
15
|
-
};
|
package/lib/consts.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_CORE_CONFIG = exports.DEFAULT_PORT = exports.CUSTOM_PREFIX = exports.ADAPTER_PREFIX = exports.DATABASE_PREFIX = exports.PLUGIN_PREFIX = exports.OFFICIAL_MODULES_SCOPE = void 0;
|
|
4
|
-
const i18n_1 = require("@kotori-bot/i18n");
|
|
5
|
-
exports.OFFICIAL_MODULES_SCOPE = '@kotori-bot/';
|
|
6
|
-
exports.PLUGIN_PREFIX = 'kotori-plugin-';
|
|
7
|
-
exports.DATABASE_PREFIX = `${exports.PLUGIN_PREFIX}database-`;
|
|
8
|
-
exports.ADAPTER_PREFIX = `${exports.PLUGIN_PREFIX}adapter-`;
|
|
9
|
-
exports.CUSTOM_PREFIX = `${exports.PLUGIN_PREFIX}custom-`;
|
|
10
|
-
exports.DEFAULT_PORT = 720;
|
|
11
|
-
exports.DEFAULT_CORE_CONFIG = {
|
|
12
|
-
global: {
|
|
13
|
-
lang: i18n_1.DEFAULT_LANG,
|
|
14
|
-
'command-prefix': '/',
|
|
15
|
-
port: exports.DEFAULT_PORT
|
|
16
|
-
},
|
|
17
|
-
adapter: {},
|
|
18
|
-
plugin: {}
|
|
19
|
-
};
|
package/lib/context/context.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import Symbols from './symbols';
|
|
2
|
-
import './events';
|
|
3
|
-
interface obj {
|
|
4
|
-
[propName: string | number | symbol]: any;
|
|
5
|
-
}
|
|
6
|
-
interface ContextOrigin {
|
|
7
|
-
readonly [Symbols.container]: Map<string, obj>;
|
|
8
|
-
readonly [Symbols.table]: Map<string, string[]>;
|
|
9
|
-
root: Context;
|
|
10
|
-
get(prop: string): obj | undefined;
|
|
11
|
-
inject<T extends Keys>(prop: T): void;
|
|
12
|
-
provide<T extends obj>(prop: string, value: T): void;
|
|
13
|
-
mixin<K extends Keys>(prop: string, keys: K[]): void;
|
|
14
|
-
extends<T extends obj>(meta?: T, identity?: string): Context;
|
|
15
|
-
}
|
|
16
|
-
interface ContextImpl extends ContextOrigin {
|
|
17
|
-
}
|
|
18
|
-
declare module './context' {
|
|
19
|
-
interface Context {
|
|
20
|
-
identity?: string;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
type Keys = keyof Omit<Context, keyof ContextOrigin> & string;
|
|
24
|
-
export declare class Context implements ContextImpl {
|
|
25
|
-
readonly [Symbols.container]: Map<string, obj>;
|
|
26
|
-
readonly [Symbols.table]: Map<string, string[]>;
|
|
27
|
-
root: Context;
|
|
28
|
-
parent: Context | null;
|
|
29
|
-
constructor(root?: Context);
|
|
30
|
-
get<T = obj | undefined>(prop: string): T;
|
|
31
|
-
inject<T extends Keys>(prop: T): void;
|
|
32
|
-
provide<T extends obj>(prop: string, value: T): void;
|
|
33
|
-
mixin<K extends Keys>(prop: string, keys: K[]): void;
|
|
34
|
-
extends<T extends obj = object>(meta?: T, identity?: string): Context;
|
|
35
|
-
}
|
|
36
|
-
export default Context;
|
package/lib/context/context.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Context = void 0;
|
|
7
|
-
/*
|
|
8
|
-
* @Author: Hotaru biyuehuya@gmail.com
|
|
9
|
-
* @Blog: https://hotaru.icu
|
|
10
|
-
* @Date: 2024-02-07 13:44:38
|
|
11
|
-
* @LastEditors: Hotaru biyuehuya@gmail.com
|
|
12
|
-
* @LastEditTime: 2024-05-01 21:32:19
|
|
13
|
-
*/
|
|
14
|
-
const tools_1 = require("@kotori-bot/tools");
|
|
15
|
-
const symbols_1 = __importDefault(require("./symbols"));
|
|
16
|
-
const modules_1 = __importDefault(require("./modules"));
|
|
17
|
-
const handler = (value, ctx) => {
|
|
18
|
-
if (!value || typeof value !== 'object' || !(value.ctx instanceof Context))
|
|
19
|
-
return value;
|
|
20
|
-
return new Proxy(value, {
|
|
21
|
-
get(target, prop, receiver) {
|
|
22
|
-
if (prop === 'ctx')
|
|
23
|
-
return ctx;
|
|
24
|
-
return Reflect.get(target, prop, receiver);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
const DEFAULT_EXTENDS_NAME = 'sub';
|
|
29
|
-
class Context {
|
|
30
|
-
[symbols_1.default.container] = new Map();
|
|
31
|
-
[symbols_1.default.table] = new Map();
|
|
32
|
-
root;
|
|
33
|
-
parent = null;
|
|
34
|
-
constructor(root) {
|
|
35
|
-
this.root = root || this;
|
|
36
|
-
this.provide('events', root ? root.get('events') : new tools_1.Events());
|
|
37
|
-
this.mixin('events', ['emit', 'on', 'once', 'off', 'offAll']);
|
|
38
|
-
this.provide('modules', new modules_1.default(this));
|
|
39
|
-
this.mixin('modules', ['load', 'unload', 'service']);
|
|
40
|
-
}
|
|
41
|
-
get(prop) {
|
|
42
|
-
return this[symbols_1.default.container].get(prop);
|
|
43
|
-
}
|
|
44
|
-
inject(prop) {
|
|
45
|
-
if (this[prop] && !this[symbols_1.default.container].has(prop))
|
|
46
|
-
return;
|
|
47
|
-
this[prop] = this.get(prop);
|
|
48
|
-
}
|
|
49
|
-
provide(prop, value) {
|
|
50
|
-
if (this[symbols_1.default.container].has(prop))
|
|
51
|
-
return;
|
|
52
|
-
this[symbols_1.default.container].set(prop, value);
|
|
53
|
-
}
|
|
54
|
-
mixin(prop, keys) {
|
|
55
|
-
this[symbols_1.default.table].set(prop, keys);
|
|
56
|
-
const instance = this.get(prop);
|
|
57
|
-
if (!instance)
|
|
58
|
-
return;
|
|
59
|
-
this[symbols_1.default.table].set(prop, keys);
|
|
60
|
-
keys.forEach((key) => {
|
|
61
|
-
if (this[key] || !instance[key])
|
|
62
|
-
return;
|
|
63
|
-
this[key] = instance[key];
|
|
64
|
-
if (typeof this[key] === 'function') {
|
|
65
|
-
this[key] = this[key]?.bind(instance);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
extends(meta, identity) {
|
|
70
|
-
const metaHandle = meta ?? {};
|
|
71
|
-
/* clear function */
|
|
72
|
-
Object.keys(metaHandle).forEach((key) => {
|
|
73
|
-
if (typeof this[key] === 'function')
|
|
74
|
-
delete metaHandle[key];
|
|
75
|
-
});
|
|
76
|
-
/* set proxy */
|
|
77
|
-
const ctx = new Proxy(new Context(this.root), {
|
|
78
|
-
get: (target, prop) => {
|
|
79
|
-
if (prop === 'identity')
|
|
80
|
-
return identity ?? this.identity ?? DEFAULT_EXTENDS_NAME;
|
|
81
|
-
if (prop === 'parent')
|
|
82
|
-
return this;
|
|
83
|
-
if (target[prop])
|
|
84
|
-
return handler(target[prop], ctx);
|
|
85
|
-
let value;
|
|
86
|
-
this[symbols_1.default.table].forEach((keys, key) => {
|
|
87
|
-
if (value || (typeof prop === 'string' && !keys.includes(prop)))
|
|
88
|
-
return;
|
|
89
|
-
const instance = ctx[symbols_1.default.container].get(key);
|
|
90
|
-
if (!instance)
|
|
91
|
-
return;
|
|
92
|
-
value = instance[prop];
|
|
93
|
-
if (typeof value === 'function')
|
|
94
|
-
value = value.bind(instance);
|
|
95
|
-
});
|
|
96
|
-
if (value !== undefined)
|
|
97
|
-
return value;
|
|
98
|
-
if (metaHandle[prop])
|
|
99
|
-
return handler(metaHandle[prop], ctx);
|
|
100
|
-
return handler(this[prop], ctx);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
/* set table */
|
|
104
|
-
this[symbols_1.default.table].forEach((value, key) => ctx[symbols_1.default.table].set(key, value));
|
|
105
|
-
/* set container */
|
|
106
|
-
this[symbols_1.default.container].forEach((value, key) => {
|
|
107
|
-
if (!value.ctx)
|
|
108
|
-
return ctx[symbols_1.default.container].set(key, value);
|
|
109
|
-
return ctx[symbols_1.default.container].set(key, handler(value, ctx));
|
|
110
|
-
});
|
|
111
|
-
return ctx;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.Context = Context;
|
|
115
|
-
exports.default = Context;
|
package/lib/context/events.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Events } from '@kotori-bot/tools';
|
|
2
|
-
declare module './context' {
|
|
3
|
-
interface Context {
|
|
4
|
-
emit: Events<EventsMapping>['emit'];
|
|
5
|
-
parallel: Events<EventsMapping>['parallel'];
|
|
6
|
-
on: Events<EventsMapping>['on'];
|
|
7
|
-
once: Events<EventsMapping>['once'];
|
|
8
|
-
off: Events<EventsMapping>['off'];
|
|
9
|
-
offAll: Events<EventsMapping>['offAll'];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export type EventsList = {
|
|
13
|
-
[K in keyof EventsMapping]: Parameters<EventsMapping[K]>[1] extends never | undefined | null ? Parameters<EventsMapping[K]>[0] : [...Parameters<EventsMapping[K]>];
|
|
14
|
-
};
|
|
15
|
-
export interface EventsMapping {
|
|
16
|
-
ready(): void;
|
|
17
|
-
dispose(): void;
|
|
18
|
-
}
|
package/lib/context/events.js
DELETED
package/lib/context/index.d.ts
DELETED
package/lib/context/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
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);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./context"), exports);
|
|
18
|
-
__exportStar(require("./events"), exports);
|
|
19
|
-
__exportStar(require("./modules"), exports);
|
|
20
|
-
__exportStar(require("./service"), exports);
|
|
21
|
-
__exportStar(require("./symbols"), exports);
|
package/lib/context/modules.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Context } from './context';
|
|
2
|
-
import { Service } from './service';
|
|
3
|
-
type ModuleInstanceClass = new (ctx: Context, config: ModuleConfig) => void;
|
|
4
|
-
type ModuleInstanceFunction = (ctx: Context, config: ModuleConfig) => void;
|
|
5
|
-
export interface ModuleExport {
|
|
6
|
-
name?: string;
|
|
7
|
-
main?: ModuleInstanceFunction;
|
|
8
|
-
Main?: ModuleInstanceClass;
|
|
9
|
-
default?: ModuleInstanceFunction | ModuleInstanceClass;
|
|
10
|
-
inject?: string[];
|
|
11
|
-
config?: ModuleConfig;
|
|
12
|
-
}
|
|
13
|
-
export interface ModuleConfig {
|
|
14
|
-
filter: object;
|
|
15
|
-
}
|
|
16
|
-
declare module './events' {
|
|
17
|
-
interface EventsMapping {
|
|
18
|
-
ready_module(data: EventDataModule): void;
|
|
19
|
-
dispose_module(data: EventDataModule): void;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
declare module './context' {
|
|
23
|
-
interface Context {
|
|
24
|
-
load: Modules['load'];
|
|
25
|
-
unload: Modules['unload'];
|
|
26
|
-
service: Modules['service'];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
interface EventDataModule {
|
|
30
|
-
instance: ModuleExport | ModuleInstanceFunction | ModuleInstanceClass;
|
|
31
|
-
}
|
|
32
|
-
export declare class Modules {
|
|
33
|
-
private readonly ctx;
|
|
34
|
-
constructor(ctx: Context);
|
|
35
|
-
load(instance: EventDataModule['instance']): void;
|
|
36
|
-
unload(instance: EventDataModule['instance']): void;
|
|
37
|
-
service(name: string, instance: Service): void;
|
|
38
|
-
}
|
|
39
|
-
export default Modules;
|
package/lib/context/modules.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Modules = void 0;
|
|
4
|
-
/* eslint import/no-dynamic-require: 0 */
|
|
5
|
-
/* eslint global-require: 0 */
|
|
6
|
-
const tools_1 = require("@kotori-bot/tools");
|
|
7
|
-
const symbols_1 = require("./symbols");
|
|
8
|
-
const service_1 = require("./service");
|
|
9
|
-
function handleFunction(func, ctx, config) {
|
|
10
|
-
func(ctx, config);
|
|
11
|
-
}
|
|
12
|
-
function handleConstructor(Class, ctx, config) {
|
|
13
|
-
(0, tools_1.none)(new Class(ctx, config));
|
|
14
|
-
}
|
|
15
|
-
const DEFAULT_MODULE_CONFIG = { filter: {} };
|
|
16
|
-
class Modules {
|
|
17
|
-
ctx;
|
|
18
|
-
constructor(ctx) {
|
|
19
|
-
this.ctx = ctx;
|
|
20
|
-
}
|
|
21
|
-
load(instance) {
|
|
22
|
-
const ctx = this.ctx.extends({}, !this.ctx.identity && typeof instance === 'object' ? instance.name : this.ctx.identity);
|
|
23
|
-
if (instance instanceof Function) {
|
|
24
|
-
if ((0, tools_1.isClass)(instance))
|
|
25
|
-
handleConstructor(instance, ctx, DEFAULT_MODULE_CONFIG);
|
|
26
|
-
else
|
|
27
|
-
handleFunction(instance, ctx, DEFAULT_MODULE_CONFIG);
|
|
28
|
-
this.ctx.emit('ready_module', { instance });
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const { main, Main, inject, default: defaults, config } = instance;
|
|
32
|
-
if (Array.isArray(inject)) {
|
|
33
|
-
inject.forEach((identity) => {
|
|
34
|
-
ctx[symbols_1.Symbols.container].forEach((service, name) => {
|
|
35
|
-
if (!(service instanceof service_1.Service) || service.identity !== identity)
|
|
36
|
-
return;
|
|
37
|
-
ctx.inject(name);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
if (defaults) {
|
|
42
|
-
if ((0, tools_1.isClass)(defaults))
|
|
43
|
-
handleConstructor(defaults, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
44
|
-
else
|
|
45
|
-
handleFunction(defaults, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
46
|
-
}
|
|
47
|
-
else if (main) {
|
|
48
|
-
handleFunction(main, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
49
|
-
}
|
|
50
|
-
else if (Main) {
|
|
51
|
-
handleConstructor(Main, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
52
|
-
}
|
|
53
|
-
this.ctx.emit('ready_module', { instance });
|
|
54
|
-
}
|
|
55
|
-
unload(instance) {
|
|
56
|
-
this.ctx.emit('dispose_module', { instance });
|
|
57
|
-
}
|
|
58
|
-
service(name, instance) {
|
|
59
|
-
this.ctx.provide(name, instance);
|
|
60
|
-
this.ctx.on('ready', () => this.ctx.get(name).start());
|
|
61
|
-
this.ctx.on('dispose', () => this.ctx.get(name).stop());
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.Modules = Modules;
|
|
65
|
-
exports.default = Modules;
|
package/lib/context/service.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Context } from './context';
|
|
2
|
-
interface ServiceImpl<T extends object = object> {
|
|
3
|
-
readonly identity: string;
|
|
4
|
-
readonly config: T;
|
|
5
|
-
start(): void;
|
|
6
|
-
stop(): void;
|
|
7
|
-
}
|
|
8
|
-
export declare abstract class Service<T extends object = object> implements ServiceImpl<T> {
|
|
9
|
-
readonly ctx: Context;
|
|
10
|
-
readonly config: T;
|
|
11
|
-
readonly identity: string;
|
|
12
|
-
constructor(ctx: Context, config: T, identity: string);
|
|
13
|
-
start(): void;
|
|
14
|
-
stop(): void;
|
|
15
|
-
}
|
|
16
|
-
export default Service;
|
package/lib/context/service.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Service = void 0;
|
|
4
|
-
const tools_1 = require("@kotori-bot/tools");
|
|
5
|
-
class Service {
|
|
6
|
-
ctx;
|
|
7
|
-
config;
|
|
8
|
-
identity;
|
|
9
|
-
constructor(ctx, config, identity) {
|
|
10
|
-
this.ctx = ctx;
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.identity = identity;
|
|
13
|
-
}
|
|
14
|
-
start() {
|
|
15
|
-
return (0, tools_1.none)(this);
|
|
16
|
-
}
|
|
17
|
-
stop() {
|
|
18
|
-
return (0, tools_1.none)(this);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.Service = Service;
|
|
22
|
-
exports.default = Service;
|
package/lib/context/symbols.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare class Symbols {
|
|
2
|
-
static readonly container: unique symbol;
|
|
3
|
-
static readonly table: unique symbol;
|
|
4
|
-
static readonly containerKey: (prop: string) => symbol;
|
|
5
|
-
static readonly adapter: unique symbol;
|
|
6
|
-
static readonly bot: unique symbol;
|
|
7
|
-
static readonly midware: unique symbol;
|
|
8
|
-
static readonly command: unique symbol;
|
|
9
|
-
static readonly regexp: unique symbol;
|
|
10
|
-
static readonly modules: unique symbol;
|
|
11
|
-
}
|
|
12
|
-
export default Symbols;
|
package/lib/context/symbols.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Symbols = void 0;
|
|
4
|
-
class Symbols {
|
|
5
|
-
static container = Symbol.for('kotori.context.container');
|
|
6
|
-
static table = Symbol.for('kotori.context.table');
|
|
7
|
-
static containerKey = (prop) => Symbol.for(`kotori.context.container.${prop}`);
|
|
8
|
-
/* custom */
|
|
9
|
-
// static readonly service = Symbol.for('kotori.core.service');
|
|
10
|
-
static adapter = Symbol.for('kotori.core.adapter');
|
|
11
|
-
static bot = Symbol.for('kotori.core.bot');
|
|
12
|
-
static midware = Symbol.for('kotori.core.midware');
|
|
13
|
-
static command = Symbol.for('kotori.core.command');
|
|
14
|
-
static regexp = Symbol.for('kotori.core.regexp');
|
|
15
|
-
static modules = Symbol.for('kotori.loader.module');
|
|
16
|
-
}
|
|
17
|
-
exports.Symbols = Symbols;
|
|
18
|
-
exports.default = Symbols;
|
package/lib/context/test.d.ts
DELETED
package/lib/context/test.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const symbols_1 = require("./symbols");
|
|
4
|
-
const cache_1 = require("../service/cache");
|
|
5
|
-
const context_1 = require("./context");
|
|
6
|
-
class K extends context_1.Context {
|
|
7
|
-
}
|
|
8
|
-
const ctx = new K();
|
|
9
|
-
ctx.provide('cache', new cache_1.Cache(ctx));
|
|
10
|
-
const ctx2 = ctx.extends({}, 'tt');
|
|
11
|
-
ctx2.inject('cache');
|
|
12
|
-
console.log(ctx2[symbols_1.Symbols.container].get('cache').ctx.identity, ctx2.cache.ctx.identity, ctx[symbols_1.Symbols.container].get('cache').ctx.identity, ctx2.get('cache').ctx.identity);
|
package/lib/global/tokens.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare class Tokens {
|
|
2
|
-
static readonly adapter: unique symbol;
|
|
3
|
-
static readonly bot: unique symbol;
|
|
4
|
-
static readonly midware: unique symbol;
|
|
5
|
-
static readonly command: unique symbol;
|
|
6
|
-
static readonly regexp: unique symbol;
|
|
7
|
-
static readonly modules: unique symbol;
|
|
8
|
-
}
|
package/lib/global/tokens.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Tokens = void 0;
|
|
4
|
-
class Tokens {
|
|
5
|
-
static adapter = Symbol.for('kotori.core.adapter');
|
|
6
|
-
static bot = Symbol.for('kotori.core.bot');
|
|
7
|
-
static midware = Symbol.for('kotori.core.midware');
|
|
8
|
-
static command = Symbol.for('kotori.core.command');
|
|
9
|
-
static regexp = Symbol.for('kotori.core.regexp');
|
|
10
|
-
static modules = Symbol.for('kotori.loader.module');
|
|
11
|
-
}
|
|
12
|
-
exports.Tokens = Tokens;
|
package/lib/service/service.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Context } from '../context';
|
|
2
|
-
interface ServiceImpl<T extends object = object> {
|
|
3
|
-
readonly identity: string;
|
|
4
|
-
readonly config: T;
|
|
5
|
-
start(): void;
|
|
6
|
-
stop(): void;
|
|
7
|
-
}
|
|
8
|
-
export declare abstract class Service<T extends object = object> implements ServiceImpl<T> {
|
|
9
|
-
readonly ctx: Context;
|
|
10
|
-
readonly config: T;
|
|
11
|
-
readonly identity: string;
|
|
12
|
-
constructor(ctx: Context, config: T, identity: string);
|
|
13
|
-
start(): void;
|
|
14
|
-
stop(): void;
|
|
15
|
-
}
|
|
16
|
-
export default Service;
|
package/lib/service/service.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Service = void 0;
|
|
4
|
-
const tools_1 = require("@kotori-bot/tools");
|
|
5
|
-
class Service {
|
|
6
|
-
ctx;
|
|
7
|
-
config;
|
|
8
|
-
identity;
|
|
9
|
-
constructor(ctx, config, identity) {
|
|
10
|
-
this.ctx = ctx;
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.identity = identity;
|
|
13
|
-
}
|
|
14
|
-
start() {
|
|
15
|
-
return (0, tools_1.none)(this);
|
|
16
|
-
}
|
|
17
|
-
stop() {
|
|
18
|
-
return (0, tools_1.none)(this);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.Service = Service;
|
|
22
|
-
exports.default = Service;
|
package/lib/types/core.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type EventsList = {
|
|
2
|
-
[K in keyof EventsMapping]: Parameters<EventsMapping[K]>[1] extends never | undefined | null ? Parameters<EventsMapping[K]>[0] : [...Parameters<EventsMapping[K]>];
|
|
3
|
-
};
|
|
4
|
-
export interface EventsMapping {
|
|
5
|
-
ready(): void;
|
|
6
|
-
dispose(): void;
|
|
7
|
-
}
|
package/lib/types/core.js
DELETED
package/lib/types/modules.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { LocaleType } from '@kotori-bot/i18n';
|
|
2
|
-
declare module './core' {
|
|
3
|
-
interface EventsMapping {
|
|
4
|
-
ready_module(data: EventDataReadyModule): void;
|
|
5
|
-
dispose_module(data: EventDataDisposeModule): void;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
interface EventDataReadyModule {
|
|
9
|
-
module: ModuleInstance | string;
|
|
10
|
-
error?: unknown;
|
|
11
|
-
}
|
|
12
|
-
interface EventDataDisposeModule {
|
|
13
|
-
module: ModuleInstance | string;
|
|
14
|
-
}
|
|
15
|
-
export interface ModulePackage {
|
|
16
|
-
name: string;
|
|
17
|
-
version: string;
|
|
18
|
-
description: string;
|
|
19
|
-
main: string;
|
|
20
|
-
keywords: string[];
|
|
21
|
-
license: 'GPL-3.0';
|
|
22
|
-
author: string | string[];
|
|
23
|
-
peerDependencies: {
|
|
24
|
-
'kotori-bot': string;
|
|
25
|
-
[propName: string]: string;
|
|
26
|
-
};
|
|
27
|
-
kotori: {
|
|
28
|
-
enforce?: 'pre' | 'post';
|
|
29
|
-
meta: {
|
|
30
|
-
language: LocaleType[];
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export interface ModuleInstance {
|
|
35
|
-
pkg: ModulePackage;
|
|
36
|
-
files: string[];
|
|
37
|
-
main: string;
|
|
38
|
-
}
|
|
39
|
-
export {};
|
package/lib/types/modules.js
DELETED
package/lib/types/service.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Context } from '../context';
|
|
2
|
-
import type { Adapter, Service } from '../service';
|
|
3
|
-
import type { AdapterConfig } from './config';
|
|
4
|
-
declare module './core' {
|
|
5
|
-
interface EventsMapping {
|
|
6
|
-
connect(data: EventDataConnect): void;
|
|
7
|
-
status(data: EventDataStatus): void;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
interface EventDataConnect {
|
|
11
|
-
adapter: Adapter;
|
|
12
|
-
type: 'connect' | 'disconnect';
|
|
13
|
-
normal: boolean;
|
|
14
|
-
mode: 'ws' | 'ws-reverse' | 'other';
|
|
15
|
-
address: string;
|
|
16
|
-
}
|
|
17
|
-
interface EventDataStatus {
|
|
18
|
-
adapter: Adapter;
|
|
19
|
-
status: Adapter['status']['value'];
|
|
20
|
-
}
|
|
21
|
-
export type ServiceClass = new (config: object) => Service;
|
|
22
|
-
export type AdapterClass = new (ctx: Context, config: AdapterConfig, identity: string) => Adapter;
|
|
23
|
-
export {};
|
package/lib/types/service.js
DELETED
package/lib/utils/errror.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
type KotoriErrorType = 'ServiceError' | 'ModuleError' | 'UnknownError' | 'DevError';
|
|
2
|
-
interface KotoriErrorImpl {
|
|
3
|
-
readonly name: KotoriErrorType;
|
|
4
|
-
readonly extend: () => typeof KotoriError;
|
|
5
|
-
}
|
|
6
|
-
export declare class KotoriError<T extends object = object> extends Error implements KotoriErrorImpl {
|
|
7
|
-
constructor(message?: string, extra?: T, type?: KotoriErrorType);
|
|
8
|
-
readonly extra?: T;
|
|
9
|
-
readonly name: KotoriErrorType;
|
|
10
|
-
extend(): typeof KotoriError<T>;
|
|
11
|
-
}
|
|
12
|
-
export declare const ModuleError: {
|
|
13
|
-
new (message?: string, extra?: object | undefined, type?: KotoriErrorType): KotoriError<object>;
|
|
14
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
15
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
16
|
-
stackTraceLimit: number;
|
|
17
|
-
};
|
|
18
|
-
export declare const DevError: {
|
|
19
|
-
new (message?: string, extra?: object | undefined, type?: KotoriErrorType): KotoriError<object>;
|
|
20
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
21
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
22
|
-
stackTraceLimit: number;
|
|
23
|
-
};
|
|
24
|
-
export default KotoriError;
|
package/lib/utils/errror.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DevError = exports.ModuleError = exports.KotoriError = void 0;
|
|
4
|
-
class KotoriError extends Error {
|
|
5
|
-
constructor(message, extra, type = 'UnknownError') {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = type;
|
|
8
|
-
this.extra = extra;
|
|
9
|
-
}
|
|
10
|
-
extra;
|
|
11
|
-
name;
|
|
12
|
-
extend() {
|
|
13
|
-
const { message: fatherMessage, name: fatherType, extra: fatherExtra } = this;
|
|
14
|
-
// const newClass: typeof KotoriError = Object.create(KotoriError);
|
|
15
|
-
return new Proxy((KotoriError), {
|
|
16
|
-
construct(Class, params) {
|
|
17
|
-
const args = params;
|
|
18
|
-
args[0] = `${fatherMessage} ${args[0]}`;
|
|
19
|
-
args[1] = args[1] ?? fatherExtra;
|
|
20
|
-
args[2] = args[2] ?? fatherType;
|
|
21
|
-
return new Class(...args);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.KotoriError = KotoriError;
|
|
27
|
-
exports.ModuleError = new KotoriError(undefined, undefined, 'ModuleError').extend();
|
|
28
|
-
exports.DevError = new KotoriError(undefined, undefined, 'DevError').extend();
|
|
29
|
-
exports.default = KotoriError;
|