Commit bade7249 authored by nanahira's avatar nanahira

migrate

parent 156f4d91
Pipeline #6082 passed with stages
in 27 seconds
......@@ -12,7 +12,7 @@ npm install koishi-plugin-limit-help
### 直接安装
在 https://cdn01.moecube.com/nanahira/koishi-plugin/limit-help/index.js 下载,并配置 `koishi.config.js`
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/limit-help/index.js 下载,并配置 `koishi.config.js`
## 配置
......@@ -31,7 +31,7 @@ module.exports = {
```js
module.exports = {
plugins: {
"/path/to/limit-help/index.js": (ctx) => ctx.private()
"/path/to/limit-help/index.js": { $private: true }
}
}
```
This diff is collapsed.
{
"name": "koishi-plugin-limit-help",
"version": "1.0.1",
"version": "2.0.0",
"description": "Koishi 帮助限制器",
"main": "dist/index.js",
"scripts": {
......@@ -30,7 +30,7 @@
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"koishi-core": "^3.13.0",
"koishi": "^4.0.0-alpha.8",
"prettier": "^2.3.2",
"raw-loader": "^4.0.2",
"ts-loader": "^9.2.5",
......
import 'source-map-support/register';
import type { Context } from 'koishi-core';
import type { Context } from 'koishi';
import { Config, MyPlugin } from './plugin';
export { Config } from './plugin';
export const name = 'limit-help-index';
export const name = 'limit-help';
const plugin = new MyPlugin();
export const schema = plugin.schema;
export function apply(ctx: Context, config: Config) {
ctx.plugin(new MyPlugin(), config);
ctx.plugin(plugin, config);
}
import 'source-map-support/register';
import type { Context } from 'koishi-core';
import { Context, MaybeArray, Schema } from 'koishi';
export type Config = ((ctx: Context) => Context) | null;
const selectors = [
'user',
'guild',
'channel',
'self',
'private',
'platform',
] as const;
type SelectorType = typeof selectors[number];
type SelectorValue = boolean | MaybeArray<string | number>;
type BaseSelection = { [K in SelectorType as `$${K}`]?: SelectorValue };
export interface Selection extends BaseSelection {
$and?: Selection[];
$or?: Selection[];
$not?: Selection;
}
export type Config = Selection;
export class MyPlugin {
config: Config;
ctx: Context;
name = 'limit-help';
name = 'limit-help-main';
schema: Schema<Selection> = Schema.any('帮助作用域。').default({
$user: '10000',
});
apply(ctx: Context, config: Config) {
this.ctx = ctx;
this.config = config || ((ctx) => ctx.intersect(() => false));
this.config = Schema.validate(config, this.schema);
this.disableHelp();
}
disableHelp() {
......@@ -18,6 +40,6 @@ export class MyPlugin {
return;
}
const helpCtx = helpCommand.context;
helpCommand.context = helpCtx.intersect(this.config(helpCtx));
helpCommand.context = helpCtx.intersect(this.ctx.select(this.config));
}
}
......@@ -25,4 +25,7 @@ module.exports = {
},
path: path.resolve(__dirname, "dist"),
},
externals: {
'koishi': 'koishi',
}
};
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