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
184cb41e
Commit
184cb41e
authored
Dec 26, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename KoishiPlugin to DefinePlugin
parent
3291f64e
Pipeline
#8278
passed with stages
in 1 minute and 16 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
24 deletions
+26
-24
README.md
README.md
+10
-10
src/register.ts
src/register.ts
+3
-1
tests/http.spec.ts
tests/http.spec.ts
+2
-2
tests/inject-using.spec.ts
tests/inject-using.spec.ts
+2
-2
tests/on-apply.spec.ts
tests/on-apply.spec.ts
+4
-4
tests/service-activate.spec.ts
tests/service-activate.spec.ts
+5
-5
No files found.
README.md
View file @
184cb41e
...
@@ -13,7 +13,7 @@ npm install koishi-thirdeye koishi
...
@@ -13,7 +13,7 @@ npm install koishi-thirdeye koishi
可以简单定义类以快速开发 Koishi 插件。
可以简单定义类以快速开发 Koishi 插件。
```
ts
```
ts
import
{
Koishi
Plugin
,
SchemaProperty
,
CommandUsage
,
PutOption
,
UseCommand
,
OnApply
,
KoaContext
,
UseMiddleware
,
UseEvent
,
Get
}
from
'
koishi-thirdeye
'
;
import
{
Define
Plugin
,
SchemaProperty
,
CommandUsage
,
PutOption
,
UseCommand
,
OnApply
,
KoaContext
,
UseMiddleware
,
UseEvent
,
Get
}
from
'
koishi-thirdeye
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
export
class
MyPluginConfig
{
export
class
MyPluginConfig
{
...
@@ -21,7 +21,7 @@ export class MyPluginConfig {
...
@@ -21,7 +21,7 @@ export class MyPluginConfig {
foo
:
string
;
foo
:
string
;
}
}
@
Koishi
Plugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
@
Define
Plugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
export
default
class
MyPlugin
implements
OnApply
{
export
default
class
MyPlugin
implements
OnApply
{
constructor
(
private
ctx
:
Context
,
private
config
:
Partial
<
MyPluginConfig
>
)
{
constructor
(
private
ctx
:
Context
,
private
config
:
Partial
<
MyPluginConfig
>
)
{
}
}
...
@@ -55,7 +55,7 @@ export default class MyPlugin implements OnApply {
...
@@ -55,7 +55,7 @@ export default class MyPlugin implements OnApply {
## 使用
## 使用
使用 koishi-thirdeye 编写的插件,需要在插件类上使用
`@
KoishiPlugin(options: Koishi
PluginRegistrationOptions)`
装饰器。
使用 koishi-thirdeye 编写的插件,需要在插件类上使用
`@
DefinePlugin(options: Define
PluginRegistrationOptions)`
装饰器。
您可以在参数中指定该插件的基本信息。
您可以在参数中指定该插件的基本信息。
...
@@ -68,7 +68,7 @@ koishi-thirdeye 内建了 `schemastery-gen` 的支持。只需要导入这1个
...
@@ -68,7 +68,7 @@ koishi-thirdeye 内建了 `schemastery-gen` 的支持。只需要导入这1个
最基本的插件定义方式如下:
最基本的插件定义方式如下:
```
ts
```
ts
import
{
Koishi
Plugin
,
SchemaProperty
,
InjectConfig
}
from
'
koishi-thirdeye
'
;
import
{
Define
Plugin
,
SchemaProperty
,
InjectConfig
}
from
'
koishi-thirdeye
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
export
class
MyPluginConfig
{
export
class
MyPluginConfig
{
...
@@ -76,7 +76,7 @@ export class MyPluginConfig {
...
@@ -76,7 +76,7 @@ export class MyPluginConfig {
foo
:
string
;
foo
:
string
;
}
}
@
Koishi
Plugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
@
Define
Plugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
export
default
class
MyPlugin
{
export
default
class
MyPlugin
{
constructor
(
private
ctx
:
Context
,
private
config
:
Partial
<
MyPluginConfig
>
)
{
constructor
(
private
ctx
:
Context
,
private
config
:
Partial
<
MyPluginConfig
>
)
{
}
}
...
@@ -92,10 +92,10 @@ export default class MyPlugin {
...
@@ -92,10 +92,10 @@ export default class MyPlugin {
您可以使用
`this.ctx`
以及
`this.config`
进行访问上下文对象以及插件配置。因此上面的例子可以简化为下面的代码:
您可以使用
`this.ctx`
以及
`this.config`
进行访问上下文对象以及插件配置。因此上面的例子可以简化为下面的代码:
> `@
Koishi
Plugin` 装饰器不可省略。
> `@
Define
Plugin` 装饰器不可省略。
```
ts
```
ts
import
{
Koishi
Plugin
,
SchemaProperty
,
BasePlugin
}
from
'
koishi-thirdeye
'
;
import
{
Define
Plugin
,
SchemaProperty
,
BasePlugin
}
from
'
koishi-thirdeye
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
export
class
MyPluginConfig
{
export
class
MyPluginConfig
{
...
@@ -103,7 +103,7 @@ export class MyPluginConfig {
...
@@ -103,7 +103,7 @@ export class MyPluginConfig {
foo
:
string
;
foo
:
string
;
}
}
@
Koishi
Plugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
@
Define
Plugin
({
name
:
'
my-plugin
'
,
schema
:
MyPluginConfig
})
export
default
class
MyPlugin
extends
BasePlugin
<
MyPluginConfig
>
{
export
default
class
MyPlugin
extends
BasePlugin
<
MyPluginConfig
>
{
}
}
...
@@ -235,7 +235,7 @@ koishi-thirdeye 使用一组装饰器进行描述指令的行为。这些装饰
...
@@ -235,7 +235,7 @@ koishi-thirdeye 使用一组装饰器进行描述指令的行为。这些装饰
import
{
Inject
,
UseEvent
}
from
'
koishi-thirdeye
'
;
import
{
Inject
,
UseEvent
}
from
'
koishi-thirdeye
'
;
import
{
Cache
}
from
'
koishi
'
;
import
{
Cache
}
from
'
koishi
'
;
@
Koishi
Plugin
({
name
:
'
my-plugin
'
})
@
Define
Plugin
({
name
:
'
my-plugin
'
})
export
class
MyPlugin
{
export
class
MyPlugin
{
constructor
(
private
ctx
:
Context
,
private
config
:
any
)
{
constructor
(
private
ctx
:
Context
,
private
config
:
any
)
{
}
}
...
@@ -280,7 +280,7 @@ declare module 'koishi' {
...
@@ -280,7 +280,7 @@ declare module 'koishi' {
// `@Provide(name)` 装饰器会自动完成 `Context.service(name)` 的声明操作
// `@Provide(name)` 装饰器会自动完成 `Context.service(name)` 的声明操作
@
Provide
(
'
myService
'
)
@
Provide
(
'
myService
'
)
@
Koishi
Plugin
({
name
:
'
my-database
'
})
@
Define
Plugin
({
name
:
'
my-database
'
})
export
class
MyDatabasePlugin
{
export
class
MyDatabasePlugin
{
// 该类会作为 Koishi 的 Service 供其他 Koishi 插件进行引用
// 该类会作为 Koishi 的 Service 供其他 Koishi 插件进行引用
}
}
...
...
src/register.ts
View file @
184cb41e
...
@@ -59,7 +59,7 @@ function getContextFromFilters(ctx: Context, filters: OnContextFunction[]) {
...
@@ -59,7 +59,7 @@ function getContextFromFilters(ctx: Context, filters: OnContextFunction[]) {
return
targetCtx
;
return
targetCtx
;
}
}
export
function
Koishi
Plugin
<
T
=
any
>
(
export
function
Define
Plugin
<
T
=
any
>
(
options
:
KoishiPluginRegistrationOptions
<
T
>
=
{},
options
:
KoishiPluginRegistrationOptions
<
T
>
=
{},
)
{
)
{
return
function
<
return
function
<
...
@@ -382,3 +382,5 @@ export function KoishiPlugin<T = any>(
...
@@ -382,3 +382,5 @@ export function KoishiPlugin<T = any>(
return
newClass
;
return
newClass
;
};
};
}
}
export
const
KoishiPlugin
=
DefinePlugin
;
tests/http.spec.ts
View file @
184cb41e
import
{
App
}
from
'
koishi
'
;
import
{
App
}
from
'
koishi
'
;
import
{
Koishi
Plugin
}
from
'
../src/register
'
;
import
{
Define
Plugin
}
from
'
../src/register
'
;
import
{
Get
}
from
'
../src/decorators
'
;
import
{
Get
}
from
'
../src/decorators
'
;
import
{
KoaContext
}
from
'
../src/def
'
;
import
{
KoaContext
}
from
'
../src/def
'
;
import
request
from
'
supertest
'
;
import
request
from
'
supertest
'
;
@
Koishi
Plugin
()
@
Define
Plugin
()
class
MyPlugin
{
class
MyPlugin
{
@
Get
(
'
ping
'
)
@
Get
(
'
ping
'
)
async
ping
(
ctx
:
KoaContext
)
{
async
ping
(
ctx
:
KoaContext
)
{
...
...
tests/inject-using.spec.ts
View file @
184cb41e
import
{
Inject
,
Koishi
Plugin
}
from
'
..
'
;
import
{
Inject
,
Define
Plugin
}
from
'
..
'
;
import
{
Cache
,
Assets
,
Bot
,
Context
}
from
'
koishi
'
;
import
{
Cache
,
Assets
,
Bot
,
Context
}
from
'
koishi
'
;
describe
(
'
InjectUsing
'
,
()
=>
{
describe
(
'
InjectUsing
'
,
()
=>
{
@
Koishi
Plugin
({
using
:
[
'
database
'
]
})
@
Define
Plugin
({
using
:
[
'
database
'
]
})
class
MyPlugin
{
class
MyPlugin
{
@
Inject
(
true
)
@
Inject
(
true
)
cache
:
Cache
;
cache
:
Cache
;
...
...
tests/on-apply.spec.ts
View file @
184cb41e
import
{
App
,
Context
}
from
'
koishi
'
;
import
{
App
,
Context
}
from
'
koishi
'
;
import
{
import
{
Koishi
Plugin
,
Define
Plugin
,
OnApply
,
OnApply
,
OnConnect
,
OnConnect
,
OnDisconnect
,
OnDisconnect
,
...
@@ -19,15 +19,15 @@ declare module 'koishi' {
...
@@ -19,15 +19,15 @@ declare module 'koishi' {
}
}
@
Provide
(
'
immediateDependency
'
,
{
immediate
:
true
})
@
Provide
(
'
immediateDependency
'
,
{
immediate
:
true
})
@
Koishi
Plugin
()
@
Define
Plugin
()
class
ImmediateDependency
{}
class
ImmediateDependency
{}
@
Provide
(
'
nonImmediateDependency
'
)
@
Provide
(
'
nonImmediateDependency
'
)
@
Koishi
Plugin
()
@
Define
Plugin
()
class
NonImmediateDependency
{}
class
NonImmediateDependency
{}
@
Provide
(
'
myPlugin
'
,
{
immediate
:
true
})
@
Provide
(
'
myPlugin
'
,
{
immediate
:
true
})
@
Koishi
Plugin
()
@
Define
Plugin
()
class
TestingBase
implements
OnConnect
,
OnDisconnect
,
OnApply
{
class
TestingBase
implements
OnConnect
,
OnDisconnect
,
OnApply
{
@
InjectContext
()
@
InjectContext
()
ctx
:
Context
;
ctx
:
Context
;
...
...
tests/service-activate.spec.ts
View file @
184cb41e
import
{
App
,
Context
}
from
'
koishi
'
;
import
{
App
,
Context
}
from
'
koishi
'
;
import
{
Koishi
Plugin
}
from
'
../src/register
'
;
import
{
Define
Plugin
}
from
'
../src/register
'
;
import
{
Inject
,
Provide
,
UseEvent
}
from
'
../src/decorators
'
;
import
{
Inject
,
Provide
,
UseEvent
}
from
'
../src/decorators
'
;
declare
module
'
koishi
'
{
declare
module
'
koishi
'
{
...
@@ -15,7 +15,7 @@ declare module 'koishi' {
...
@@ -15,7 +15,7 @@ declare module 'koishi' {
}
}
@
Provide
(
'
myProvider
'
)
@
Provide
(
'
myProvider
'
)
@
Koishi
Plugin
()
@
Define
Plugin
()
class
MyProvider
{
class
MyProvider
{
ping
()
{
ping
()
{
return
'
pong
'
;
return
'
pong
'
;
...
@@ -23,7 +23,7 @@ class MyProvider {
...
@@ -23,7 +23,7 @@ class MyProvider {
}
}
@
Provide
(
'
myEagerProvider
'
,
{
immediate
:
true
})
@
Provide
(
'
myEagerProvider
'
,
{
immediate
:
true
})
@
Koishi
Plugin
()
@
Define
Plugin
()
class
MyEagerProvider
{
class
MyEagerProvider
{
ping
()
{
ping
()
{
return
'
pong eager
'
;
return
'
pong eager
'
;
...
@@ -31,7 +31,7 @@ class MyEagerProvider {
...
@@ -31,7 +31,7 @@ class MyEagerProvider {
}
}
@
Provide
(
'
myConsumer
'
,
{
immediate
:
true
})
@
Provide
(
'
myConsumer
'
,
{
immediate
:
true
})
@
Koishi
Plugin
()
@
Define
Plugin
()
class
MyConsumer
{
class
MyConsumer
{
@
Inject
()
@
Inject
()
myProvider
:
MyProvider
;
myProvider
:
MyProvider
;
...
@@ -54,7 +54,7 @@ class MyConsumer {
...
@@ -54,7 +54,7 @@ class MyConsumer {
}
}
@
Provide
(
'
myUsingConsumer
'
,
{
immediate
:
true
})
@
Provide
(
'
myUsingConsumer
'
,
{
immediate
:
true
})
@
Koishi
Plugin
()
@
Define
Plugin
()
class
MyUsingConsumer
{
class
MyUsingConsumer
{
@
Inject
(
true
)
@
Inject
(
true
)
myProvider
:
MyProvider
;
myProvider
:
MyProvider
;
...
...
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