Commit 6fae1078 authored by nanahira's avatar nanahira

Migrate schema to Config

parent 8cd61d93
import 'source-map-support/register'; import 'source-map-support/register';
import { Context } from 'koishi'; import { Context } from 'koishi';
import { Config, MyPlugin } from './plugin'; import { PluginConfig, MyPlugin } from './plugin';
export { Config } from './plugin'; export * from './plugin';
export const name = 'dispose'; export const name = 'dispose';
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);
} }
...@@ -2,15 +2,15 @@ import 'source-map-support/register'; ...@@ -2,15 +2,15 @@ import 'source-map-support/register';
import { Context, Schema, Session } from 'koishi'; import { Context, Schema, Session } from 'koishi';
import type { OneBotBot } from '@koishijs/plugin-adapter-onebot/lib/bot'; import type { OneBotBot } from '@koishijs/plugin-adapter-onebot/lib/bot';
export interface Config { export interface PluginConfig {
commmandName?: string; commmandName?: string;
} }
export class MyPlugin { export class MyPlugin {
config: Config; config: PluginConfig;
ctx: Context; ctx: Context;
name = 'dispose-main'; name = 'dispose-main';
schema: Schema<Config> = Schema.object({ schema: Schema<PluginConfig> = Schema.object({
commmandName: Schema.string().description('退群命令名称').default('dispose'), commmandName: Schema.string().description('退群命令名称').default('dispose'),
}); });
private async onQuit(session: Session) { private async onQuit(session: Session) {
...@@ -40,7 +40,7 @@ export class MyPlugin { ...@@ -40,7 +40,7 @@ export class MyPlugin {
} }
return; return;
} }
apply(ctx: Context, config: Config) { apply(ctx: Context, config: PluginConfig) {
this.ctx = ctx; this.ctx = ctx;
this.config = config; this.config = config;
this.ctx this.ctx
......
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