Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Thirdeye
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
Koishi Thirdeye
Commits
f8e998c1
Commit
f8e998c1
authored
Nov 21, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto register schema
parent
5e678ce0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
README.md
README.md
+3
-3
src/register.ts
src/register.ts
+4
-1
No files found.
README.md
View file @
f8e998c1
...
...
@@ -13,7 +13,7 @@ npm install koishi-thirdeye koishi@next
可以简单定义类以快速开发 Koishi 插件。
```
ts
import
{
KoishiPlugin
,
DefineSchema
,
CommandUsage
,
PutOption
,
UseCommand
OnApply
}
from
'
koishi-thirdeye
'
import
{
KoishiPlugin
,
DefineSchema
,
CommandUsage
,
PutOption
,
UseCommand
,
OnApply
}
from
'
koishi-thirdeye
'
export
class
MyPluginConfig
{
@
DefineSchema
({
default
:
'
bar
'
})
...
...
@@ -24,7 +24,7 @@ export class MyPluginConfig {
export
default
class
MyPlugin
implements
OnApply
{
constructor
(
private
ctx
:
Context
,
private
config
:
Partial
<
MyPluginConfig
>
)
{
}
onApply
()
{
// 该方法会在插件加载时调用,用于在上下文中注册事件等操作。
}
...
...
@@ -47,7 +47,7 @@ export default class MyPlugin implements OnApply {
*
`schema`
插件的配置描述模式。可以是 Schema 描述模式,也可以是由
`schemastery-gen`
生成的 Schema 类。
koishi-thirdeye 内建了
`schemastery-gen`
的支持。只需要导入这1个包即可。
koishi-thirdeye 内建了
`schemastery-gen`
的支持。只需要导入这1个包即可。
另外,系统会自动进行
`@RegisterSchema`
的配置描述的注册。
## API
...
...
src/register.ts
View file @
f8e998c1
...
...
@@ -17,6 +17,7 @@ import {
}
from
'
./def
'
;
import
{
reflector
}
from
'
./meta/meta-fetch
'
;
import
{
applySelector
}
from
'
./utility/utility
'
;
import
{
RegisterSchema
}
from
'
schemastery-gen
'
;
export
interface
KoishiPluginRegistrationOptions
<
T
=
any
>
{
name
?:
string
;
...
...
@@ -56,7 +57,9 @@ export function KoishiPlugin<T = any>(
C
extends
{
new
(...
args
:
any
[]):
any
;
schema
?:
Schema
;
name
?:
string
}
>
(
originalClass
:
C
)
{
const
newClass
=
class
extends
originalClass
implements
PluginClass
{
static
schema
=
options
.
schema
;
static
schema
=
(
options
.
schema
as
Schema
).
type
?
options
.
schema
:
RegisterSchema
()(
options
.
schema
);
__ctx
:
Context
;
__config
:
T
;
__pluginOptions
:
KoishiPluginRegistrationOptions
<
T
>
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment