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
0f37cf82
Commit
0f37cf82
authored
Dec 26, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add BasePlugin
parent
77ce2f6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
3 deletions
+57
-3
README.md
README.md
+47
-3
index.ts
index.ts
+1
-0
src/base-plugin.ts
src/base-plugin.ts
+9
-0
No files found.
README.md
View file @
0f37cf82
...
...
@@ -5,7 +5,7 @@
## 安装
```
shell
npm
install
koishi-thirdeye koishi
@next
npm
install
koishi-thirdeye koishi
```
## 快速入门
...
...
@@ -13,11 +13,11 @@ npm install koishi-thirdeye koishi@next
可以简单定义类以快速开发 Koishi 插件。
```
ts
import
{
KoishiPlugin
,
DefineSchema
,
CommandUsage
,
PutOption
,
UseCommand
,
OnApply
,
KoaContext
,
UseMiddleware
,
UseEvent
,
Get
}
from
'
koishi-thirdeye
'
;
import
{
KoishiPlugin
,
SchemaProperty
,
CommandUsage
,
PutOption
,
UseCommand
,
OnApply
,
KoaContext
,
UseMiddleware
,
UseEvent
,
Get
}
from
'
koishi-thirdeye
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
export
class
MyPluginConfig
{
@
DefineSchema
({
default
:
'
bar
'
})
@
SchemaProperty
({
default
:
'
bar
'
})
foo
:
string
;
}
...
...
@@ -65,6 +65,50 @@ export default class MyPlugin implements OnApply {
koishi-thirdeye 内建了
`schemastery-gen`
的支持。只需要导入这1个包即可。另外,系统会自动进行
`@RegisterSchema`
的配置描述的注册。
最基本的插件定义方式如下:
```
ts
import
{
KoishiPlugin
,
SchemaProperty
,
InjectConfig
}
from
'
koishi-thirdeye
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
export
class
MyPluginConfig
{
@
SchemaProperty
({
default
:
'
bar
'
})
foo
:
string
;
}
@
KoishiPlugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
export
default
class
MyPlugin
{
constructor
(
private
ctx
:
Context
,
private
config
:
Partial
<
MyPluginConfig
>
)
{
}
@
InjectConfig
()
private
config
:
Config
;
}
```
### 插件基类
为了简化不必要的代码,在您的类没有其他继承的情况下,可以继承于
`BasePlugin<Config>`
类,以省去不必要的构造函数等声明。
您可以使用
`this.ctx`
以及
`this.config`
进行访问上下文对象以及插件配置。因此上面的例子可以简化为下面的代码:
> `@KoishiPlugin` 装饰器不可省略。
```
ts
import
{
KoishiPlugin
,
SchemaProperty
,
BasePlugin
}
from
'
koishi-thirdeye
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
export
class
MyPluginConfig
{
@
SchemaProperty
({
default
:
'
bar
'
})
foo
:
string
;
}
@
KoishiPlugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
export
default
class
MyPlugin
extends
BasePlugin
<
MyPluginConfig
>
{
}
```
## API
### 注入
...
...
index.ts
View file @
0f37cf82
import
'
reflect-metadata
'
;
export
*
from
'
./src/register
'
;
export
*
from
'
./src/decorators
'
;
export
*
from
'
./src/base-plugin
'
;
export
*
from
'
./src/def/interfaces
'
;
export
*
from
'
schemastery-gen
'
;
src/base-plugin.ts
0 → 100644
View file @
0f37cf82
import
{
Context
}
from
'
koishi
'
;
import
{
InjectConfig
}
from
'
./decorators
'
;
export
class
BasePlugin
<
C
>
{
constructor
(
protected
ctx
:
Context
,
config
:
Partial
<
C
>
)
{}
@
InjectConfig
()
protected
config
:
C
;
}
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