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
23d82194
Commit
23d82194
authored
Oct 04, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http adapter injection
parent
d1c6a13a
Pipeline
#6071
passed with stages
in 48 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
6 deletions
+34
-6
README.md
README.md
+15
-4
package.json
package.json
+1
-1
src/koishi.interfaces.ts
src/koishi.interfaces.ts
+2
-0
src/koishi.service.ts
src/koishi.service.ts
+16
-1
No files found.
README.md
View file @
23d82194
...
@@ -23,13 +23,14 @@ import PluginOnebot from '@koishijs/plugin-onebot';
...
@@ -23,13 +23,14 @@ import PluginOnebot from '@koishijs/plugin-onebot';
imports
:
[
imports
:
[
KoishiModule
.
register
({
KoishiModule
.
register
({
// Koishi config goes here
// Koishi config goes here
prefix
:
'
.
'
,
usePlugins
:
[
usePlugins
:
[
// Plugins to install
// Plugins to install
PluginDef
(
PluginOnebot
,
{
PluginDef
(
PluginOnebot
,
{
protocol
:
'
ws
'
,
protocol
:
'
ws
'
,
endpoint
:
config
.
get
(
'
CQ_ENDPOINT
'
)
,
endpoint
:
'
CQ_ENDPOINT
'
,
selfId
:
config
.
get
(
'
CQ_SELFID
'
)
,
selfId
:
'
CQ_ENDPOINT
'
,
token
:
config
.
get
(
'
CQ_TOKEN
'
)
,
token
:
'
CQ_ENDPOINT
'
,
}),
}),
],
],
})
})
...
@@ -44,14 +45,24 @@ You may also register Koishi plugins later.
...
@@ -44,14 +45,24 @@ You may also register Koishi plugins later.
```
ts
```
ts
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
HttpAdapterHost
}
from
'
@nestjs/core
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
KoishiModule
,
PluginDef
}
from
'
koishi-nestjs
'
;
import
{
KoishiModule
,
PluginDef
}
from
'
koishi-nestjs
'
;
import
PluginOnebot
from
'
@koishijs/plugin-onebot
'
;
import
PluginOnebot
from
'
@koishijs/plugin-onebot
'
;
@
Module
({
@
Module
({
imports
:
[
imports
:
[
KoishiModule
.
registerAsync
({
KoishiModule
.
registerAsync
({
useFactory
:
()
=>
({
imports
:
[
ConfigModule
.
forRoot
()],
inject
:
[
ConfigService
,
HttpAdapterHost
],
useFactory
:
async
(
config
:
ConfigService
,
adapterHost
:
HttpAdapterHost
,
)
=>
({
// Koishi config goes here
// Koishi config goes here
prefix
:
'
.
'
,
// OPTIONAL: Injects Http Server here to Koishi instance making routes functioning.
httpAdapter
:
adapterHost
.
httpAdapter
,
usePlugins
:
[
usePlugins
:
[
// Plugins to install
// Plugins to install
PluginDef
(
PluginOnebot
,
{
PluginDef
(
PluginOnebot
,
{
...
...
package.json
View file @
23d82194
{
{
"name"
:
"koishi-nestjs"
,
"name"
:
"koishi-nestjs"
,
"version"
:
"1.0.
8
"
,
"version"
:
"1.0.
9
"
,
"description"
:
"Koishi.js as Nest.js Module"
,
"description"
:
"Koishi.js as Nest.js Module"
,
"main"
:
"dist/index.js"
,
"main"
:
"dist/index.js"
,
"typings"
:
"dist/index.d.ts"
,
"typings"
:
"dist/index.d.ts"
,
...
...
src/koishi.interfaces.ts
View file @
23d82194
import
{
ModuleMetadata
,
Provider
,
Type
}
from
'
@nestjs/common
'
;
import
{
ModuleMetadata
,
Provider
,
Type
}
from
'
@nestjs/common
'
;
import
{
App
,
Plugin
,
MaybeArray
}
from
'
koishi
'
;
import
{
App
,
Plugin
,
MaybeArray
}
from
'
koishi
'
;
import
{
AbstractHttpAdapter
}
from
'
@nestjs/core
'
;
const
selectors
=
[
const
selectors
=
[
'
user
'
,
'
user
'
,
...
@@ -36,6 +37,7 @@ export function PluginDef<T extends Plugin>(
...
@@ -36,6 +37,7 @@ export function PluginDef<T extends Plugin>(
export
interface
KoishiModuleOptions
extends
App
.
Config
{
export
interface
KoishiModuleOptions
extends
App
.
Config
{
usePlugins
?:
KoishiModulePlugin
<
Plugin
>
[];
usePlugins
?:
KoishiModulePlugin
<
Plugin
>
[];
httpAdapter
:
AbstractHttpAdapter
;
}
}
export
interface
KoishiModuleOptionsFactory
{
export
interface
KoishiModuleOptionsFactory
{
...
...
src/koishi.service.ts
View file @
23d82194
...
@@ -7,6 +7,7 @@ import {
...
@@ -7,6 +7,7 @@ import {
}
from
'
@nestjs/common
'
;
}
from
'
@nestjs/common
'
;
import
{
KOISHI_MODULE_OPTIONS
}
from
'
./koishi.constants
'
;
import
{
KOISHI_MODULE_OPTIONS
}
from
'
./koishi.constants
'
;
import
{
KoishiModuleOptions
}
from
'
./koishi.interfaces
'
;
import
{
KoishiModuleOptions
}
from
'
./koishi.interfaces
'
;
import
{
Server
}
from
'
http
'
;
@
Injectable
()
@
Injectable
()
export
class
KoishiService
export
class
KoishiService
...
@@ -14,12 +15,26 @@ export class KoishiService
...
@@ -14,12 +15,26 @@ export class KoishiService
implements
OnModuleInit
,
OnApplicationBootstrap
{
implements
OnModuleInit
,
OnApplicationBootstrap
{
constructor
(
constructor
(
@
Inject
(
KOISHI_MODULE_OPTIONS
)
@
Inject
(
KOISHI_MODULE_OPTIONS
)
private
koishiModuleOptions
:
KoishiModuleOptions
,
private
readonly
koishiModuleOptions
:
KoishiModuleOptions
,
)
{
)
{
super
(
koishiModuleOptions
);
super
(
koishiModuleOptions
);
}
}
private
setHttpServer
()
{
if
(
this
.
koishiModuleOptions
.
httpAdapter
&&
!
this
.
koishiModuleOptions
.
port
)
{
const
httpServer
:
Server
=
this
.
koishiModuleOptions
.
httpAdapter
.
getHttpServer
();
if
(
httpServer
instanceof
Server
)
{
this
.
logger
(
'
app
'
).
info
(
'
App using Nest HTTP Server.
'
);
this
.
_httpServer
=
httpServer
;
}
}
}
onModuleInit
()
{
onModuleInit
()
{
this
.
setHttpServer
();
if
(
this
.
koishiModuleOptions
.
usePlugins
)
{
if
(
this
.
koishiModuleOptions
.
usePlugins
)
{
for
(
const
pluginDesc
of
this
.
koishiModuleOptions
.
usePlugins
)
{
for
(
const
pluginDesc
of
this
.
koishiModuleOptions
.
usePlugins
)
{
const
ctx
=
pluginDesc
.
select
const
ctx
=
pluginDesc
.
select
...
...
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