2020-05-02 16:14:47 +00:00
|
|
|
import { server, MiaoScriptConsole, event } from "@ccms/api";
|
2020-05-07 10:33:10 +00:00
|
|
|
import { injectable, inject, postConstruct } from "@ccms/container";
|
2020-01-17 09:45:13 +00:00
|
|
|
import { getPluginMetadata } from "./utils";
|
2019-09-07 04:23:15 +00:00
|
|
|
|
|
|
|
export namespace interfaces {
|
|
|
|
@injectable()
|
|
|
|
export abstract class Plugin {
|
|
|
|
public description: PluginMetadata;
|
2019-09-10 09:22:00 +00:00
|
|
|
public logger: Console;
|
2020-05-07 10:33:10 +00:00
|
|
|
@inject(server.Console)
|
|
|
|
private Console: MiaoScriptConsole;
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2020-05-07 10:33:10 +00:00
|
|
|
constructor() {
|
2020-01-17 09:45:13 +00:00
|
|
|
this.description = getPluginMetadata(this)
|
2020-05-07 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@postConstruct()
|
|
|
|
private initialize() {
|
2020-01-17 09:45:13 +00:00
|
|
|
// @ts-ignore
|
2020-05-07 10:33:10 +00:00
|
|
|
this.logger = new this.Console(this.description.prefix || this.description.name)
|
2020-01-17 09:45:13 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
public load() { }
|
|
|
|
public enable() { }
|
|
|
|
public disable() { }
|
|
|
|
}
|
2020-01-17 03:11:20 +00:00
|
|
|
interface BaseMetadata {
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 名称 为空则为对象名称
|
|
|
|
*/
|
2020-01-17 03:11:20 +00:00
|
|
|
name?: string;
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 支持的服务器列表 为空则代表所有
|
|
|
|
*/
|
2020-01-17 03:11:20 +00:00
|
|
|
servers?: string[];
|
|
|
|
}
|
|
|
|
export interface PluginMetadata extends BaseMetadata {
|
2019-09-22 10:02:28 +00:00
|
|
|
/**
|
|
|
|
* 插件名称
|
|
|
|
*/
|
2019-09-07 04:23:15 +00:00
|
|
|
name: string;
|
2019-09-22 10:02:28 +00:00
|
|
|
/**
|
|
|
|
* 前缀
|
|
|
|
*/
|
|
|
|
prefix?: string;
|
|
|
|
/**
|
|
|
|
* 插件版本
|
|
|
|
*/
|
2019-09-07 04:23:15 +00:00
|
|
|
version: string;
|
2019-09-22 10:02:28 +00:00
|
|
|
/**
|
|
|
|
* 插件版本
|
|
|
|
*/
|
2019-09-07 04:23:15 +00:00
|
|
|
author: string | string[];
|
2019-09-22 10:02:28 +00:00
|
|
|
/**
|
|
|
|
* 插件源文件 必须指定为 __filename
|
|
|
|
*/
|
2019-09-19 10:59:32 +00:00
|
|
|
source: string;
|
2020-05-08 10:41:56 +00:00
|
|
|
/**
|
|
|
|
* 插件类型 默认为 ioc 执行 MiaoScript 加载逻辑
|
|
|
|
*/
|
|
|
|
type?: string;
|
2019-09-22 10:02:28 +00:00
|
|
|
/**
|
|
|
|
* 插件本体
|
|
|
|
*/
|
2019-09-07 04:23:15 +00:00
|
|
|
target?: any;
|
|
|
|
}
|
2020-04-24 07:38:00 +00:00
|
|
|
export interface ExecMetadata extends BaseMetadata {
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 执行器
|
|
|
|
*/
|
2019-09-19 10:59:32 +00:00
|
|
|
executor?: string;
|
2020-01-17 03:11:20 +00:00
|
|
|
}
|
|
|
|
export interface CommandMetadata extends ExecMetadata {
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 参数列表
|
|
|
|
*/
|
2019-09-19 10:59:32 +00:00
|
|
|
paramtypes?: string[];
|
|
|
|
}
|
2020-01-17 03:11:20 +00:00
|
|
|
export interface ListenerMetadata extends ExecMetadata {
|
2020-04-24 07:38:00 +00:00
|
|
|
/**
|
|
|
|
* 监听优先级
|
|
|
|
*/
|
|
|
|
priority?: event.EventPriority;
|
|
|
|
/**
|
|
|
|
* 是否忽略已取消的事件
|
|
|
|
*/
|
|
|
|
ignoreCancel?: boolean;
|
|
|
|
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
2020-02-23 16:12:32 +00:00
|
|
|
export interface ConfigMetadata extends BaseMetadata {
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 配置文件版本号
|
|
|
|
*/
|
2020-02-23 16:12:32 +00:00
|
|
|
version?: number;
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 实体变量名称
|
|
|
|
*/
|
2020-02-24 08:24:36 +00:00
|
|
|
variable?: string;
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 配置文件格式 默认 yml
|
|
|
|
*/
|
2020-02-24 08:24:36 +00:00
|
|
|
format?: string;
|
2020-02-23 16:12:32 +00:00
|
|
|
}
|
2019-09-19 10:59:32 +00:00
|
|
|
export type PluginLike = Plugin | string;
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|