ms/packages/plugin/src/interfaces.ts

106 lines
2.5 KiB
TypeScript
Raw Normal View History

import { server, MiaoScriptConsole, event } from "@ccms/api";
import { injectable, inject, postConstruct } from "@ccms/container";
import { getPluginMetadata } from "./utils";
export namespace interfaces {
@injectable()
export abstract class Plugin {
public description: PluginMetadata;
public logger: Console;
@inject(server.Console)
private Console: MiaoScriptConsole;
constructor() {
this.description = getPluginMetadata(this)
}
@postConstruct()
private initialize() {
// @ts-ignore
this.logger = new this.Console(this.description.prefix || this.description.name)
}
public load() { }
public enable() { }
public disable() { }
}
interface BaseMetadata {
/**
*
*/
name?: string;
/**
*
*/
servers?: string[];
}
export interface PluginMetadata extends BaseMetadata {
/**
*
*/
name: string;
/**
*
*/
prefix?: string;
/**
*
*/
version: string;
/**
*
*/
author: string | string[];
/**
* __filename
*/
source: string;
2020-05-08 10:41:56 +00:00
/**
* ioc MiaoScript
*/
type?: string;
/**
*
*/
target?: any;
}
export interface ExecMetadata extends BaseMetadata {
/**
*
*/
executor?: string;
}
export interface CommandMetadata extends ExecMetadata {
/**
*
*/
paramtypes?: string[];
}
export interface ListenerMetadata extends ExecMetadata {
/**
*
*/
priority?: event.EventPriority;
/**
*
*/
ignoreCancel?: boolean;
}
export interface ConfigMetadata extends BaseMetadata {
/**
*
*/
version?: number;
/**
*
*/
variable?: string;
/**
* yml
*/
format?: string;
}
export type PluginLike = Plugin | string;
}