File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,16 @@ export const refreshApplicationCommands = async (harmonix: Harmonix) => {
4545 cmd . config . id = command . id
4646 }
4747 consola . success ( 'Successfully reloaded application commands.\n' )
48- const readyEvent = harmonix . events . get ( 'ready' )
49-
50- if ( readyEvent ) {
51- ctx . call ( harmonix as RuntimeHarmonix , ( ) => readyEvent . callback ( client ) )
48+ const readyEvents = harmonix . events . filter (
49+ ( event ) => event . config . name === 'ready'
50+ )
51+
52+ if ( readyEvents . size > 0 ) {
53+ for ( const [ , readyEvent ] of readyEvents ) {
54+ ctx . call ( harmonix as RuntimeHarmonix , ( ) =>
55+ readyEvent . callback ( client )
56+ )
57+ }
5258 }
5359 } catch ( error : any ) {
5460 createError ( error . message )
Original file line number Diff line number Diff line change @@ -12,7 +12,11 @@ import type {
1212
1313export const loadEvents = ( harmonix : Harmonix , events : HarmonixEvent [ ] ) => {
1414 for ( const evt of events ) {
15- harmonix . events . set ( evt . config . name ! , evt )
15+ if ( evt . config . order ) {
16+ harmonix . events . set ( `${ evt . config . order } .${ evt . config . name ! } ` , evt )
17+ } else {
18+ harmonix . events . set ( evt . config . name ! , evt )
19+ }
1620 }
1721}
1822
Original file line number Diff line number Diff line change @@ -49,12 +49,19 @@ export const resolveEvent = (
4949 )
5050 return { config : { name : filename ( _evtPath ) } , callback : ( ) => { } }
5151 }
52+ const matchPrefix = filename ( _evtPath ) . match ( / ^ [ 0 - 9 ] + \. / )
5253 const matchSuffix = filename ( _evtPath ) . match ( / \. ( o n | o n c e ) ? $ / )
53- const name = filename ( _evtPath ) . replace ( / \. ( o n | o n c e ) $ / , '' )
54+ const name = filename ( _evtPath )
55+ . replace ( / ^ [ 0 - 9 ] + \. / , '' )
56+ . replace ( / \. ( o n | o n c e ) $ / , '' )
57+ const order = matchPrefix
58+ ? parseInt ( matchPrefix [ 0 ] . slice ( 0 , - 1 ) )
59+ : undefined
5460 const once = matchSuffix ? matchSuffix [ 1 ] === 'once' : undefined
5561 const config : EventConfig = {
5662 name : event . config . name ?? name ,
57- once : event . config . once ?? once
63+ once : event . config . once ?? once ,
64+ order : event . config . order ?? order
5865 }
5966
6067 return { config, callback : event . callback }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export type EventCallback<Event extends keyof ClientEvents = any> = (
77export interface EventConfig {
88 name ?: string
99 once ?: boolean
10+ order ?: number
1011}
1112
1213export interface DefineEvent {
You can’t perform that action at this time.
0 commit comments