@@ -9,7 +9,10 @@ import {
9
9
getCommandKit ,
10
10
getContext ,
11
11
} from '../../context/async-context' ;
12
- import { EventInterceptorContextData } from '../common/EventInterceptor' ;
12
+ import {
13
+ EventInterceptorContextData ,
14
+ EventInterceptorErrorHandler ,
15
+ } from '../common/EventInterceptor' ;
13
16
14
17
export type ModalKitPredicate = (
15
18
interaction : ModalSubmitInteraction ,
@@ -34,6 +37,7 @@ export type OnModalKitEnd = CommandKitModalBuilderOnEnd;
34
37
*/
35
38
export type CommandKitModalBuilderInteractionCollectorDispatch = (
36
39
interaction : ModalSubmitInteraction ,
40
+ context : ModalKit ,
37
41
) => Awaitable < void > ;
38
42
39
43
export type CommandKitModalBuilderOnEnd = ( reason : string ) => Awaitable < void > ;
@@ -46,8 +50,9 @@ export class ModalKit extends ModalBuilder {
46
50
null ;
47
51
#contextData: CommandKitModalBuilderInteractionCollectorDispatchContextData | null =
48
52
{
49
- autoReset : true ,
53
+ autoReset : false ,
50
54
time : 5 * 60 * 1000 ,
55
+ once : true ,
51
56
} ;
52
57
#unsub: ( ( ) => void ) | null = null ;
53
58
@@ -123,6 +128,24 @@ export class ModalKit extends ModalBuilder {
123
128
return this ;
124
129
}
125
130
131
+ /**
132
+ * Sets the handler to run when the interaction collector ends.
133
+ * @param handler - The handler to run when the interaction collector ends.
134
+ * @returns This instance of the modal builder.
135
+ */
136
+ public onError ( handler : EventInterceptorErrorHandler ) : this {
137
+ if ( ! handler ) {
138
+ throw new TypeError (
139
+ 'Cannot setup "onError" without a handler function parameter.' ,
140
+ ) ;
141
+ }
142
+
143
+ this . #contextData ??= { } ;
144
+ this . #contextData. onError = handler ;
145
+
146
+ return this ;
147
+ }
148
+
126
149
/**
127
150
* Sets a filter for the interaction collector.
128
151
* @param predicate - The filter to use for the interaction collector.
@@ -174,7 +197,7 @@ export class ModalKit extends ModalBuilder {
174
197
175
198
if ( ! handler ) return this . #unsub?.( ) ;
176
199
177
- return handler ( interaction ) ;
200
+ return handler ( interaction , this ) ;
178
201
} ,
179
202
this . #contextData,
180
203
) ;
0 commit comments