Commit 3942369f authored by nanahira's avatar nanahira

Migrate schema to Config

parent 90baedb6
import 'source-map-support/register'; import 'source-map-support/register';
import type { Context } from 'koishi'; import type { Context } from 'koishi';
import { Config, MyPlugin } from './plugin'; import { PluginConfig, MyPlugin } from './plugin';
export { Config } from './plugin'; export * from './plugin';
declare module 'koishi' { declare module 'koishi' {
interface Modules { interface Modules {
...@@ -11,7 +11,7 @@ declare module 'koishi' { ...@@ -11,7 +11,7 @@ declare module 'koishi' {
export const name = 'act'; export const name = 'act';
const plugin = new MyPlugin(); const plugin = new MyPlugin();
export const schema = plugin.schema; export const Config = plugin.schema;
export function apply(ctx: Context, config: Config) { export function apply(ctx: Context, config: PluginConfig) {
ctx.plugin(plugin, config); ctx.plugin(plugin, config);
} }
...@@ -26,7 +26,7 @@ export interface Selection extends BaseSelection { ...@@ -26,7 +26,7 @@ export interface Selection extends BaseSelection {
$not?: Selection; $not?: Selection;
} }
export interface Config { export interface PluginConfig {
adminContext?: Selection; adminContext?: Selection;
autoChangeName?: boolean; autoChangeName?: boolean;
dropHelp?: boolean; dropHelp?: boolean;
...@@ -34,13 +34,13 @@ export interface Config { ...@@ -34,13 +34,13 @@ export interface Config {
} }
export class MyPlugin { export class MyPlugin {
config: Config; config: PluginConfig;
ctx: Context; ctx: Context;
adminCtx: Context; adminCtx: Context;
shows = new Map<string, Show>(); shows = new Map<string, Show>();
name = 'act-main'; name = 'act-main';
schema: Schema<Config> = Schema.object({ schema: Schema<PluginConfig> = Schema.object({
adminContext: Schema.any().description('管理员接口作用域。'), adminContext: Schema.any().description('管理员接口作用域。'),
autoChangeName: Schema.boolean() autoChangeName: Schema.boolean()
.description('公演开始之前是否修改每个演员机器人的群名片。推荐开启。') .description('公演开始之前是否修改每个演员机器人的群名片。推荐开启。')
...@@ -54,7 +54,7 @@ export class MyPlugin { ...@@ -54,7 +54,7 @@ export class MyPlugin {
.description('是否删除 `help` 命令,避免社死 (?)') .description('是否删除 `help` 命令,避免社死 (?)')
.default(false), .default(false),
}); });
apply(ctx: Context, config: Config) { apply(ctx: Context, config: PluginConfig) {
this.ctx = ctx; this.ctx = ctx;
this.config = config; this.config = config;
if (this.config.dropHelp) { if (this.config.dropHelp) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment