@yumerijs/core 1.1.0-alpha.1 → 1.1.0-alpha.3

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/dist/command.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  **/
6
6
  import { Core } from './core';
7
7
  import { Session } from './session';
8
+ import { Middleware } from './middleware';
8
9
  interface ActionFn {
9
10
  (session: any, ...args: any[]): Promise<any>;
10
11
  }
@@ -12,8 +13,33 @@ export declare class Command {
12
13
  name: string;
13
14
  actionFn: ActionFn | null;
14
15
  core: Core;
16
+ middlewares: Middleware[];
15
17
  constructor(core: Core, name: string);
18
+ /**
19
+ * 注册命令处理函数
20
+ * @param fn 处理函数
21
+ * @returns this 支持链式调用
22
+ */
16
23
  action(fn: ActionFn): this;
24
+ /**
25
+ * 注册命令特定的中间件
26
+ * @param middleware 中间件函数
27
+ * @returns this 支持链式调用
28
+ */
29
+ use(middleware: Middleware): this;
30
+ /**
31
+ * 执行命令,包括中间件链和处理函数
32
+ * @param session 会话对象
33
+ * @param args 其他参数
34
+ * @returns 处理后的会话对象
35
+ */
17
36
  execute(session: any, ...args: any[]): Promise<Session | null>;
37
+ /**
38
+ * 执行命令处理函数(不包含中间件)
39
+ * @param session 会话对象
40
+ * @param args 其他参数
41
+ * @returns 处理后的会话对象
42
+ */
43
+ executeHandler(session: any, ...args: any[]): Promise<Session | null>;
18
44
  }
19
45
  export {};
package/dist/command.js CHANGED
@@ -8,14 +8,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.Command = void 0;
9
9
  class Command {
10
10
  constructor(core, name) {
11
- this.actionFn = null; // Corrected type: ActionFn | null
12
- this.core = core; // 接收 Core 实例
11
+ this.actionFn = null;
12
+ this.middlewares = []; // 存储命令特定的中间件
13
+ this.core = core;
13
14
  this.name = name;
14
15
  }
16
+ /**
17
+ * 注册命令处理函数
18
+ * @param fn 处理函数
19
+ * @returns this 支持链式调用
20
+ */
15
21
  action(fn) {
16
22
  this.actionFn = fn;
17
23
  return this;
18
24
  }
25
+ /**
26
+ * 注册命令特定的中间件
27
+ * @param middleware 中间件函数
28
+ * @returns this 支持链式调用
29
+ */
30
+ use(middleware) {
31
+ this.middlewares.push(middleware);
32
+ return this;
33
+ }
34
+ /**
35
+ * 执行命令,包括中间件链和处理函数
36
+ * @param session 会话对象
37
+ * @param args 其他参数
38
+ * @returns 处理后的会话对象
39
+ */
19
40
  async execute(session, ...args) {
20
41
  if (this.actionFn) {
21
42
  await this.actionFn(session, ...args);
@@ -23,6 +44,19 @@ class Command {
23
44
  }
24
45
  return null;
25
46
  }
47
+ /**
48
+ * 执行命令处理函数(不包含中间件)
49
+ * @param session 会话对象
50
+ * @param args 其他参数
51
+ * @returns 处理后的会话对象
52
+ */
53
+ async executeHandler(session, ...args) {
54
+ if (this.actionFn) {
55
+ await this.actionFn(session, ...args);
56
+ return session;
57
+ }
58
+ return null;
59
+ }
26
60
  }
27
61
  exports.Command = Command;
28
62
  //# sourceMappingURL=command.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";AAAA;;;;IAII;;;AASJ,MAAa,OAAO;IAKlB,YAAY,IAAU,EAAE,IAAY;QAHpC,aAAQ,GAAoB,IAAI,CAAC,CAAC,kCAAkC;QAIlE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,aAAa;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,EAAY;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAY,EAAE,GAAG,IAAW;QACxC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YACtC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtBD,0BAsBC"}
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";AAAA;;;;IAII;;;AAUJ,MAAa,OAAO;IAMlB,YAAY,IAAU,EAAE,IAAY;QAJpC,aAAQ,GAAoB,IAAI,CAAC;QAEjC,gBAAW,GAAiB,EAAE,CAAC,CAAC,aAAa;QAG3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,EAAY;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,UAAsB;QACxB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,OAAY,EAAE,GAAG,IAAW;QACxC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YACtC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY,EAAE,GAAG,IAAW;QAC/C,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YACtC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA1DD,0BA0DC"}
package/dist/config.d.ts CHANGED
@@ -1,14 +1,122 @@
1
1
  /**
2
- * @time: 2025/03/24 12:26
2
+ * @time: 2025/05/24 12:18
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
+ /**
7
+ * 插件配置模式定义类
8
+ * 用于描述插件配置项的类型、默认值、描述等信息
9
+ */
10
+ export declare class ConfigSchema {
11
+ /**
12
+ * 配置项类型
13
+ */
14
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
15
+ /**
16
+ * 默认值
17
+ */
18
+ default?: any;
19
+ /**
20
+ * 配置项描述
21
+ */
22
+ description?: string;
23
+ /**
24
+ * 是否必需
25
+ */
26
+ required?: boolean;
27
+ /**
28
+ * 枚举值列表(可选项)
29
+ */
30
+ enum?: any[];
31
+ /**
32
+ * 数组项类型定义(当type为array时使用)
33
+ */
34
+ items?: ConfigSchema;
35
+ /**
36
+ * 对象属性定义(当type为object时使用)
37
+ */
38
+ properties?: Record<string, ConfigSchema>;
39
+ /**
40
+ * 创建配置模式对象
41
+ * @param type 配置项类型
42
+ * @param options 配置项选项
43
+ */
44
+ constructor(type: 'string' | 'number' | 'boolean' | 'object' | 'array', options?: {
45
+ default?: any;
46
+ description?: string;
47
+ required?: boolean;
48
+ enum?: any[];
49
+ items?: ConfigSchema;
50
+ properties?: Record<string, ConfigSchema>;
51
+ });
52
+ /**
53
+ * 创建字符串类型配置模式
54
+ * @param options 配置项选项
55
+ * @returns 配置模式对象
56
+ */
57
+ static string(options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
58
+ /**
59
+ * 创建数字类型配置模式
60
+ * @param options 配置项选项
61
+ * @returns 配置模式对象
62
+ */
63
+ static number(options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
64
+ /**
65
+ * 创建布尔类型配置模式
66
+ * @param options 配置项选项
67
+ * @returns 配置模式对象
68
+ */
69
+ static boolean(options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
70
+ /**
71
+ * 创建对象类型配置模式
72
+ * @param properties 对象属性定义
73
+ * @param options 配置项选项
74
+ * @returns 配置模式对象
75
+ */
76
+ static object(properties: Record<string, ConfigSchema>, options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
77
+ /**
78
+ * 创建数组类型配置模式
79
+ * @param items 数组项类型定义
80
+ * @param options 配置项选项
81
+ * @returns 配置模式对象
82
+ */
83
+ static array(items: ConfigSchema, options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
84
+ }
6
85
  export declare class Config {
86
+ /**
87
+ * 配置名称
88
+ */
7
89
  name: string;
90
+ /**
91
+ * 配置内容
92
+ */
8
93
  content: {
9
94
  [name: string]: any;
10
95
  };
96
+ /**
97
+ * 配置模式
98
+ */
99
+ schema?: Record<string, ConfigSchema>;
100
+ /**
101
+ * 创建配置对象
102
+ * @param name 配置名称
103
+ * @param content 配置内容
104
+ * @param schema 配置模式
105
+ */
11
106
  constructor(name: string, content?: {
12
107
  [name: string]: any;
13
- });
108
+ }, schema?: Record<string, ConfigSchema>);
109
+ /**
110
+ * 获取配置项值
111
+ * @param key 配置项键名
112
+ * @param defaultValue 默认值
113
+ * @returns 配置项值
114
+ */
115
+ get<T>(key: string, defaultValue?: T): T;
116
+ /**
117
+ * 设置配置项值
118
+ * @param key 配置项键名
119
+ * @param value 配置项值
120
+ */
121
+ set(key: string, value: any): void;
14
122
  }
package/dist/config.js CHANGED
@@ -1,17 +1,119 @@
1
1
  "use strict";
2
2
  /**
3
- * @time: 2025/03/24 12:26
3
+ * @time: 2025/05/24 12:18
4
4
  * @author: FireGuo
5
5
  * WindyPear-Team All right reserved
6
6
  **/
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.Config = void 0;
8
+ exports.Config = exports.ConfigSchema = void 0;
9
+ /**
10
+ * 插件配置模式定义类
11
+ * 用于描述插件配置项的类型、默认值、描述等信息
12
+ */
13
+ class ConfigSchema {
14
+ /**
15
+ * 创建配置模式对象
16
+ * @param type 配置项类型
17
+ * @param options 配置项选项
18
+ */
19
+ constructor(type, options) {
20
+ this.type = type;
21
+ if (options) {
22
+ this.default = options.default;
23
+ this.description = options.description;
24
+ this.required = options.required;
25
+ this.enum = options.enum;
26
+ this.items = options.items;
27
+ this.properties = options.properties;
28
+ }
29
+ }
30
+ /**
31
+ * 创建字符串类型配置模式
32
+ * @param options 配置项选项
33
+ * @returns 配置模式对象
34
+ */
35
+ static string(options) {
36
+ return new ConfigSchema('string', options);
37
+ }
38
+ /**
39
+ * 创建数字类型配置模式
40
+ * @param options 配置项选项
41
+ * @returns 配置模式对象
42
+ */
43
+ static number(options) {
44
+ return new ConfigSchema('number', options);
45
+ }
46
+ /**
47
+ * 创建布尔类型配置模式
48
+ * @param options 配置项选项
49
+ * @returns 配置模式对象
50
+ */
51
+ static boolean(options) {
52
+ return new ConfigSchema('boolean', options);
53
+ }
54
+ /**
55
+ * 创建对象类型配置模式
56
+ * @param properties 对象属性定义
57
+ * @param options 配置项选项
58
+ * @returns 配置模式对象
59
+ */
60
+ static object(properties, options) {
61
+ return new ConfigSchema('object', { ...options, properties });
62
+ }
63
+ /**
64
+ * 创建数组类型配置模式
65
+ * @param items 数组项类型定义
66
+ * @param options 配置项选项
67
+ * @returns 配置模式对象
68
+ */
69
+ static array(items, options) {
70
+ return new ConfigSchema('array', { ...options, items });
71
+ }
72
+ }
73
+ exports.ConfigSchema = ConfigSchema;
9
74
  class Config {
10
- constructor(name, content) {
75
+ /**
76
+ * 创建配置对象
77
+ * @param name 配置名称
78
+ * @param content 配置内容
79
+ * @param schema 配置模式
80
+ */
81
+ constructor(name, content, schema) {
82
+ /**
83
+ * 配置名称
84
+ */
11
85
  this.name = '';
86
+ /**
87
+ * 配置内容
88
+ */
12
89
  this.content = {};
13
90
  this.name = name;
14
91
  this.content = content || {}; // 如果 content 是 undefined,则赋值为空对象
92
+ this.schema = schema;
93
+ }
94
+ /**
95
+ * 获取配置项值
96
+ * @param key 配置项键名
97
+ * @param defaultValue 默认值
98
+ * @returns 配置项值
99
+ */
100
+ get(key, defaultValue) {
101
+ if (this.content[key] !== undefined) {
102
+ return this.content[key];
103
+ }
104
+ // 如果有schema,尝试从schema中获取默认值
105
+ if (this.schema && this.schema[key] && this.schema[key].default !== undefined) {
106
+ return this.schema[key].default;
107
+ }
108
+ return defaultValue;
109
+ }
110
+ /**
111
+ * 设置配置项值
112
+ * @param key 配置项键名
113
+ * @param value 配置项值
114
+ */
115
+ set(key, value) {
116
+ this.content[key] = value;
15
117
  }
16
118
  }
17
119
  exports.Config = Config;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;IAII;;;AAEJ,MAAa,MAAM;IAIf,YAAY,IAAY,EAAE,OAAiC;QAHpD,SAAI,GAAW,EAAE,CAAC;QAClB,YAAO,GAA4B,EAAE,CAAC;QAGzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC,CAAC,iCAAiC;IACnE,CAAC;CACJ;AARD,wBAQC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;IAII;;;AAEJ;;;GAGG;AACH,MAAa,YAAY;IAoCrB;;;;OAIG;IACH,YACE,IAA0D,EAC1D,OAOC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;YACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACvC,CAAC;IACH,CAA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AAG,CAAM,CAAC;QAClC,CAAC;QAED,4BAA4B;QAC5B,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAC5E,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAY,CAAC;QACzC,CAAC;QAED,OAAO,YAAiB,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAAW,EAAE,KAAU;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;CAuBJ;AA7ED,wBA6EC"}
@@ -0,0 +1,17 @@
1
+ import { Core } from './core';
2
+ import { Command } from './command';
3
+ export declare class Context {
4
+ private core;
5
+ pluginname: string;
6
+ constructor(core: Core, pluginname: string);
7
+ command(name: string): Command;
8
+ on(name: string, listener: (...args: any[]) => Promise<void>): void;
9
+ use(name: string, callback: Function): void;
10
+ /**
11
+ * Unless nessesary, do not use core directly
12
+ */
13
+ getCore(): Core;
14
+ emit(event: string, ...args: any[]): Promise<void>;
15
+ getComponent(name: string): any;
16
+ registerComponent(name: string, component: any): void;
17
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Context = void 0;
4
+ const command_1 = require("./command");
5
+ class Context {
6
+ constructor(core, pluginname) {
7
+ this.core = core;
8
+ this.pluginname = pluginname;
9
+ }
10
+ command(name) {
11
+ if (this.core.commands[name]) {
12
+ this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register command "${name}", but it has been registered by plugin "${this.core.cmdtoplu[name]}."`);
13
+ return new command_1.Command(this.core, name);
14
+ }
15
+ else {
16
+ this.core.cmdtoplu[name] = this.pluginname;
17
+ return this.core.command(name);
18
+ }
19
+ }
20
+ on(name, listener) {
21
+ // 存储该插件监听的事件,需要注意的是一个事件可由多个插件监听
22
+ this.core.evttoplu[name][this.pluginname].push(listener);
23
+ this.core.on(name, listener);
24
+ }
25
+ use(name, callback) {
26
+ this.core.mdwtoplu[name] = this.pluginname;
27
+ this.core.use(name, async (...args) => {
28
+ return callback(...args);
29
+ });
30
+ }
31
+ /**
32
+ * Unless nessesary, do not use core directly
33
+ */
34
+ getCore() {
35
+ return this.core;
36
+ }
37
+ async emit(event, ...args) {
38
+ return await this.core.emit(event, ...args);
39
+ }
40
+ getComponent(name) {
41
+ return this.core.getComponent(name);
42
+ }
43
+ registerComponent(name, component) {
44
+ if (this.core.components[name]) {
45
+ this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register component "${name}", but it has been registered by plugin "${this.core.comtoplu[name]}."`);
46
+ return;
47
+ }
48
+ this.core.comtoplu[name] = this.pluginname;
49
+ this.core.components[name] = component;
50
+ return;
51
+ }
52
+ }
53
+ exports.Context = Context;
54
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC,MAAa,OAAO;IAGhB,YAAY,IAAU,EAAE,UAAkB;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,IAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,kCAAkC,IAAI,4CAA4C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/J,OAAO,IAAI,iBAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACvC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,IAAI,CA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AAI,4CAA4C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjK,OAAM;QACV,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAC3C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;QACvC,OAAO;IACX,CAAC;CACJ;AAjDD,0BAiDC"}
package/dist/core.d.ts CHANGED
@@ -3,9 +3,11 @@ import { Logger } from './logger';
3
3
  import { Command } from './command';
4
4
  import { Session } from './session';
5
5
  import { Platform } from './platform';
6
+ import { Middleware } from './middleware';
7
+ import { Context } from './context';
6
8
  interface Plugin {
7
- apply: (core: Core, config: Config) => Promise<void>;
8
- disable: (core: Core) => Promise<void>;
9
+ apply: (ctx: Context, config: Config) => Promise<void>;
10
+ disable: (ctx: Context) => Promise<void>;
9
11
  depend: Array<string>;
10
12
  provide: Array<string>;
11
13
  }
@@ -26,14 +28,30 @@ export declare class Core {
26
28
  config: any;
27
29
  platforms: Platform[];
28
30
  private eventListeners;
29
- private components;
31
+ components: {
32
+ [name: string]: any;
33
+ };
30
34
  commands: Record<string, Command>;
31
- private pluginLoader;
32
- private logger;
33
- private providedComponents;
35
+ pluginLoader: PluginLoader;
36
+ logger: Logger;
37
+ providedComponents: {
38
+ [name: string]: string;
39
+ };
34
40
  private pluginModules;
41
+ private configPath;
42
+ private globalMiddlewares;
43
+ cmdtoplu: Record<string, string>;
44
+ comtoplu: Record<string, string>;
45
+ evttoplu: Record<string, Record<string, ((...args: any[]) => Promise<void>)[]>>;
46
+ mdwtoplu: Record<string, string>;
47
+ plftoplu: Record<string, string>;
35
48
  constructor(pluginLoader: PluginLoader);
36
49
  loadConfig(configPath: string): Promise<void>;
50
+ /**
51
+ * 监听配置文件变化
52
+ * @param configPath 配置文件路径
53
+ */
54
+ private watchConfig;
37
55
  getPluginConfig(pluginName: string): Promise<Config>;
38
56
  loadPlugins(): Promise<void>;
39
57
  /**
@@ -42,15 +60,27 @@ export declare class Core {
42
60
  * @param pluginsDir 插件目录
43
61
  */
44
62
  watchPlugins(core: Core, pluginsDir?: string): void;
45
- private reloadPlugin;
46
- private unloadPluginAndEmit;
63
+ /**
64
+ * 重新加载插件
65
+ * @param pluginName 插件名称
66
+ * @param core Core实例
67
+ */
68
+ reloadPlugin(pluginName: string, core: Core): Promise<void>;
69
+ /**
70
+ * 卸载插件并触发事件
71
+ * @param pluginName 插件名称
72
+ * @param core Core实例
73
+ */
74
+ unloadPluginAndEmit(pluginName: string, core: Core): Promise<void>;
47
75
  registerComponent(name: string, component: any): void;
48
76
  getComponent(name: string): any;
49
77
  unregisterComponent(name: string): void;
50
78
  on(event: string, listener: (...args: any[]) => Promise<void>): void;
51
79
  emit(event: string, ...args: any[]): Promise<void>;
80
+ use(name: string, middleware: Middleware): Core;
52
81
  command(name: string): Command;
53
82
  executeCommand(name: string, session: any, ...args: any[]): Promise<Session | null>;
54
83
  registerPlatform(platform: Platform): any;
84
+ unregall(pluginname: string): void;
55
85
  }
56
86
  export {};