File tree Expand file tree Collapse file tree 4 files changed +29
-15
lines changed
Expand file tree Collapse file tree 4 files changed +29
-15
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import type {
1818 DefineEvent ,
1919 DefineEventWithOptions ,
2020 DefinePrecondition ,
21+ DefinePreconditionWithName ,
2122 EmbedOptions ,
2223 EmbedSetters ,
2324 EventCallback ,
@@ -101,10 +102,25 @@ export const defineContextMenu: DefineContextMenu &
101102 }
102103}
103104
104- export const definePrecondition : DefinePrecondition = (
105- callback : PreconditionCallback
105+ export const definePrecondition : DefinePrecondition &
106+ DefinePreconditionWithName = (
107+ ...args : [ PreconditionCallback | string , PreconditionCallback ?]
106108) => {
107- return { options : { } , callback }
109+ let name = ''
110+ let callback : PreconditionCallback
111+
112+ if ( args . length === 1 ) {
113+ const [ cb ] = args as [ PreconditionCallback ]
114+
115+ callback = cb
116+ } else {
117+ const [ nm , cb ] = args as [ string , PreconditionCallback ]
118+
119+ name = nm
120+ callback = cb
121+ }
122+
123+ return { name, callback }
108124}
109125
110126export const defineModal = ( options : ModalOptions ) : ModalBuilder => {
Original file line number Diff line number Diff line change @@ -35,6 +35,6 @@ export const loadPreconditions = (
3535 preconditions : HarmonixPrecondition [ ]
3636) => {
3737 for ( const prc of preconditions ) {
38- harmonix . preconditions . set ( prc . options . name ! , prc )
38+ harmonix . preconditions . set ( prc . name ! , prc )
3939 }
4040}
Original file line number Diff line number Diff line change @@ -13,8 +13,7 @@ import type {
1313 HarmonixEvent ,
1414 HarmonixEventInput ,
1515 HarmonixPrecondition ,
16- HarmonixPreconditionInput ,
17- PreconditionOptions
16+ HarmonixPreconditionInput
1817} from './types'
1918
2019export const resolveEvent = (
@@ -96,11 +95,9 @@ export const resolvePrecondition = (
9695 } )
9796 const _prcPath = _jiti . resolve ( prc )
9897 const precondition = _jiti ( _prcPath ) as HarmonixPrecondition
99- const options : PreconditionOptions = {
100- name : precondition . options . name || filename ( _prcPath ) . split ( '.' ) [ 0 ]
101- }
98+ const name = precondition . name || filename ( _prcPath ) . split ( '.' ) [ 0 ]
10299
103- return { options , callback : precondition . callback }
100+ return { name , callback : precondition . callback }
104101 } else {
105102 return prc
106103 }
Original file line number Diff line number Diff line change @@ -20,17 +20,18 @@ export type PreconditionCallback = (
2020 entity : SlashEntity | ContextMenuEntity
2121) => boolean
2222
23- export interface PreconditionOptions {
24- name ?: string
25- }
26-
2723export type DefinePrecondition = (
2824 callback : PreconditionCallback
2925) => HarmonixPrecondition
3026
27+ export type DefinePreconditionWithName = (
28+ name : string ,
29+ callback : PreconditionCallback
30+ ) => HarmonixPrecondition
31+
3132export type HarmonixPreconditionInput = string | HarmonixPrecondition
3233
3334export interface HarmonixPrecondition {
34- options : PreconditionOptions
35+ name : string
3536 callback : PreconditionCallback
3637}
You can’t perform that action at this time.
0 commit comments