2020-06-17 10:39:24 +00:00
|
|
|
import { server, MiaoScriptConsole, event, plugin } from "@ccms/api"
|
|
|
|
import { injectable, inject, postConstruct } from "@ccms/container"
|
|
|
|
import { getPluginMetadata } from "./utils"
|
2019-09-07 04:23:15 +00:00
|
|
|
|
|
|
|
export namespace interfaces {
|
|
|
|
@injectable()
|
2020-06-02 10:01:56 +00:00
|
|
|
export abstract class Plugin implements plugin.Plugin {
|
2020-06-17 10:39:24 +00:00
|
|
|
public description: plugin.PluginMetadata
|
|
|
|
public logger: Console
|
2020-05-07 10:33:10 +00:00
|
|
|
@inject(server.Console)
|
2020-06-17 10:39:24 +00:00
|
|
|
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-06-17 10:39:24 +00:00
|
|
|
export interface ExecMetadata extends plugin.BaseMetadata {
|
2020-09-17 09:44:48 +00:00
|
|
|
/**
|
|
|
|
* 执行器所在对象 用于绑定this
|
|
|
|
*/
|
|
|
|
target?: any
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 执行器
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
executor?: string
|
2020-01-17 03:11:20 +00:00
|
|
|
}
|
|
|
|
export interface CommandMetadata extends ExecMetadata {
|
2020-09-22 09:33:59 +00:00
|
|
|
/**
|
|
|
|
* 命令别名
|
|
|
|
*/
|
|
|
|
alias?: string[]
|
2020-06-20 08:38:14 +00:00
|
|
|
/**
|
|
|
|
* 命令描述
|
|
|
|
*/
|
|
|
|
description?: string
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 参数列表
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
paramtypes?: string[]
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
2020-01-17 03:11:20 +00:00
|
|
|
export interface ListenerMetadata extends ExecMetadata {
|
2020-04-24 07:38:00 +00:00
|
|
|
/**
|
|
|
|
* 监听优先级
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
priority?: event.EventPriority
|
2020-04-24 07:38:00 +00:00
|
|
|
/**
|
|
|
|
* 是否忽略已取消的事件
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
ignoreCancel?: boolean
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
2020-06-17 10:39:24 +00:00
|
|
|
export interface ConfigMetadata extends plugin.BaseMetadata {
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 配置文件版本号
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
version?: number
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 实体变量名称
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
variable?: string
|
2020-02-25 15:15:39 +00:00
|
|
|
/**
|
|
|
|
* 配置文件格式 默认 yml
|
|
|
|
*/
|
2020-06-17 10:39:24 +00:00
|
|
|
format?: string
|
2020-05-15 06:28:40 +00:00
|
|
|
/**
|
2020-10-31 03:40:38 +00:00
|
|
|
* 自动保存 默认为 false
|
2020-05-15 06:28:40 +00:00
|
|
|
*/
|
2020-10-31 03:40:38 +00:00
|
|
|
autosave?: boolean
|
2020-09-24 10:36:10 +00:00
|
|
|
/**
|
|
|
|
* 配置文件名称
|
|
|
|
*/
|
|
|
|
filename?: string
|
|
|
|
/**
|
|
|
|
* 配置文件全路径
|
|
|
|
*/
|
|
|
|
file?: any
|
2020-02-23 16:12:32 +00:00
|
|
|
}
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|