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
a445a60e
Commit
a445a60e
authored
Dec 28, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catchups from 3rdeye
parent
c84e085c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
36 deletions
+56
-36
src/providers/koishi-metascan.service.ts
src/providers/koishi-metascan.service.ts
+20
-14
src/utility/koishi.decorators.ts
src/utility/koishi.decorators.ts
+15
-3
src/utility/koishi.interfaces.ts
src/utility/koishi.interfaces.ts
+21
-19
No files found.
src/providers/koishi-metascan.service.ts
View file @
a445a60e
...
...
@@ -13,6 +13,7 @@ import {
KoishiServiceWireProperty
,
}
from
'
../utility/koishi.constants
'
;
import
{
CommandDefinitionFun
,
CommandPutConfig
,
DoRegisterConfig
,
KoishiCommandInterceptorRegistration
,
...
...
@@ -81,13 +82,16 @@ export class KoishiMetascanService {
return
;
}
switch
(
config
.
type
)
{
case
'
args
'
:
return
args
;
case
'
arg
'
:
const
{
data
:
i
ndex
}
=
config
as
CommandPutConfig
<
'
arg
'
>
;
return
args
[
i
ndex
];
const
{
data
:
argI
ndex
}
=
config
as
CommandPutConfig
<
'
arg
'
>
;
return
args
[
argI
ndex
];
case
'
argv
'
:
return
argv
;
case
'
session
'
:
return
argv
.
session
;
case
'
argvField
'
:
const
{
data
:
argvField
}
=
config
as
CommandPutConfig
<
'
argvField
'
>
;
return
argv
[
argvField
];
case
'
option
'
:
const
{
data
:
optionData
}
=
config
as
CommandPutConfig
<
'
option
'
>
;
return
argv
.
options
[
optionData
.
name
];
...
...
@@ -105,8 +109,9 @@ export class KoishiMetascanService {
}
return
argv
.
session
.
author
?.
nickname
||
argv
.
session
.
author
?.
username
;
case
'
sessionField
'
:
const
{
data
:
field
}
=
config
as
CommandPutConfig
<
'
sessionField
'
>
;
return
argv
.
session
[
field
];
const
{
data
:
sessionField
}
=
config
as
CommandPutConfig
<
'
sessionField
'
>
;
return
argv
.
session
[
sessionField
];
default
:
return
;
}
...
...
@@ -155,9 +160,8 @@ export class KoishiMetascanService {
);
break
;
case
'
beforeEvent
'
:
const
{
data
:
beforeEventData
,
}
=
regData
as
DoRegisterConfig
<
'
beforeEvent
'
>
;
const
{
data
:
beforeEventData
}
=
regData
as
DoRegisterConfig
<
'
beforeEvent
'
>
;
const
beforeEventName
=
beforeEventData
.
name
;
baseContext
.
before
(
beforeEventName
,
...
...
@@ -181,17 +185,19 @@ export class KoishiMetascanService {
commandData
.
desc
,
commandData
.
config
,
);
const
commandDefs
=
this
.
metaFetcher
.
getMetadataArray
(
KoishiCommandDefinition
,
methodFun
,
);
const
commandDefs
:
CommandDefinitionFun
[]
=
this
.
metaFetcher
.
getPropertyMetadataArray
(
KoishiCommandDefinition
,
instance
,
methodKey
,
);
for
(
const
commandDef
of
commandDefs
)
{
command
=
commandDef
(
command
)
||
command
;
}
if
(
commandData
.
config
?.
empty
)
{
break
;
}
const
interceptorDefs
=
_
.
uniq
(
const
interceptorDefs
:
KoishiCommandInterceptorRegistration
[]
=
_
.
uniq
(
this
.
metaFetcher
.
getPropertyMetadataArray
(
KoishiCommandInterceptorDef
,
instance
,
...
...
src/utility/koishi.decorators.ts
View file @
a445a60e
...
...
@@ -62,7 +62,7 @@ export const InjectContextUser = (...values: string[]) =>
export
function
TransformMetadata
<
K
extends
MetadataKey
,
VM
extends
Partial
<
MetadataGenericMap
>
=
MetadataGenericMap
VM
extends
Partial
<
MetadataGenericMap
>
=
MetadataGenericMap
,
>
(
metadataKey
:
K
,
metadataValueFun
:
(
oldValue
:
VM
[
K
])
=>
VM
[
K
],
...
...
@@ -196,7 +196,9 @@ export const OnSelection = (selection: Selection) =>
// Command definition
export
const
CommandDef
=
(
def
:
CommandDefinitionFun
):
MethodDecorator
=>
export
const
CommandDef
=
(
def
:
CommandDefinitionFun
,
):
MethodDecorator
&
ClassDecorator
=>
AppendMetadata
(
KoishiCommandDefinition
,
def
);
export
const
CommandDescription
=
(
desc
:
string
)
=>
...
...
@@ -231,6 +233,12 @@ export const CommandUserFields = (fields: FieldCollector<'user'>) =>
export
const
CommandChannelFields
=
(
fields
:
FieldCollector
<
'
channel
'
>
)
=>
CommandDef
((
cmd
)
=>
cmd
.
channelFields
(
fields
));
export
const
CommandBefore
=
(
callback
:
Command
.
Action
,
append
=
false
)
=>
CommandDef
((
cmd
)
=>
cmd
.
before
(
callback
,
append
));
export
const
CommandAction
=
(
callback
:
Command
.
Action
,
prepend
=
false
)
=>
CommandDef
((
cmd
)
=>
cmd
.
action
(
callback
,
prepend
));
// Command put config
function
PutCommandParam
<
T
extends
keyof
CommandPutConfigMap
>
(
...
...
@@ -248,8 +256,11 @@ function PutCommandParam<T extends keyof CommandPutConfigMap>(
export
const
PutArgv
=
()
=>
PutCommandParam
(
'
argv
'
);
export
const
PutSession
=
(
field
?:
keyof
Session
)
=>
field
?
PutCommandParam
(
'
sessionField
'
,
field
)
:
PutCommandParam
(
'
session
'
);
field
?
PutCommandParam
(
'
sessionField
'
,
field
)
:
PutCommandParam
(
'
argvField
'
,
'
session
'
);
export
const
PutArg
=
(
i
:
number
)
=>
PutCommandParam
(
'
arg
'
,
i
);
export
const
PutArgs
=
()
=>
PutCommandParam
(
'
args
'
);
export
const
PutOption
=
(
name
:
string
,
desc
:
string
,
...
...
@@ -272,6 +283,7 @@ export const PutChannelId = () => PutSession('channelId');
export
const
PutChannelName
=
()
=>
PutSession
(
'
channelName
'
);
export
const
PutSelfId
=
()
=>
PutSession
(
'
selfId
'
);
export
const
PutBot
=
()
=>
PutSession
(
'
bot
'
);
export
const
PutNext
=
()
=>
PutCommandParam
(
'
argvField
'
,
'
next
'
);
// Service
...
...
src/utility/koishi.interfaces.ts
View file @
a445a60e
...
...
@@ -96,10 +96,11 @@ export type EventNameAndPrepend = CommonEventNameAndPrepend<EventName>;
type
OmitSubstring
<
S
extends
string
,
T
extends
string
T
extends
string
,
>
=
S
extends
`
${
infer
L
}${
T
}${
infer
R
}
`
?
`
${
L
}${
R
}
`
:
never
;
export
type
BeforeEventName
=
OmitSubstring
<
EventName
&
string
,
'
before-
'
>
;
export
type
BeforeEventNameAndPrepend
=
CommonEventNameAndPrepend
<
BeforeEventName
>
;
export
type
BeforeEventNameAndPrepend
=
CommonEventNameAndPrepend
<
BeforeEventName
>
;
export
type
ContextFunction
<
T
>
=
(
ctx
:
Context
)
=>
T
;
export
type
OnContextFunction
=
ContextFunction
<
Context
>
;
...
...
@@ -113,7 +114,7 @@ export interface DoRegisterConfigDataMap {
export
interface
MappingStruct
<
T
extends
Record
<
string
|
number
|
symbol
,
any
>
,
K
extends
keyof
T
K
extends
keyof
T
,
>
{
type
:
K
;
data
?:
T
[
K
];
...
...
@@ -121,7 +122,7 @@ export interface MappingStruct<
export
function
GenerateMappingStruct
<
T
extends
Record
<
string
|
number
|
symbol
,
any
>
,
K
extends
keyof
T
K
extends
keyof
T
,
>
(
type
:
K
,
data
?:
T
[
K
]):
MappingStruct
<
T
,
K
>
{
return
{
type
,
...
...
@@ -130,7 +131,7 @@ export function GenerateMappingStruct<
}
export
type
DoRegisterConfig
<
K
extends
keyof
DoRegisterConfigDataMap
=
keyof
DoRegisterConfigDataMap
K
extends
keyof
DoRegisterConfigDataMap
=
keyof
DoRegisterConfigDataMap
,
>
=
MappingStruct
<
DoRegisterConfigDataMap
,
K
>
;
// Command stuff
...
...
@@ -153,9 +154,10 @@ export interface CommandOptionConfig {
}
export
interface
CommandPutConfigMap
{
args
:
never
;
arg
:
number
;
argv
:
never
;
session
:
never
;
argvField
:
keyof
Argv
;
option
:
CommandOptionConfig
;
user
:
FieldCollector
<
'
user
'
>
;
channel
:
FieldCollector
<
'
channel
'
>
;
...
...
@@ -164,7 +166,7 @@ export interface CommandPutConfigMap {
}
export
type
CommandPutConfig
<
K
extends
keyof
CommandPutConfigMap
=
keyof
CommandPutConfigMap
K
extends
keyof
CommandPutConfigMap
=
keyof
CommandPutConfigMap
,
>
=
MappingStruct
<
CommandPutConfigMap
,
K
>
;
export
type
CommandDefinitionFun
=
(
cmd
:
Command
)
=>
Command
;
...
...
@@ -176,19 +178,17 @@ export type MetadataArrayValueMap = {
export
type
MetadataGenericMap
=
MetadataArrayValueMap
&
MetadataMap
;
export
type
MetadataArrayValue
<
K
extends
keyof
MetadataArrayValueMap
>
=
MetadataArrayValueMap
[
K
];
export
type
MetadataArrayValue
<
K
extends
keyof
MetadataArrayValueMap
>
=
MetadataArrayValueMap
[
K
];
export
type
MetadataKey
=
keyof
MetadataArrayMap
|
keyof
MetadataMap
;
export
type
MetadataMapValue
<
K
extends
MetadataKey
>
=
K
extends
keyof
MetadataArrayValueMap
?
MetadataArrayValue
<
K
>
:
K
extends
keyof
MetadataMap
?
MetadataMap
[
K
]
:
never
;
export
type
MetadataMapValue
<
K
extends
MetadataKey
>
=
K
extends
keyof
MetadataArrayValueMap
?
MetadataArrayValue
<
K
>
:
K
extends
keyof
MetadataMap
?
MetadataMap
[
K
]
:
never
;
// command interceptor
...
...
@@ -196,7 +196,8 @@ export interface KoishiCommandInterceptor<
U
extends
User
.
Field
=
never
,
G
extends
Channel
.
Field
=
never
,
A
extends
any
[]
=
any
[],
O
extends
{}
=
{}
// eslint-disable-next-line @typescript-eslint/ban-types
O
extends
{}
=
{},
>
{
intercept
:
Command
.
Action
<
U
,
G
,
A
,
O
>
;
}
...
...
@@ -205,7 +206,8 @@ export type KoishiCommandInterceptorRegistration<
U
extends
User
.
Field
=
never
,
G
extends
Channel
.
Field
=
never
,
A
extends
any
[]
=
any
[],
O
extends
{}
=
{}
// eslint-disable-next-line @typescript-eslint/ban-types
O
extends
{}
=
{},
>
=
|
KoishiCommandInterceptor
<
U
,
G
,
A
,
O
>
|
Type
<
KoishiCommandInterceptor
<
U
,
G
,
A
,
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