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
534a56c6
Commit
534a56c6
authored
Oct 07, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove injection of HttpAdapter
parent
3a4278fe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
23 deletions
+33
-23
README.md
README.md
+2
-10
src/koishi-metascan.service.ts
src/koishi-metascan.service.ts
+27
-7
src/koishi.decorators.ts
src/koishi.decorators.ts
+1
-2
src/koishi.interfaces.ts
src/koishi.interfaces.ts
+0
-2
src/koishi.service.ts
src/koishi.service.ts
+3
-2
No files found.
README.md
View file @
534a56c6
...
...
@@ -43,7 +43,6 @@ export class AppModule {}
```
ts
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
HttpAdapterHost
}
from
'
@nestjs/core
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
KoishiModule
,
PluginDef
}
from
'
koishi-nestjs
'
;
import
PluginOnebot
from
'
@koishijs/plugin-onebot
'
;
...
...
@@ -52,15 +51,10 @@ import PluginOnebot from '@koishijs/plugin-onebot';
imports
:
[
KoishiModule
.
registerAsync
({
imports
:
[
ConfigModule
.
forRoot
()],
inject
:
[
ConfigService
,
HttpAdapterHost
],
useFactory
:
async
(
config
:
ConfigService
,
adapterHost
:
HttpAdapterHost
,
)
=>
({
inject
:
[
ConfigService
],
useFactory
:
async
(
config
:
ConfigService
)
=>
({
// 在这里填写 Koishi 配置参数
prefix
:
'
.
'
,
// 可选,如果使用 Onebot 的 ws reverse 协议,那么需要配置该项来保证 ws 服务器正常运行
httpAdapter
:
adapterHost
.
httpAdapter
,
usePlugins
:
[
// 预安装的插件
PluginDef
(
PluginOnebot
,
{
...
...
@@ -83,8 +77,6 @@ Koishi-Nest 的配置项和 Koishi 配置项一致,参照 [Koishi 文档](http
*
`loggerPrefix`
:
`string`
Nest 日志中 Logger 的前缀。默认
`koishi`
。
*
`httpAdapter`
:
`AbstractHttpAdapter`
Nest 的 HTTP 适配器引用,用于
`@koishijs/plugin-adapter-onebot`
中
`ws:reverse`
协议的适配。非该协议可以忽略该项。
*
`usePlugins`
:
`KoishiModulePlugin[]`
可选。预先安装的 Koishi 插件列表。使用
`PluginDef(plugin, options, select)`
方法生成该项的定义。该配置项的成员参数如下。
*
`plugin`
Koishi 插件。
...
...
src/koishi-metascan.service.ts
View file @
534a56c6
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
DiscoveryService
,
MetadataScanner
,
Reflector
}
from
'
@nestjs/core
'
;
import
{
AbstractHttpAdapter
,
DiscoveryService
,
HttpAdapterHost
,
MetadataScanner
,
ModulesContainer
,
Reflector
,
}
from
'
@nestjs/core
'
;
import
{
Argv
,
Command
,
Context
}
from
'
koishi
'
;
import
{
InstanceWrapper
}
from
'
@nestjs/core/injector/instance-wrapper
'
;
import
{
...
...
@@ -22,8 +29,20 @@ export class KoishiMetascanService {
private
readonly
discoveryService
:
DiscoveryService
,
private
readonly
metadataScanner
:
MetadataScanner
,
private
readonly
reflector
:
Reflector
,
private
readonly
moduleContainer
:
ModulesContainer
,
)
{}
getHttpAdapter
():
AbstractHttpAdapter
{
for
(
const
module
of
this
.
moduleContainer
.
values
())
{
const
adapterHost
=
module
.
providers
.
get
(
HttpAdapterHost
);
if
(
adapterHost
)
{
return
(
adapterHost
as
InstanceWrapper
<
HttpAdapterHost
>
).
instance
.
httpAdapter
;
}
}
return
null
;
}
private
async
handleInstance
(
ctx
:
Context
,
instance
:
Record
<
string
,
any
>
,
...
...
@@ -56,7 +75,6 @@ export class KoishiMetascanService {
baseContext
=
filter
(
baseContext
)
||
baseContext
;
}
}
console
.
log
(
regData
);
switch
(
regData
.
type
)
{
case
'
middleware
'
:
baseContext
.
middleware
(
...
...
@@ -65,8 +83,9 @@ export class KoishiMetascanService {
);
break
;
case
'
onevent
'
:
const
{
data
:
eventData
}
=
regData
as
DoRegisterConfig
<
EventNameAndPrepend
>
;
const
{
data
:
eventData
,
}
=
regData
as
DoRegisterConfig
<
EventNameAndPrepend
>
;
baseContext
.
on
(
eventData
.
name
,
(...
args
:
any
[])
=>
methodFun
.
call
(
instance
,
...
args
),
);
...
...
@@ -87,9 +106,10 @@ export class KoishiMetascanService {
const
{
data
:
commandData
}
=
regData
as
DoRegisterConfig
<
ContextFunction
<
Command
>
>
;
let
command
=
commandData
(
baseContext
).
action
(
(
argv
:
Argv
,
...
args
:
any
[])
=>
methodFun
.
call
(
instance
,
argv
,
...
args
),
let
command
=
commandData
(
baseContext
,
).
action
((
argv
:
Argv
,
...
args
:
any
[])
=>
methodFun
.
call
(
instance
,
argv
,
...
args
),
);
const
commandDefs
:
CommandDefinitionFun
[]
=
this
.
reflector
.
get
(
KoishiCommandDefinition
,
...
...
src/koishi.decorators.ts
View file @
534a56c6
...
...
@@ -9,7 +9,6 @@ import {
KoishiOnContextScope
,
}
from
'
./koishi.constants
'
;
import
{
CommandConfigWIthDescription
,
CommandDefinitionFun
,
ContextFunction
,
DoRegisterConfig
,
...
...
@@ -18,7 +17,7 @@ import {
OnContextFunction
,
Selection
,
}
from
'
./koishi.interfaces
'
;
import
{
Context
,
Command
,
Argv
}
from
'
koishi
'
;
import
{
Argv
,
Command
}
from
'
koishi
'
;
// Injections
export
const
InjectContext
=
()
=>
Inject
(
KOISHI_CONTEXT
);
...
...
src/koishi.interfaces.ts
View file @
534a56c6
import
{
ModuleMetadata
,
Provider
,
Type
}
from
'
@nestjs/common
'
;
import
{
App
,
Command
,
Context
,
EventMap
,
MaybeArray
,
Plugin
}
from
'
koishi
'
;
import
{
AbstractHttpAdapter
}
from
'
@nestjs/core
'
;
const
selectors
=
[
'
user
'
,
...
...
@@ -37,7 +36,6 @@ export function PluginDef<T extends Plugin>(
export
interface
KoishiModuleOptions
extends
App
.
Config
{
usePlugins
?:
KoishiModulePlugin
<
Plugin
>
[];
httpAdapter
?:
AbstractHttpAdapter
;
loggerPrefix
?:
string
;
}
...
...
src/koishi.service.ts
View file @
534a56c6
...
...
@@ -35,8 +35,9 @@ export class KoishiService
_nestKoaTmpServerPort
:
number
;
private
async
setHttpServer
()
{
if
(
this
.
koishiModuleOptions
.
httpAdapter
)
{
const
httpServer
:
Server
=
this
.
koishiModuleOptions
.
httpAdapter
.
getHttpServer
();
const
httpAdapter
=
this
.
metascan
.
getHttpAdapter
();
if
(
httpAdapter
)
{
const
httpServer
:
Server
=
httpAdapter
.
getHttpServer
();
if
(
httpServer
instanceof
Server
)
{
this
.
logger
(
'
app
'
).
info
(
'
App using Nest HTTP Server.
'
);
this
.
_httpServer
=
httpServer
;
...
...
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