Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Thirdeye
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 Thirdeye
Commits
178bbd57
Commit
178bbd57
authored
Dec 18, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add UseBeforeEvent
parent
c198c1c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
10 deletions
+27
-10
src/decorators.ts
src/decorators.ts
+7
-0
src/def/interfaces.ts
src/def/interfaces.ts
+11
-3
src/register.ts
src/register.ts
+9
-7
No files found.
src/decorators.ts
View file @
178bbd57
import
{
BeforeEventName
,
CommandConfigExtended
,
CommandDefinitionFun
,
CommandPutConfig
,
...
...
@@ -39,6 +40,12 @@ export const UseMiddleware = (prepend?: boolean): MethodDecorator =>
export
const
UseEvent
=
(
name
:
EventName
,
prepend
?:
boolean
):
MethodDecorator
=>
DoRegister
(
GenerateMappingStruct
(
'
onevent
'
,
{
name
,
prepend
}));
export
const
UseBeforeEvent
=
(
name
:
BeforeEventName
,
prepend
?:
boolean
,
):
MethodDecorator
=>
DoRegister
(
GenerateMappingStruct
(
'
beforeEvent
'
,
{
name
,
prepend
}));
export
const
UsePlugin
=
():
MethodDecorator
=>
DoRegister
(
GenerateMappingStruct
(
'
plugin
'
));
...
...
src/def/interfaces.ts
View file @
178bbd57
import
{
App
,
Argv
,
BeforeEventMap
,
Channel
,
Command
,
Context
,
...
...
@@ -76,17 +77,24 @@ export function PluginDef<T extends keyof Modules | Plugin>(
return
{
plugin
,
options
,
select
};
}
export
type
EventName
=
keyof
EventMap
;
export
interface
EventNameAndPrepend
{
name
:
EventName
;
export
interface
CommonEventNameAndPrepend
<
T
extends
keyof
any
>
{
name
:
T
;
prepend
?:
boolean
;
}
export
type
EventName
=
keyof
EventMap
;
export
type
EventNameAndPrepend
=
CommonEventNameAndPrepend
<
EventName
>
;
export
type
BeforeEventName
=
keyof
BeforeEventMap
;
export
type
BeforeEventNameAndPrepend
=
CommonEventNameAndPrepend
<
BeforeEventName
>
;
export
type
ContextFunction
<
T
>
=
(
ctx
:
Context
)
=>
T
;
export
type
OnContextFunction
=
ContextFunction
<
Context
>
;
export
interface
DoRegisterConfigDataMap
{
middleware
:
boolean
;
// prepend
onevent
:
EventNameAndPrepend
;
beforeEvent
:
BeforeEventNameAndPrepend
;
plugin
:
never
;
command
:
CommandRegisterConfig
;
route
:
KoishiRouteDef
;
...
...
src/register.ts
View file @
178bbd57
...
...
@@ -247,14 +247,16 @@ export function KoishiPlugin<T = any>(
(...
args
:
any
[])
=>
this
[
methodKey
](...
args
),
eventData
.
prepend
,
);
// special events
/*if (eventName === 'service') {
const serviceName = eventName.slice(8);
if (baseContext[serviceName] != null) {
this[methodKey]();
}
}*/
break
;
case
'
beforeEvent
'
:
const
{
data
:
beforeEventData
}
=
regData
as
DoRegisterConfig
<
'
beforeEvent
'
>
;
const
beforeEventName
=
beforeEventData
.
name
;
baseContext
.
before
(
beforeEventName
,
(...
args
:
any
[])
=>
this
[
methodKey
](...
args
),
beforeEventData
.
prepend
,
);
case
'
plugin
'
:
this
.
_applyInnerPlugin
(
baseContext
,
methodKey
);
break
;
...
...
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