@kotori-bot/core 1.3.0 → 1.4.0
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/components/core.d.ts +3 -2
- package/lib/components/core.js +5 -4
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/message.d.ts +2 -1
- package/lib/components/message.js +14 -14
- package/lib/constants.d.ts +15 -0
- package/lib/constants.js +19 -0
- package/lib/context/context.d.ts +1 -0
- package/lib/context/context.js +6 -2
- package/lib/context/modules.js +5 -5
- package/lib/global/constants.d.ts +15 -0
- package/lib/global/constants.js +19 -0
- package/lib/global/index.d.ts +2 -0
- package/lib/global/index.js +18 -0
- package/lib/global/symbols.d.ts +8 -0
- package/lib/global/symbols.js +12 -0
- package/lib/global/tokens.d.ts +8 -0
- package/lib/global/tokens.js +12 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +4 -4
- package/lib/service/adapter.d.ts +1 -1
- package/lib/service/adapter.js +8 -8
- package/lib/service/cache.d.ts +1 -1
- package/lib/service/cache.js +2 -2
- package/lib/types/adapter.d.ts +2 -2
- package/lib/types/config.d.ts +2 -1
- package/lib/types/message.d.ts +2 -2
- package/lib/utils/command.js +6 -6
- package/lib/utils/commandError.d.ts +2 -2
- package/lib/utils/commandError.js +2 -2
- package/lib/utils/container.d.ts +1 -1
- package/lib/utils/error.d.ts +25 -0
- package/lib/utils/error.js +29 -0
- package/lib/utils/errror.d.ts +0 -1
- package/lib/utils/factory.d.ts +2 -2
- package/package.json +7 -3
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
|
@@ -7,7 +7,7 @@ exports.Config = void 0;
|
|
|
7
7
|
const tsukiko_1 = __importDefault(require("tsukiko"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const tools_1 = require("@kotori-bot/tools");
|
|
10
|
-
const
|
|
10
|
+
const global_1 = require("../global");
|
|
11
11
|
const packageInfoSchema = tsukiko_1.default.Object({
|
|
12
12
|
name: tsukiko_1.default.String(),
|
|
13
13
|
version: tsukiko_1.default.String(),
|
|
@@ -19,7 +19,7 @@ const packageInfoSchema = tsukiko_1.default.Object({
|
|
|
19
19
|
class Config {
|
|
20
20
|
config;
|
|
21
21
|
pkg;
|
|
22
|
-
constructor(config =
|
|
22
|
+
constructor(config = global_1.DEFAULT_CORE_CONFIG) {
|
|
23
23
|
this.config = config;
|
|
24
24
|
/* load package.json */
|
|
25
25
|
const info = (0, tools_1.loadConfig)((0, path_1.join)(__dirname, '../../package.json'));
|
package/lib/components/core.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Http } from '@kotori-bot/tools';
|
|
2
2
|
import I18n from '@kotori-bot/i18n';
|
|
3
3
|
import type { Parser } from 'tsukiko';
|
|
4
|
-
import { Context
|
|
4
|
+
import { Context } from 'fluoro';
|
|
5
5
|
import Config from './config';
|
|
6
6
|
import Message from './message';
|
|
7
7
|
import type { AdapterClass } from '../types';
|
|
8
8
|
import { Cache, type Api } from '../service';
|
|
9
|
-
|
|
9
|
+
import { Symbols } from '../global';
|
|
10
|
+
declare module 'fluoro' {
|
|
10
11
|
interface Context {
|
|
11
12
|
readonly [Symbols.adapter]: Core[typeof Symbols.adapter];
|
|
12
13
|
readonly [Symbols.bot]: Core[typeof Symbols.bot];
|
package/lib/components/core.js
CHANGED
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Core = void 0;
|
|
7
7
|
const tools_1 = require("@kotori-bot/tools");
|
|
8
8
|
const i18n_1 = __importDefault(require("@kotori-bot/i18n"));
|
|
9
|
-
const
|
|
9
|
+
const fluoro_1 = require("fluoro");
|
|
10
10
|
const config_1 = __importDefault(require("./config"));
|
|
11
11
|
const message_1 = __importDefault(require("./message"));
|
|
12
12
|
const service_1 = require("../service");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[
|
|
13
|
+
const global_1 = require("../global");
|
|
14
|
+
class Core extends fluoro_1.Context {
|
|
15
|
+
[global_1.Symbols.adapter] = new Map();
|
|
16
|
+
[global_1.Symbols.bot] = new Map();
|
|
16
17
|
constructor(config) {
|
|
17
18
|
super();
|
|
18
19
|
this.provide('config', new config_1.default(config));
|
package/lib/components/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type Context
|
|
1
|
+
import { type Context } from 'fluoro';
|
|
2
2
|
import { type CommandConfig, type MidwareCallback, type RegexpCallback } from '../types';
|
|
3
3
|
import { Command } from '../utils/command';
|
|
4
|
+
import { Symbols } from '../global';
|
|
4
5
|
interface MidwareData {
|
|
5
6
|
callback: MidwareCallback;
|
|
6
7
|
priority: number;
|
|
@@ -5,20 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Message = void 0;
|
|
7
7
|
const tools_1 = require("@kotori-bot/tools");
|
|
8
|
-
const context_1 = require("../context");
|
|
9
8
|
const factory_1 = require("../utils/factory");
|
|
10
9
|
const command_1 = require("../utils/command");
|
|
11
10
|
const commandError_1 = __importDefault(require("../utils/commandError"));
|
|
11
|
+
const global_1 = require("../global");
|
|
12
12
|
class Message {
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
13
|
+
[global_1.Symbols.midware] = new Set();
|
|
14
|
+
[global_1.Symbols.command] = new Set();
|
|
15
|
+
[global_1.Symbols.regexp] = new Set();
|
|
16
16
|
handleMidware(session) {
|
|
17
17
|
const { api } = session;
|
|
18
|
-
api.adapter.status.receivedMsg += 1;
|
|
19
18
|
let isPass = true;
|
|
20
19
|
let midwares = [];
|
|
21
|
-
|
|
20
|
+
api.adapter.status.receivedMsg += 1;
|
|
21
|
+
this[global_1.Symbols.midware].forEach((val) => midwares.push(val));
|
|
22
22
|
midwares = midwares.sort((first, second) => first.priority - second.priority);
|
|
23
23
|
let lastMidwareNum = -1;
|
|
24
24
|
while (midwares.length > 0) {
|
|
@@ -35,7 +35,7 @@ class Message {
|
|
|
35
35
|
const { session } = data;
|
|
36
36
|
if (!data.isPass)
|
|
37
37
|
return;
|
|
38
|
-
this[
|
|
38
|
+
this[global_1.Symbols.regexp].forEach((data) => {
|
|
39
39
|
const match = session.message.match(data.match);
|
|
40
40
|
if (!match)
|
|
41
41
|
return;
|
|
@@ -57,7 +57,7 @@ class Message {
|
|
|
57
57
|
if (cancel.value)
|
|
58
58
|
return;
|
|
59
59
|
let matched;
|
|
60
|
-
this[
|
|
60
|
+
this[global_1.Symbols.command].forEach(async (cmd) => {
|
|
61
61
|
if (matched || !cmd.meta.action)
|
|
62
62
|
return;
|
|
63
63
|
const result = command_1.Command.run(params.raw, cmd.meta);
|
|
@@ -111,22 +111,22 @@ class Message {
|
|
|
111
111
|
}
|
|
112
112
|
midware(callback, priority = 100) {
|
|
113
113
|
const data = { callback, priority };
|
|
114
|
-
this[
|
|
115
|
-
const dispose = () => this[
|
|
114
|
+
this[global_1.Symbols.midware].add(data);
|
|
115
|
+
const dispose = () => this[global_1.Symbols.midware].delete(data);
|
|
116
116
|
(0, factory_1.disposeFactory)(this.ctx, dispose);
|
|
117
117
|
return dispose;
|
|
118
118
|
}
|
|
119
119
|
command(template, config) {
|
|
120
120
|
const command = new command_1.Command(template, config);
|
|
121
|
-
this[
|
|
122
|
-
const dispose = () => this[
|
|
121
|
+
this[global_1.Symbols.command].add(command);
|
|
122
|
+
const dispose = () => this[global_1.Symbols.command].delete(command);
|
|
123
123
|
(0, factory_1.disposeFactory)(this.ctx, dispose);
|
|
124
124
|
return command;
|
|
125
125
|
}
|
|
126
126
|
regexp(match, callback) {
|
|
127
127
|
const data = { match, callback };
|
|
128
|
-
this[
|
|
129
|
-
const dispose = () => this[
|
|
128
|
+
this[global_1.Symbols.regexp].add(data);
|
|
129
|
+
const dispose = () => this[global_1.Symbols.regexp].delete(data);
|
|
130
130
|
(0, factory_1.disposeFactory)(this.ctx, dispose);
|
|
131
131
|
return dispose;
|
|
132
132
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
CHANGED
|
@@ -25,6 +25,7 @@ export declare class Context implements ContextImpl {
|
|
|
25
25
|
readonly [Symbols.container]: Map<string, obj>;
|
|
26
26
|
readonly [Symbols.table]: Map<string, string[]>;
|
|
27
27
|
root: Context;
|
|
28
|
+
parent: Context | null;
|
|
28
29
|
constructor(root?: Context);
|
|
29
30
|
get<T = obj | undefined>(prop: string): T;
|
|
30
31
|
inject<T extends Keys>(prop: T): void;
|
package/lib/context/context.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.Context = void 0;
|
|
|
9
9
|
* @Blog: https://hotaru.icu
|
|
10
10
|
* @Date: 2024-02-07 13:44:38
|
|
11
11
|
* @LastEditors: Hotaru biyuehuya@gmail.com
|
|
12
|
-
* @LastEditTime: 2024-
|
|
12
|
+
* @LastEditTime: 2024-05-01 21:32:19
|
|
13
13
|
*/
|
|
14
14
|
const tools_1 = require("@kotori-bot/tools");
|
|
15
15
|
const symbols_1 = __importDefault(require("./symbols"));
|
|
@@ -25,10 +25,12 @@ const handler = (value, ctx) => {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
+
const DEFAULT_EXTENDS_NAME = 'sub';
|
|
28
29
|
class Context {
|
|
29
30
|
[symbols_1.default.container] = new Map();
|
|
30
31
|
[symbols_1.default.table] = new Map();
|
|
31
32
|
root;
|
|
33
|
+
parent = null;
|
|
32
34
|
constructor(root) {
|
|
33
35
|
this.root = root || this;
|
|
34
36
|
this.provide('events', root ? root.get('events') : new tools_1.Events());
|
|
@@ -75,7 +77,9 @@ class Context {
|
|
|
75
77
|
const ctx = new Proxy(new Context(this.root), {
|
|
76
78
|
get: (target, prop) => {
|
|
77
79
|
if (prop === 'identity')
|
|
78
|
-
return identity ?? this.identity ??
|
|
80
|
+
return identity ?? this.identity ?? DEFAULT_EXTENDS_NAME;
|
|
81
|
+
if (prop === 'parent')
|
|
82
|
+
return this;
|
|
79
83
|
if (target[prop])
|
|
80
84
|
return handler(target[prop], ctx);
|
|
81
85
|
let value;
|
package/lib/context/modules.js
CHANGED
|
@@ -9,7 +9,7 @@ const service_1 = require("./service");
|
|
|
9
9
|
function handleFunction(func, ctx, config) {
|
|
10
10
|
func(ctx, config);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function handleConstructor(Class, ctx, config) {
|
|
13
13
|
(0, tools_1.none)(new Class(ctx, config));
|
|
14
14
|
}
|
|
15
15
|
const DEFAULT_MODULE_CONFIG = { filter: {} };
|
|
@@ -22,9 +22,9 @@ class Modules {
|
|
|
22
22
|
const ctx = this.ctx.extends({}, !this.ctx.identity && typeof instance === 'object' ? instance.name : this.ctx.identity);
|
|
23
23
|
if (instance instanceof Function) {
|
|
24
24
|
if ((0, tools_1.isClass)(instance))
|
|
25
|
-
|
|
25
|
+
handleConstructor(instance, ctx, DEFAULT_MODULE_CONFIG);
|
|
26
26
|
else
|
|
27
|
-
instance
|
|
27
|
+
handleFunction(instance, ctx, DEFAULT_MODULE_CONFIG);
|
|
28
28
|
this.ctx.emit('ready_module', { instance });
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
@@ -40,7 +40,7 @@ class Modules {
|
|
|
40
40
|
}
|
|
41
41
|
if (defaults) {
|
|
42
42
|
if ((0, tools_1.isClass)(defaults))
|
|
43
|
-
|
|
43
|
+
handleConstructor(defaults, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
44
44
|
else
|
|
45
45
|
handleFunction(defaults, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
46
46
|
}
|
|
@@ -48,7 +48,7 @@ class Modules {
|
|
|
48
48
|
handleFunction(main, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
49
49
|
}
|
|
50
50
|
else if (Main) {
|
|
51
|
-
|
|
51
|
+
handleConstructor(Main, ctx, config ?? DEFAULT_MODULE_CONFIG);
|
|
52
52
|
}
|
|
53
53
|
this.ctx.emit('ready_module', { instance });
|
|
54
54
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./constants"), exports);
|
|
18
|
+
__exportStar(require("./symbols"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class Symbols {
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Symbols = void 0;
|
|
4
|
+
class Symbols {
|
|
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.Symbols = Symbols;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from 'fluoro';
|
|
2
2
|
export * from './components';
|
|
3
3
|
export * from './service';
|
|
4
4
|
export * from './utils/command';
|
|
5
|
-
export * from './utils/
|
|
5
|
+
export * from './utils/error';
|
|
6
6
|
export * from './utils/commandError';
|
|
7
7
|
export * from './utils/container';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './global';
|
|
9
9
|
export * from './types';
|
|
10
10
|
export * from '@kotori-bot/tools';
|
|
11
11
|
export * from '@kotori-bot/i18n';
|
package/lib/index.js
CHANGED
|
@@ -19,16 +19,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
* @Blog: https://hotaru.icu
|
|
20
20
|
* @Date: 2024-02-07 13:44:38
|
|
21
21
|
* @LastEditors: Hotaru biyuehuya@gmail.com
|
|
22
|
-
* @LastEditTime: 2024-
|
|
22
|
+
* @LastEditTime: 2024-05-03 11:36:22
|
|
23
23
|
*/
|
|
24
|
-
__exportStar(require("
|
|
24
|
+
__exportStar(require("fluoro"), exports);
|
|
25
25
|
__exportStar(require("./components"), exports);
|
|
26
26
|
__exportStar(require("./service"), exports);
|
|
27
27
|
__exportStar(require("./utils/command"), exports);
|
|
28
|
-
__exportStar(require("./utils/
|
|
28
|
+
__exportStar(require("./utils/error"), exports);
|
|
29
29
|
__exportStar(require("./utils/commandError"), exports);
|
|
30
30
|
__exportStar(require("./utils/container"), exports);
|
|
31
|
-
__exportStar(require("./
|
|
31
|
+
__exportStar(require("./global"), exports);
|
|
32
32
|
__exportStar(require("./types"), exports);
|
|
33
33
|
__exportStar(require("@kotori-bot/tools"), exports);
|
|
34
34
|
__exportStar(require("@kotori-bot/i18n"), exports);
|
package/lib/service/adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Context, EventsList } from 'fluoro';
|
|
1
2
|
import type Api from './api';
|
|
2
|
-
import { Context, EventsList } from '../context';
|
|
3
3
|
import { EventDataApiBase, EventDataTargetId, AdapterConfig } from '../types';
|
|
4
4
|
import Elements from './elements';
|
|
5
5
|
type EventApiType = {
|
package/lib/service/adapter.js
CHANGED
|
@@ -5,16 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Adapter = void 0;
|
|
7
7
|
const tools_1 = require("@kotori-bot/tools");
|
|
8
|
-
const context_1 = require("../context");
|
|
9
8
|
const types_1 = require("../types");
|
|
10
9
|
const elements_1 = __importDefault(require("./elements"));
|
|
11
10
|
const factory_1 = require("../utils/factory");
|
|
12
11
|
const commandError_1 = __importDefault(require("../utils/commandError"));
|
|
12
|
+
const global_1 = require("../global");
|
|
13
13
|
function setProxy(api, ctx) {
|
|
14
14
|
const proxy = Object.create(api);
|
|
15
15
|
proxy.sendPrivateMsg = new Proxy(api.sendPrivateMsg, {
|
|
16
16
|
apply(_, __, argArray) {
|
|
17
|
-
const
|
|
17
|
+
const [message, targetId] = argArray;
|
|
18
18
|
const cancel = (0, factory_1.cancelFactory)();
|
|
19
19
|
ctx.emit('before_send', { api, message, messageType: types_1.MessageScope.PRIVATE, targetId, cancel: cancel.get() });
|
|
20
20
|
if (cancel.value)
|
|
@@ -24,7 +24,7 @@ function setProxy(api, ctx) {
|
|
|
24
24
|
});
|
|
25
25
|
proxy.sendGroupMsg = new Proxy(api.sendGroupMsg, {
|
|
26
26
|
apply(_, __, argArray) {
|
|
27
|
-
const
|
|
27
|
+
const [message, targetId] = argArray;
|
|
28
28
|
const cancel = (0, factory_1.cancelFactory)();
|
|
29
29
|
ctx.emit('before_send', { api, message, messageType: types_1.MessageScope.PRIVATE, targetId, cancel: cancel.get() });
|
|
30
30
|
if (cancel.value)
|
|
@@ -62,7 +62,7 @@ function formatFactory(i18n) {
|
|
|
62
62
|
return (0, tools_1.stringTemp)(i18n.locale(template), params);
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function quickFactory(send, i18n) {
|
|
66
66
|
return async (message) => {
|
|
67
67
|
const msg = await message;
|
|
68
68
|
if (!msg || msg instanceof commandError_1.default)
|
|
@@ -118,9 +118,9 @@ class Adapter {
|
|
|
118
118
|
this.platform = config.extends;
|
|
119
119
|
this.api = setProxy(new Api(this), this.ctx);
|
|
120
120
|
this.elements = el;
|
|
121
|
-
if (!this.ctx[
|
|
122
|
-
this.ctx[
|
|
123
|
-
this.ctx[
|
|
121
|
+
if (!this.ctx[global_1.Symbols.bot].get(this.platform))
|
|
122
|
+
this.ctx[global_1.Symbols.bot].set(this.platform, new Set());
|
|
123
|
+
this.ctx[global_1.Symbols.bot].get(this.platform).add(this.api);
|
|
124
124
|
}
|
|
125
125
|
online() {
|
|
126
126
|
if (this.status.value !== 'offline')
|
|
@@ -139,7 +139,7 @@ class Adapter {
|
|
|
139
139
|
const i18n = this.ctx.i18n.extends(this.config.lang);
|
|
140
140
|
const send = sendMessageFactory(this, type, data);
|
|
141
141
|
const format = formatFactory(i18n);
|
|
142
|
-
const quick =
|
|
142
|
+
const quick = quickFactory(send, i18n);
|
|
143
143
|
const prompt = promptFactory(quick, this, data);
|
|
144
144
|
const confirm = confirmFactory(quick, this, data);
|
|
145
145
|
const { api, elements: el } = this;
|
package/lib/service/cache.d.ts
CHANGED
package/lib/service/cache.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Cache = void 0;
|
|
4
|
-
const
|
|
5
|
-
class Cache extends
|
|
4
|
+
const fluoro_1 = require("fluoro");
|
|
5
|
+
class Cache extends fluoro_1.Service {
|
|
6
6
|
cache;
|
|
7
7
|
constructor(ctx) {
|
|
8
8
|
super(ctx, {}, 'cache');
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Context } from '
|
|
1
|
+
import type { Context } from 'fluoro';
|
|
2
2
|
import type { Adapter } from '../service';
|
|
3
3
|
import type { AdapterConfig } from './config';
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'fluoro' {
|
|
5
5
|
interface EventsMapping {
|
|
6
6
|
connect(data: EventDataConnect): void;
|
|
7
7
|
status(data: EventDataStatus): void;
|
package/lib/types/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LocaleType } from '@kotori-bot/i18n';
|
|
2
|
+
import { ModuleConfig } from 'fluoro';
|
|
2
3
|
import type { EventDataTargetId } from './message';
|
|
3
|
-
import { ModuleConfig } from '../context';
|
|
4
4
|
export interface CoreConfig {
|
|
5
5
|
global: GlobalConfig;
|
|
6
6
|
adapter: {
|
|
@@ -11,6 +11,7 @@ export interface CoreConfig {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export interface GlobalConfig {
|
|
14
|
+
level?: number;
|
|
14
15
|
lang: LocaleType;
|
|
15
16
|
'command-prefix': string;
|
|
16
17
|
}
|
package/lib/types/message.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Tsu, { TsuError } from 'tsukiko';
|
|
2
2
|
import type I18n from '@kotori-bot/i18n';
|
|
3
|
-
import type { EventsList } from '
|
|
3
|
+
import type { EventsList } from 'fluoro';
|
|
4
4
|
import type CommandError from '../utils/commandError';
|
|
5
5
|
import type { Api, Elements } from '../service';
|
|
6
6
|
import { Command } from '../utils/command';
|
|
7
|
-
declare module '
|
|
7
|
+
declare module 'fluoro' {
|
|
8
8
|
interface EventsMapping {
|
|
9
9
|
midwares(data: EventDataMidwares): void;
|
|
10
10
|
before_parse(data: EventDataBeforeParse): void;
|
package/lib/utils/command.js
CHANGED
|
@@ -61,15 +61,15 @@ class Command {
|
|
|
61
61
|
const result = (0, minimist_1.default)(arr, opts);
|
|
62
62
|
/* handle args */
|
|
63
63
|
const args = result._;
|
|
64
|
-
const
|
|
64
|
+
const count = {
|
|
65
65
|
expected: data.args.filter((el) => !el.optional).length,
|
|
66
66
|
reality: args.length
|
|
67
67
|
};
|
|
68
|
-
if (
|
|
69
|
-
return new commandError_1.CommandError({ type: 'arg_few', ...
|
|
70
|
-
|
|
71
|
-
if ((data.args.length <= 0 || !data.args[data.args.length - 1].rest) &&
|
|
72
|
-
return new commandError_1.CommandError({ type: 'arg_many', ...
|
|
68
|
+
if (count.reality < count.expected)
|
|
69
|
+
return new commandError_1.CommandError({ type: 'arg_few', ...count });
|
|
70
|
+
count.expected = data.args.length;
|
|
71
|
+
if ((data.args.length <= 0 || !data.args[data.args.length - 1].rest) && count.reality > count.expected)
|
|
72
|
+
return new commandError_1.CommandError({ type: 'arg_many', ...count });
|
|
73
73
|
let error;
|
|
74
74
|
data.args.forEach((val, index) => {
|
|
75
75
|
/* exit when happen error or last arg is empty */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommandResultExtra } from '../types';
|
|
2
|
-
import { KotoriError } from './
|
|
2
|
+
import { KotoriError } from './error';
|
|
3
3
|
export declare class CommandError extends KotoriError {
|
|
4
|
-
value: CommandResultExtra[keyof CommandResultExtra];
|
|
4
|
+
readonly value: CommandResultExtra[keyof CommandResultExtra];
|
|
5
5
|
constructor(value: CommandResultExtra[keyof CommandResultExtra]);
|
|
6
6
|
}
|
|
7
7
|
export default CommandError;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandError = void 0;
|
|
4
|
-
const
|
|
5
|
-
class CommandError extends
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
class CommandError extends error_1.KotoriError {
|
|
6
6
|
value;
|
|
7
7
|
constructor(value) {
|
|
8
8
|
super();
|
package/lib/utils/container.d.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
type KotoriErrorType = 'ServiceError' | 'ModuleError' | 'UnknownError' | 'DevError';
|
|
3
|
+
interface KotoriErrorImpl {
|
|
4
|
+
readonly name: KotoriErrorType;
|
|
5
|
+
readonly extend: () => typeof KotoriError;
|
|
6
|
+
}
|
|
7
|
+
export declare class KotoriError<T extends object = object> extends Error implements KotoriErrorImpl {
|
|
8
|
+
constructor(message?: string, extra?: T, type?: KotoriErrorType);
|
|
9
|
+
readonly extra?: T;
|
|
10
|
+
readonly name: KotoriErrorType;
|
|
11
|
+
extend(): typeof KotoriError<T>;
|
|
12
|
+
}
|
|
13
|
+
export declare const ModuleError: {
|
|
14
|
+
new (message?: string, extra?: object | undefined, type?: KotoriErrorType): KotoriError<object>;
|
|
15
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
16
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
17
|
+
stackTraceLimit: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const DevError: {
|
|
20
|
+
new (message?: string, extra?: object | undefined, type?: KotoriErrorType): KotoriError<object>;
|
|
21
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
22
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
23
|
+
stackTraceLimit: number;
|
|
24
|
+
};
|
|
25
|
+
export default KotoriError;
|
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
package/lib/utils/errror.d.ts
CHANGED
package/lib/utils/factory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Context } from '
|
|
2
|
-
export declare function disposeFactory(ctx: Context, dispose:
|
|
1
|
+
import type { Context } from 'fluoro';
|
|
2
|
+
export declare function disposeFactory(ctx: Context, dispose: () => void): void;
|
|
3
3
|
export declare function cancelFactory(): {
|
|
4
4
|
get(): () => void;
|
|
5
5
|
fn(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kotori-bot/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Kotori Core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -27,7 +27,11 @@
|
|
|
27
27
|
"@types/minimist": "^1.2.5",
|
|
28
28
|
"minimist": "^1.2.8",
|
|
29
29
|
"tsukiko": "^1.2.1",
|
|
30
|
-
"@kotori-bot/
|
|
31
|
-
"@kotori-bot/
|
|
30
|
+
"@kotori-bot/i18n": "^1.2.1",
|
|
31
|
+
"@kotori-bot/tools": "^1.3.0",
|
|
32
|
+
"fluoro": "^1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc --build"
|
|
32
36
|
}
|
|
33
37
|
}
|