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
1b5f9c98
Commit
1b5f9c98
authored
Oct 24, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more put params
parent
7b3f9b79
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
12 deletions
+84
-12
src/koishi.decorators.ts
src/koishi.decorators.ts
+26
-2
src/koishi.interfaces.ts
src/koishi.interfaces.ts
+6
-0
src/providers/koishi-metascan.service.ts
src/providers/koishi-metascan.service.ts
+52
-10
No files found.
src/koishi.decorators.ts
View file @
1b5f9c98
...
...
@@ -22,7 +22,7 @@ import {
OnContextFunction
,
Selection
,
}
from
'
./koishi.interfaces
'
;
import
{
Argv
,
Command
,
Context
}
from
'
koishi
'
;
import
{
Argv
,
Command
,
Context
,
FieldCollector
,
Session
}
from
'
koishi
'
;
import
{
ContextScopeTypes
,
getContextProvideToken
,
...
...
@@ -180,6 +180,12 @@ export const CommandOption = (
config
:
Argv
.
OptionConfig
=
{},
)
=>
CommandDef
((
cmd
)
=>
cmd
.
option
(
name
,
desc
,
config
));
export
const
CommandUserFields
=
(
fields
:
FieldCollector
<
'
user
'
>
)
=>
CommandDef
((
cmd
)
=>
cmd
.
userFields
(
fields
));
export
const
CommandChannelFields
=
(
fields
:
FieldCollector
<
'
channel
'
>
)
=>
CommandDef
((
cmd
)
=>
cmd
.
channelFields
(
fields
));
// Command put config
function
PutCommandParam
<
T
extends
keyof
CommandPutConfigMap
>
(
...
...
@@ -196,7 +202,8 @@ function PutCommandParam<T extends keyof CommandPutConfigMap>(
}
export
const
PutArgv
=
()
=>
PutCommandParam
(
'
argv
'
);
export
const
PutSession
=
()
=>
PutCommandParam
(
'
session
'
);
export
const
PutSession
=
(
field
?:
keyof
Session
)
=>
field
?
PutCommandParam
(
'
sessionField
'
,
field
)
:
PutCommandParam
(
'
session
'
);
export
const
PutArg
=
(
i
:
number
)
=>
PutCommandParam
(
'
arg
'
,
i
);
export
const
PutOption
=
(
name
:
string
,
...
...
@@ -204,6 +211,23 @@ export const PutOption = (
config
:
Argv
.
OptionConfig
=
{},
)
=>
PutCommandParam
(
'
option
'
,
{
name
,
desc
,
config
});
export
const
PutUser
=
(
field
:
FieldCollector
<
'
user
'
>
)
=>
PutCommandParam
(
'
user
'
,
field
);
export
const
PutChannel
=
(
field
:
FieldCollector
<
'
channel
'
>
)
=>
PutCommandParam
(
'
channel
'
,
field
);
export
const
PutUserName
=
(
useDatabase
=
true
)
=>
PutCommandParam
(
'
username
'
,
useDatabase
);
export
const
PutUserId
=
()
=>
PutSession
(
'
userId
'
);
export
const
PutGuildId
=
()
=>
PutSession
(
'
guildId
'
);
export
const
PutGuildName
=
()
=>
PutSession
(
'
guildName
'
);
export
const
PutChannelId
=
()
=>
PutSession
(
'
channelId
'
);
export
const
PutChannelName
=
()
=>
PutSession
(
'
channelName
'
);
export
const
PutSelfId
=
()
=>
PutSession
(
'
selfId
'
);
export
const
PutBot
=
()
=>
PutSession
(
'
bot
'
);
// Service
export
function
WireContextService
(
name
?:
string
):
PropertyDecorator
{
...
...
src/koishi.interfaces.ts
View file @
1b5f9c98
...
...
@@ -5,8 +5,10 @@ import {
Command
,
Context
,
EventMap
,
FieldCollector
,
MaybeArray
,
Plugin
,
Session
,
}
from
'
koishi
'
;
const
selectors
=
[
...
...
@@ -134,6 +136,10 @@ export interface CommandPutConfigMap {
argv
:
never
;
session
:
never
;
option
:
CommandOptionConfig
;
user
:
FieldCollector
<
'
user
'
>
;
channel
:
FieldCollector
<
'
channel
'
>
;
username
:
boolean
;
sessionField
:
keyof
Session
;
}
export
type
CommandPutConfig
<
...
...
src/providers/koishi-metascan.service.ts
View file @
1b5f9c98
...
...
@@ -7,7 +7,7 @@ import {
ModulesContainer
,
Reflector
,
}
from
'
@nestjs/core
'
;
import
{
Argv
,
Command
,
Context
}
from
'
koishi
'
;
import
{
Argv
,
Command
,
Context
,
User
}
from
'
koishi
'
;
import
{
InstanceWrapper
}
from
'
@nestjs/core/injector/instance-wrapper
'
;
import
{
KoishiCommandDefinition
,
...
...
@@ -20,6 +20,7 @@ import {
import
{
CommandDefinitionFun
,
CommandPutConfig
,
CommandPutConfigMap
,
ContextFunction
,
DoRegisterConfig
,
EventName
,
...
...
@@ -51,6 +52,39 @@ export class KoishiMetascanService {
}
}
private
preRegisterCommandActionArg
(
config
:
CommandPutConfig
,
cmd
:
Command
)
{
if
(
!
config
)
{
return
;
}
switch
(
config
.
type
)
{
case
'
option
'
:
const
{
data
:
optionData
}
=
config
as
CommandPutConfig
<
'
option
'
>
;
cmd
.
option
(
optionData
.
name
,
optionData
.
desc
,
optionData
.
config
);
break
;
case
'
user
'
:
const
{
data
:
userFields
}
=
config
as
CommandPutConfig
<
'
user
'
>
;
if
(
userFields
)
{
cmd
.
userFields
(
userFields
);
}
break
;
case
'
channel
'
:
const
{
data
:
channelFields
}
=
config
as
CommandPutConfig
<
'
channel
'
>
;
if
(
channelFields
)
{
cmd
.
channelFields
(
channelFields
);
}
break
;
case
'
username
'
:
const
{
data
:
useDatabase
}
=
config
as
CommandPutConfig
<
'
username
'
>
;
if
(
useDatabase
)
{
cmd
.
userFields
([
'
name
'
]);
}
break
;
default
:
break
;
}
return
;
}
private
getCommandActionArg
(
config
:
CommandPutConfig
,
argv
:
Argv
,
...
...
@@ -70,6 +104,22 @@ export class KoishiMetascanService {
case
'
option
'
:
const
{
data
:
optionData
}
=
config
as
CommandPutConfig
<
'
option
'
>
;
return
argv
.
options
[
optionData
.
name
];
case
'
user
'
:
return
argv
.
session
.
user
;
case
'
channel
'
:
return
argv
.
session
.
channel
;
case
'
username
'
:
const
{
data
:
useDatabase
}
=
config
as
CommandPutConfig
<
'
username
'
>
;
if
(
useDatabase
)
{
const
user
=
argv
.
session
.
user
as
User
.
Observed
<
'
name
'
>
;
if
(
user
?.
name
)
{
return
user
?.
name
;
}
}
return
argv
.
session
.
author
?.
nickname
||
argv
.
session
.
author
?.
username
;
case
'
sessionField
'
:
const
{
data
:
field
}
=
config
as
CommandPutConfig
<
'
sessionField
'
>
;
return
argv
.
session
[
field
];
default
:
return
;
}
...
...
@@ -161,15 +211,7 @@ export class KoishiMetascanService {
);
}
else
{
for
(
const
_optionToRegister
of
commandData
.
putOptions
)
{
if
(
_optionToRegister
?.
type
!==
'
option
'
)
{
continue
;
}
const
optionToRegister
=
_optionToRegister
as
CommandPutConfig
<
'
option
'
>
;
command
.
option
(
optionToRegister
.
data
.
name
,
optionToRegister
.
data
.
desc
,
optionToRegister
.
data
.
config
,
);
this
.
preRegisterCommandActionArg
(
_optionToRegister
,
command
);
}
command
.
action
((
argv
:
Argv
,
...
args
:
any
[])
=>
{
const
params
=
commandData
.
putOptions
.
map
((
o
)
=>
...
...
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