Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Nestjs
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 Nestjs
Commits
e44a7a46
Commit
e44a7a46
authored
Jan 09, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add PluginDef 3rd param for selection back
parent
b12f01f2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
5 deletions
+67
-5
src/koishi.service.ts
src/koishi.service.ts
+3
-1
src/utility/koishi.decorators.ts
src/utility/koishi.decorators.ts
+25
-2
src/utility/koishi.interfaces.ts
src/utility/koishi.interfaces.ts
+5
-2
tests/koishi-tests.spec.ts
tests/koishi-tests.spec.ts
+6
-0
tests/utility/testing-module.ts
tests/utility/testing-module.ts
+28
-0
No files found.
src/koishi.service.ts
View file @
e44a7a46
...
...
@@ -21,6 +21,7 @@ import WebSocket from 'ws';
import
{
KoishiNestRouter
}
from
'
./utility/koa-router
'
;
import
'
./utility/koishi.workarounds
'
;
import
'
./utility/koishi.declares
'
;
import
{
selectContext
}
from
'
koishi-thirdeye
'
;
@
Injectable
({
scope
:
Scope
.
DEFAULT
,
...
...
@@ -85,7 +86,8 @@ export class KoishiService
this
.
metascan
.
preRegisterContext
(
this
);
if
(
this
.
koishiModuleOptions
.
usePlugins
)
{
for
(
const
pluginDef
of
this
.
koishiModuleOptions
.
usePlugins
)
{
this
.
plugin
(
pluginDef
.
plugin
,
pluginDef
.
options
);
const
ctx
=
selectContext
(
this
,
pluginDef
.
selection
);
ctx
.
plugin
(
pluginDef
.
plugin
,
pluginDef
.
options
);
}
}
await
this
.
metascan
.
registerContext
(
this
);
...
...
src/utility/koishi.decorators.ts
View file @
e44a7a46
...
...
@@ -13,9 +13,10 @@ import {
MetadataArrayValueMap
,
MetadataGenericMap
,
MetadataKey
,
PluginDefinitionWithSelection
,
ServiceName
,
}
from
'
./koishi.interfaces
'
;
import
{
Context
}
from
'
koishi
'
;
import
{
Context
,
Plugin
}
from
'
koishi
'
;
import
{
ContextScopeTypes
,
getContextProvideToken
,
...
...
@@ -93,7 +94,29 @@ export const ConcatMetadata = <K extends keyof MetadataArrayValueMap>(
// Export all koishi-decorator decorators
export
*
from
'
koishi-thirdeye/dist/src/decorators/common
'
;
export
{
PluginDef
}
from
'
koishi-thirdeye
'
;
import
{
PluginDef
as
_pluginDef
,
PluginRegistrar
,
Selection
,
}
from
'
koishi-thirdeye
'
;
export
function
PluginDef
(
name
:
string
,
options
?:
any
,
selection
?:
Selection
,
):
PluginRegistrar
.
PluginDefinitionName
&
{
selection
?:
Selection
};
export
function
PluginDef
<
T
extends
Plugin
>
(
plugin
:
T
,
options
?:
PluginRegistrar
.
PluginOptions
<
T
>
,
selection
?:
Selection
,
):
PluginDefinitionWithSelection
<
T
>
;
export
function
PluginDef
<
T
extends
Plugin
>
(
plugin
:
T
,
options
?:
PluginRegistrar
.
PluginOptions
<
T
>
,
selection
:
Selection
=
{},
):
PluginDefinitionWithSelection
<
T
>
{
return
{
...
_pluginDef
(
plugin
,
options
),
selection
};
}
// Service
...
...
src/utility/koishi.interfaces.ts
View file @
e44a7a46
import
{
ModuleMetadata
,
Provider
,
Type
}
from
'
@nestjs/common
'
;
import
{
App
,
Channel
,
Command
,
Context
,
User
}
from
'
koishi
'
;
import
{
App
,
Channel
,
Command
,
Context
,
User
,
Plugin
}
from
'
koishi
'
;
import
{
MetadataArrayMap
,
MetadataMap
}
from
'
./koishi.constants
'
;
import
{
PluginRegistrar
,
Selection
}
from
'
koishi-thirdeye
'
;
...
...
@@ -14,10 +14,13 @@ export interface KoishiModuleTopOptions {
useWs
?:
boolean
;
}
export
type
PluginDefinitionWithSelection
<
T
extends
Plugin
>
=
PluginRegistrar
.
PluginDefinition
<
Context
,
T
>
&
{
selection
:
Selection
};
export
interface
KoishiModuleOptions
extends
App
.
Config
,
KoishiModuleTopOptions
{
usePlugins
?:
Plugin
Registrar
.
PluginDefini
tion
<
any
>
[];
usePlugins
?:
Plugin
DefinitionWithSelec
tion
<
any
>
[];
loggerPrefix
?:
string
;
loggerColor
?:
number
;
moduleSelection
?:
KoishiModuleSelection
[];
...
...
tests/koishi-tests.spec.ts
View file @
e44a7a46
...
...
@@ -127,6 +127,12 @@ describe('Koishi in Nest.js', () => {
).
toBe
(
false
);
});
it
(
'
should response to plugin
'
,
()
=>
{
const
command
=
koishiApp
.
command
(
'
from-plugin
'
);
expect
(
command
).
toBeDefined
();
expect
(
command
.
execute
({})).
resolves
.
toBe
(
'
fooo
'
);
});
it
(
'
should handle command error
'
,
()
=>
{
const
command
=
koishiApp
.
command
(
'
boo
'
);
expect
(
command
).
toBeDefined
();
...
...
tests/utility/testing-module.ts
View file @
e44a7a46
...
...
@@ -4,16 +4,21 @@ import { Argv, Context, SessionError } from 'koishi';
import
{
CommandTemplate
,
CommandUsage
,
DefinePlugin
,
OnGuild
,
OnPlatform
,
PutOption
,
PutValue
,
RegisterSchema
,
SchemaProperty
,
StarterPlugin
,
UseCommand
,
UseEvent
,
}
from
'
koishi-thirdeye
'
;
import
{
CommandInterceptors
,
InjectContextUser
,
PluginDef
,
UsingService
,
}
from
'
../../src/utility/koishi.decorators
'
;
import
{
Test
}
from
'
@nestjs/testing
'
;
...
...
@@ -101,6 +106,20 @@ export class KoishiTestService {
}
}
@
RegisterSchema
()
class
TestingPluginConfig
{
@
SchemaProperty
({
default
:
'
foo
'
})
foo
:
string
;
}
@
DefinePlugin
()
class
TestingPlugin
extends
StarterPlugin
(
TestingPluginConfig
)
{
@
UseCommand
(
'
from-plugin
'
)
testingCommand
()
{
return
this
.
config
.
foo
;
}
}
export
function
testingModule
()
{
return
Test
.
createTestingModule
({
imports
:
[
...
...
@@ -113,6 +132,15 @@ export function testingModule() {
content
:
'
miiii
'
,
},
},
usePlugins
:
[
PluginDef
(
TestingPlugin
,
{
foo
:
'
fooo
'
},
{
self
:
'
koishi
'
,
},
),
],
}),
],
providers
:
[
...
...
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