discord-embed-router 0.2.0 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +144 -53
- package/dist/index.d.ts +144 -53
- package/dist/index.js +286 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -139
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { ParamData, Path, MatchFunction, MatchResult, TokenData } from 'path-to-regexp';
|
|
2
|
-
import { Interaction, InteractionEditReplyOptions, ButtonInteraction, AnySelectMenuInteraction, InteractionReplyOptions, ButtonBuilder, APIButtonComponent, StringSelectMenuOptionBuilder,
|
|
2
|
+
import { Interaction, InteractionEditReplyOptions, ButtonInteraction, AnySelectMenuInteraction, InteractionReplyOptions, ButtonBuilder, APIButtonComponent, StringSelectMenuOptionBuilder, StringSelectMenuBuilder, StringSelectMenuComponentData, APIStringSelectComponent, RestOrArray, ChannelSelectMenuBuilder, ChannelSelectMenuComponentData, APIChannelSelectComponent, RoleSelectMenuBuilder, RoleSelectMenuComponentData, APIRoleSelectComponent, UserSelectMenuBuilder, UserSelectMenuComponentData, APIUserSelectComponent } from 'discord.js';
|
|
3
3
|
|
|
4
4
|
type State<L, P extends ParamData = ParamData> = MatchResult<P> & {
|
|
5
5
|
embedRouter: EmbedRouter<L>;
|
|
6
6
|
locals?: L | undefined;
|
|
7
7
|
query: URLSearchParams;
|
|
8
8
|
};
|
|
9
|
-
type RouteResponse = InteractionEditReplyOptions;
|
|
10
|
-
type RouteHandler<L, P extends ParamData = ParamData> = (interaction: Interaction, state: State<L, P>) => Promise<RouteResponse> | RouteResponse;
|
|
11
|
-
type
|
|
9
|
+
type RouteResponse = InteractionEditReplyOptions | undefined;
|
|
10
|
+
type RouteHandler<M extends Method, L, P extends ParamData = ParamData> = (interaction: Interaction, state: State<L, P>) => M extends "GET" ? Promise<RouteResponse> | RouteResponse : Promise<RouteResponse | undefined> | RouteResponse | undefined;
|
|
11
|
+
type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
12
|
+
type CompiledRoute<M extends Method, L, P extends ParamData = ParamData> = {
|
|
13
|
+
method: Method;
|
|
12
14
|
path: Path[];
|
|
13
15
|
matchFunction: MatchFunction<P>;
|
|
14
|
-
handler: RouteHandler<L, P>;
|
|
15
|
-
};
|
|
16
|
-
type ResolvedRoute<L, P extends ParamData = ParamData> = {
|
|
17
|
-
state: State<L, P>;
|
|
18
|
-
handler: RouteHandler<L, P>;
|
|
16
|
+
handler: RouteHandler<M, L, P>;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
type TakeIdentifier<T extends string, Name extends string = ""> = T extends `${infer Char}${infer Rest}` ? Char extends "/" | ":" | "*" | "{" | "}" ? [Name, T] : TakeIdentifier<Rest, `${Name}${Char}`> : [Name, T];
|
|
@@ -31,29 +29,52 @@ type ExtractParams<T extends string | TokenData, Depth extends string = ""> = T
|
|
|
31
29
|
}) & ExtractParams<After, Depth> : ExtractParams<Rest, Depth> : Char extends "{" ? ExtractParams<Rest, `${Depth}1`> : Char extends "}" ? ExtractParams<Rest, Depth extends `1${infer Rest2}` ? Rest2 : Depth> : ExtractParams<Rest, Depth> : object : never;
|
|
32
30
|
|
|
33
31
|
declare class EmbedRouter<L> {
|
|
34
|
-
private
|
|
35
|
-
private name;
|
|
36
|
-
private idPrefix;
|
|
37
|
-
private identifier;
|
|
32
|
+
#private;
|
|
38
33
|
getIdPrefix(): string;
|
|
39
|
-
private routes;
|
|
40
34
|
/**
|
|
41
35
|
*
|
|
42
36
|
* @param name the name to give the router. ensures buttons stay connected across restarts
|
|
43
37
|
* @param idPrefix the prefix for RouteButtonBuilder customIds
|
|
44
38
|
*/
|
|
45
39
|
constructor({ name, idPrefix, }?: {
|
|
46
|
-
name?: string;
|
|
47
|
-
idPrefix?: string;
|
|
40
|
+
name?: string | undefined;
|
|
41
|
+
idPrefix?: string | undefined;
|
|
48
42
|
});
|
|
49
|
-
private updateIdentifier;
|
|
50
43
|
/**
|
|
51
44
|
* Registers a path with the router
|
|
52
45
|
*
|
|
53
46
|
* @param routePath path to match with
|
|
54
47
|
* @param handler function that generates the message when a path is matched
|
|
55
48
|
*/
|
|
56
|
-
get<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<L, ExtractParams<P>>): void;
|
|
49
|
+
get<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"GET", L, ExtractParams<P>>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Registers a path with the router
|
|
52
|
+
*
|
|
53
|
+
* @param routePath path to match with
|
|
54
|
+
* @param handler function that generates the message when a path is matched
|
|
55
|
+
*/
|
|
56
|
+
post<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"POST", L, ExtractParams<P>>): void;
|
|
57
|
+
/**
|
|
58
|
+
* Registers a path with the router
|
|
59
|
+
*
|
|
60
|
+
* @param routePath path to match with
|
|
61
|
+
* @param handler function that generates the message when a path is matched
|
|
62
|
+
*/
|
|
63
|
+
put<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"PUT", L, ExtractParams<P>>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Registers a path with the router
|
|
66
|
+
*
|
|
67
|
+
* @param routePath path to match with
|
|
68
|
+
* @param handler function that generates the message when a path is matched
|
|
69
|
+
*/
|
|
70
|
+
patch<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"PATCH", L, ExtractParams<P>>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Registers a path with the router
|
|
73
|
+
*
|
|
74
|
+
* @param routePath path to match with
|
|
75
|
+
* @param handler function that generates the message when a path is matched
|
|
76
|
+
*/
|
|
77
|
+
delete<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"DELETE", L, ExtractParams<P>>): void;
|
|
57
78
|
/**
|
|
58
79
|
* Adds a subrouter to the router
|
|
59
80
|
*
|
|
@@ -66,26 +87,39 @@ declare class EmbedRouter<L> {
|
|
|
66
87
|
*
|
|
67
88
|
* @param interaction interactions from "interactionCreate" (filter for ButtonInteractions)
|
|
68
89
|
*/
|
|
69
|
-
listener(interaction: ButtonInteraction | AnySelectMenuInteraction, locals?: L): Promise<void>;
|
|
90
|
+
listener(interaction: ButtonInteraction | AnySelectMenuInteraction, locals?: L | undefined): Promise<void>;
|
|
70
91
|
/**
|
|
71
|
-
*
|
|
92
|
+
* Replies to or editReplies to an interaction based on the route output
|
|
72
93
|
*
|
|
73
94
|
* @param interaction interaction to connect to
|
|
74
95
|
* @param path path to route the interaction to
|
|
75
|
-
* @param
|
|
96
|
+
* @param method method to send to route
|
|
97
|
+
* @param flags discord flags to send with message (optional, only allowed on first reply)
|
|
98
|
+
* @param locals additional info to pass in to page through state.local (optional)
|
|
76
99
|
*/
|
|
77
|
-
dispatch<P extends Path = Path>(interaction
|
|
78
|
-
|
|
100
|
+
dispatch<P extends Path = Path>({ interaction, method, path, flags, locals, }: {
|
|
101
|
+
interaction: Interaction;
|
|
102
|
+
method?: Method;
|
|
103
|
+
path: P;
|
|
104
|
+
flags?: InteractionReplyOptions["flags"] | undefined;
|
|
105
|
+
locals?: L | undefined;
|
|
106
|
+
}): Promise<void>;
|
|
79
107
|
}
|
|
80
108
|
|
|
109
|
+
type SetOptions<P extends Path> = {
|
|
110
|
+
method?: Method;
|
|
111
|
+
path: P;
|
|
112
|
+
query?: ConstructorParameters<typeof URLSearchParams>[0] | undefined;
|
|
113
|
+
};
|
|
114
|
+
|
|
81
115
|
declare class RouteButtonBuilder<L> extends ButtonBuilder {
|
|
82
|
-
private
|
|
116
|
+
#private;
|
|
83
117
|
/**
|
|
84
118
|
*
|
|
85
119
|
* @param embedRouter the router you want to route with
|
|
86
120
|
* @param data the data to construct a component out of
|
|
87
121
|
*/
|
|
88
|
-
constructor(embedRouter: EmbedRouter<L>, data?: Omit<Partial<APIButtonComponent>, "custom_id" | "url">);
|
|
122
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Omit<Partial<APIButtonComponent>, "custom_id" | "url"> | undefined);
|
|
89
123
|
/**
|
|
90
124
|
* Not supported for RouteButtonBuilder
|
|
91
125
|
*
|
|
@@ -105,18 +139,18 @@ declare class RouteButtonBuilder<L> extends ButtonBuilder {
|
|
|
105
139
|
*
|
|
106
140
|
* @param path the path to route to
|
|
107
141
|
* @param query any query parameters you want to add
|
|
142
|
+
* @param method method to send to route
|
|
108
143
|
*/
|
|
109
|
-
setTo<P extends Path>(
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionBuilder {
|
|
144
|
+
setTo<P extends Path>({ method, path, query }: SetOptions<P>): this;
|
|
113
145
|
/**
|
|
146
|
+
* Sets the path to route to when clicked
|
|
114
147
|
*
|
|
115
|
-
* @param
|
|
148
|
+
* @param path the path to route to
|
|
116
149
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
150
|
+
setTo<P extends Path>(path: P): this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionBuilder {
|
|
120
154
|
/**
|
|
121
155
|
* Not supported for RouteStringSelectMenuOptionBuilder (use setTo)
|
|
122
156
|
*
|
|
@@ -129,12 +163,19 @@ declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionB
|
|
|
129
163
|
*
|
|
130
164
|
* @param path the path to route to
|
|
131
165
|
* @param query any query parameters you want to add
|
|
166
|
+
* @param method method to send to route
|
|
132
167
|
*/
|
|
133
|
-
setTo<P extends Path>(
|
|
168
|
+
setTo<P extends Path>({ method, path, query }: SetOptions<P>): this;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the path to route to when clicked
|
|
171
|
+
*
|
|
172
|
+
* @param path the path to route to
|
|
173
|
+
*/
|
|
174
|
+
setTo<P extends Path>(path: P): this;
|
|
134
175
|
}
|
|
135
176
|
|
|
136
|
-
declare class RouteStringSelectMenuBuilder<L
|
|
137
|
-
private
|
|
177
|
+
declare class RouteStringSelectMenuBuilder<L> extends StringSelectMenuBuilder {
|
|
178
|
+
#private;
|
|
138
179
|
/**
|
|
139
180
|
*
|
|
140
181
|
* @param embedRouter the router you want to route with
|
|
@@ -142,7 +183,7 @@ declare class RouteStringSelectMenuBuilder<L, P extends Path> extends StringSele
|
|
|
142
183
|
* @param query any query parameters you want to add, :to will be replaced with the selected user's id
|
|
143
184
|
* @param data the data to construct a component out of
|
|
144
185
|
*/
|
|
145
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
186
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<StringSelectMenuComponentData | APIStringSelectComponent> | undefined);
|
|
146
187
|
/**
|
|
147
188
|
* Not supported for RouteStringSelectMenuBuilder (customId set from embedRouter)
|
|
148
189
|
*
|
|
@@ -176,18 +217,30 @@ declare class RouteStringSelectMenuBuilder<L, P extends Path> extends StringSele
|
|
|
176
217
|
* @param tos the list of route select menu options
|
|
177
218
|
*/
|
|
178
219
|
setTos(...tos: RestOrArray<RouteStringSelectMenuOptionBuilder | ConstructorParameters<typeof RouteStringSelectMenuOptionBuilder>[0]>): this;
|
|
220
|
+
/**
|
|
221
|
+
* Sets the pattern to redirect to (Required)
|
|
222
|
+
*
|
|
223
|
+
* @param path the path to redirect to, :to or *to in path will be replaced with the selected user's id
|
|
224
|
+
* @param query any query parameters you want to add, :to will be replaced with the selected user's id
|
|
225
|
+
* @param method method to send to route
|
|
226
|
+
*/
|
|
227
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the path to route to when clicked
|
|
230
|
+
*
|
|
231
|
+
* @param path the path to route to
|
|
232
|
+
*/
|
|
233
|
+
setPattern<P extends Path>(path: P): this;
|
|
179
234
|
}
|
|
180
235
|
|
|
181
|
-
declare class RouteChannelSelectMenuBuilder<L
|
|
182
|
-
private
|
|
236
|
+
declare class RouteChannelSelectMenuBuilder<L> extends ChannelSelectMenuBuilder {
|
|
237
|
+
#private;
|
|
183
238
|
/**
|
|
184
239
|
*
|
|
185
240
|
* @param embedRouter the router you want to route with
|
|
186
|
-
* @param path the path to redirect to, :channelId in path will be replaced with the selected user's id
|
|
187
|
-
* @param query any query parameters you want to add, :channelId will be replaced with the selected user's id
|
|
188
241
|
* @param data the data to construct a component out of
|
|
189
242
|
*/
|
|
190
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
243
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<ChannelSelectMenuComponentData | APIChannelSelectComponent> | undefined);
|
|
191
244
|
/**
|
|
192
245
|
* Not supported for RouteChannelSelectMenuBuilder (customId set from embedRouter)
|
|
193
246
|
*
|
|
@@ -195,18 +248,30 @@ declare class RouteChannelSelectMenuBuilder<L, P extends Path> extends ChannelSe
|
|
|
195
248
|
* @param
|
|
196
249
|
*/
|
|
197
250
|
setCustomId(): this;
|
|
251
|
+
/**
|
|
252
|
+
* Sets the pattern to redirect to (Required)
|
|
253
|
+
*
|
|
254
|
+
* @param path the path to redirect to, :channelId in path will be replaced with the selected user's id
|
|
255
|
+
* @param query any query parameters you want to add, :channelId will be replaced with the selected user's id
|
|
256
|
+
* @param method method to send to route
|
|
257
|
+
*/
|
|
258
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
259
|
+
/**
|
|
260
|
+
* Sets the path to route to when clicked
|
|
261
|
+
*
|
|
262
|
+
* @param path the path to route to
|
|
263
|
+
*/
|
|
264
|
+
setPattern<P extends Path>(path: P): this;
|
|
198
265
|
}
|
|
199
266
|
|
|
200
|
-
declare class RouteRoleSelectMenuBuilder<L
|
|
201
|
-
private
|
|
267
|
+
declare class RouteRoleSelectMenuBuilder<L> extends RoleSelectMenuBuilder {
|
|
268
|
+
#private;
|
|
202
269
|
/**
|
|
203
270
|
*
|
|
204
271
|
* @param embedRouter the router you want to route with
|
|
205
|
-
* @param path the path to redirect to, :roleId in path will be replaced with the selected user's id
|
|
206
|
-
* @param query any query parameters you want to add, :roleId will be replaced with the selected user's id
|
|
207
272
|
* @param data the data to construct a component out of
|
|
208
273
|
*/
|
|
209
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
274
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<RoleSelectMenuComponentData | APIRoleSelectComponent> | undefined);
|
|
210
275
|
/**
|
|
211
276
|
* Not supported for RouteRoleSelectMenuBuilder (customId set from embedRouter)
|
|
212
277
|
*
|
|
@@ -214,18 +279,30 @@ declare class RouteRoleSelectMenuBuilder<L, P extends Path> extends RoleSelectMe
|
|
|
214
279
|
* @param
|
|
215
280
|
*/
|
|
216
281
|
setCustomId(): this;
|
|
282
|
+
/**
|
|
283
|
+
* Sets the pattern to redirect to (Required)
|
|
284
|
+
*
|
|
285
|
+
* @param path the path to redirect to, :roleId in path will be replaced with the selected user's id
|
|
286
|
+
* @param query any query parameters you want to add, :roleId will be replaced with the selected user's id
|
|
287
|
+
* @param method method to send to route
|
|
288
|
+
*/
|
|
289
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
290
|
+
/**
|
|
291
|
+
* Sets the path to route to when clicked
|
|
292
|
+
*
|
|
293
|
+
* @param path the path to route to
|
|
294
|
+
*/
|
|
295
|
+
setPattern<P extends Path>(path: P): this;
|
|
217
296
|
}
|
|
218
297
|
|
|
219
|
-
declare class RouteUserSelectMenuBuilder<L
|
|
220
|
-
private
|
|
298
|
+
declare class RouteUserSelectMenuBuilder<L> extends UserSelectMenuBuilder {
|
|
299
|
+
#private;
|
|
221
300
|
/**
|
|
222
301
|
*
|
|
223
302
|
* @param embedRouter the router you want to route with
|
|
224
|
-
* @param path the path to redirect to, :userId in path will be replaced with the selected user's id
|
|
225
|
-
* @param query any query parameters you want to add, :userId will be replaced with the selected user's id
|
|
226
303
|
* @param data the data to construct a component out of
|
|
227
304
|
*/
|
|
228
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
305
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<UserSelectMenuComponentData | APIUserSelectComponent> | undefined);
|
|
229
306
|
/**
|
|
230
307
|
* Not supported for RouteUserSelectMenuBuilder (customId set from embedRouter)
|
|
231
308
|
*
|
|
@@ -233,6 +310,20 @@ declare class RouteUserSelectMenuBuilder<L, P extends Path> extends UserSelectMe
|
|
|
233
310
|
* @param
|
|
234
311
|
*/
|
|
235
312
|
setCustomId(): this;
|
|
313
|
+
/**
|
|
314
|
+
* Sets the pattern to redirect to (Required)
|
|
315
|
+
*
|
|
316
|
+
* @param path the path to redirect to, :userId in path will be replaced with the selected user's id
|
|
317
|
+
* @param query any query parameters you want to add, :userId will be replaced with the selected user's id
|
|
318
|
+
* @param method method to send to route
|
|
319
|
+
*/
|
|
320
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
321
|
+
/**
|
|
322
|
+
* Sets the path to route to when clicked
|
|
323
|
+
*
|
|
324
|
+
* @param path the path to route to
|
|
325
|
+
*/
|
|
326
|
+
setPattern<P extends Path>(path: P): this;
|
|
236
327
|
}
|
|
237
328
|
|
|
238
|
-
export { type CompiledRoute, EmbedRouter, type
|
|
329
|
+
export { type CompiledRoute, EmbedRouter, type Method, RouteButtonBuilder, RouteChannelSelectMenuBuilder, type RouteHandler, type RouteResponse, RouteRoleSelectMenuBuilder, RouteStringSelectMenuBuilder, RouteStringSelectMenuOptionBuilder, RouteUserSelectMenuBuilder, type State };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { ParamData, Path, MatchFunction, MatchResult, TokenData } from 'path-to-regexp';
|
|
2
|
-
import { Interaction, InteractionEditReplyOptions, ButtonInteraction, AnySelectMenuInteraction, InteractionReplyOptions, ButtonBuilder, APIButtonComponent, StringSelectMenuOptionBuilder,
|
|
2
|
+
import { Interaction, InteractionEditReplyOptions, ButtonInteraction, AnySelectMenuInteraction, InteractionReplyOptions, ButtonBuilder, APIButtonComponent, StringSelectMenuOptionBuilder, StringSelectMenuBuilder, StringSelectMenuComponentData, APIStringSelectComponent, RestOrArray, ChannelSelectMenuBuilder, ChannelSelectMenuComponentData, APIChannelSelectComponent, RoleSelectMenuBuilder, RoleSelectMenuComponentData, APIRoleSelectComponent, UserSelectMenuBuilder, UserSelectMenuComponentData, APIUserSelectComponent } from 'discord.js';
|
|
3
3
|
|
|
4
4
|
type State<L, P extends ParamData = ParamData> = MatchResult<P> & {
|
|
5
5
|
embedRouter: EmbedRouter<L>;
|
|
6
6
|
locals?: L | undefined;
|
|
7
7
|
query: URLSearchParams;
|
|
8
8
|
};
|
|
9
|
-
type RouteResponse = InteractionEditReplyOptions;
|
|
10
|
-
type RouteHandler<L, P extends ParamData = ParamData> = (interaction: Interaction, state: State<L, P>) => Promise<RouteResponse> | RouteResponse;
|
|
11
|
-
type
|
|
9
|
+
type RouteResponse = InteractionEditReplyOptions | undefined;
|
|
10
|
+
type RouteHandler<M extends Method, L, P extends ParamData = ParamData> = (interaction: Interaction, state: State<L, P>) => M extends "GET" ? Promise<RouteResponse> | RouteResponse : Promise<RouteResponse | undefined> | RouteResponse | undefined;
|
|
11
|
+
type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
12
|
+
type CompiledRoute<M extends Method, L, P extends ParamData = ParamData> = {
|
|
13
|
+
method: Method;
|
|
12
14
|
path: Path[];
|
|
13
15
|
matchFunction: MatchFunction<P>;
|
|
14
|
-
handler: RouteHandler<L, P>;
|
|
15
|
-
};
|
|
16
|
-
type ResolvedRoute<L, P extends ParamData = ParamData> = {
|
|
17
|
-
state: State<L, P>;
|
|
18
|
-
handler: RouteHandler<L, P>;
|
|
16
|
+
handler: RouteHandler<M, L, P>;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
type TakeIdentifier<T extends string, Name extends string = ""> = T extends `${infer Char}${infer Rest}` ? Char extends "/" | ":" | "*" | "{" | "}" ? [Name, T] : TakeIdentifier<Rest, `${Name}${Char}`> : [Name, T];
|
|
@@ -31,29 +29,52 @@ type ExtractParams<T extends string | TokenData, Depth extends string = ""> = T
|
|
|
31
29
|
}) & ExtractParams<After, Depth> : ExtractParams<Rest, Depth> : Char extends "{" ? ExtractParams<Rest, `${Depth}1`> : Char extends "}" ? ExtractParams<Rest, Depth extends `1${infer Rest2}` ? Rest2 : Depth> : ExtractParams<Rest, Depth> : object : never;
|
|
32
30
|
|
|
33
31
|
declare class EmbedRouter<L> {
|
|
34
|
-
private
|
|
35
|
-
private name;
|
|
36
|
-
private idPrefix;
|
|
37
|
-
private identifier;
|
|
32
|
+
#private;
|
|
38
33
|
getIdPrefix(): string;
|
|
39
|
-
private routes;
|
|
40
34
|
/**
|
|
41
35
|
*
|
|
42
36
|
* @param name the name to give the router. ensures buttons stay connected across restarts
|
|
43
37
|
* @param idPrefix the prefix for RouteButtonBuilder customIds
|
|
44
38
|
*/
|
|
45
39
|
constructor({ name, idPrefix, }?: {
|
|
46
|
-
name?: string;
|
|
47
|
-
idPrefix?: string;
|
|
40
|
+
name?: string | undefined;
|
|
41
|
+
idPrefix?: string | undefined;
|
|
48
42
|
});
|
|
49
|
-
private updateIdentifier;
|
|
50
43
|
/**
|
|
51
44
|
* Registers a path with the router
|
|
52
45
|
*
|
|
53
46
|
* @param routePath path to match with
|
|
54
47
|
* @param handler function that generates the message when a path is matched
|
|
55
48
|
*/
|
|
56
|
-
get<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<L, ExtractParams<P>>): void;
|
|
49
|
+
get<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"GET", L, ExtractParams<P>>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Registers a path with the router
|
|
52
|
+
*
|
|
53
|
+
* @param routePath path to match with
|
|
54
|
+
* @param handler function that generates the message when a path is matched
|
|
55
|
+
*/
|
|
56
|
+
post<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"POST", L, ExtractParams<P>>): void;
|
|
57
|
+
/**
|
|
58
|
+
* Registers a path with the router
|
|
59
|
+
*
|
|
60
|
+
* @param routePath path to match with
|
|
61
|
+
* @param handler function that generates the message when a path is matched
|
|
62
|
+
*/
|
|
63
|
+
put<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"PUT", L, ExtractParams<P>>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Registers a path with the router
|
|
66
|
+
*
|
|
67
|
+
* @param routePath path to match with
|
|
68
|
+
* @param handler function that generates the message when a path is matched
|
|
69
|
+
*/
|
|
70
|
+
patch<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"PATCH", L, ExtractParams<P>>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Registers a path with the router
|
|
73
|
+
*
|
|
74
|
+
* @param routePath path to match with
|
|
75
|
+
* @param handler function that generates the message when a path is matched
|
|
76
|
+
*/
|
|
77
|
+
delete<P extends Path = Path>(routePath: P | P[], handler: RouteHandler<"DELETE", L, ExtractParams<P>>): void;
|
|
57
78
|
/**
|
|
58
79
|
* Adds a subrouter to the router
|
|
59
80
|
*
|
|
@@ -66,26 +87,39 @@ declare class EmbedRouter<L> {
|
|
|
66
87
|
*
|
|
67
88
|
* @param interaction interactions from "interactionCreate" (filter for ButtonInteractions)
|
|
68
89
|
*/
|
|
69
|
-
listener(interaction: ButtonInteraction | AnySelectMenuInteraction, locals?: L): Promise<void>;
|
|
90
|
+
listener(interaction: ButtonInteraction | AnySelectMenuInteraction, locals?: L | undefined): Promise<void>;
|
|
70
91
|
/**
|
|
71
|
-
*
|
|
92
|
+
* Replies to or editReplies to an interaction based on the route output
|
|
72
93
|
*
|
|
73
94
|
* @param interaction interaction to connect to
|
|
74
95
|
* @param path path to route the interaction to
|
|
75
|
-
* @param
|
|
96
|
+
* @param method method to send to route
|
|
97
|
+
* @param flags discord flags to send with message (optional, only allowed on first reply)
|
|
98
|
+
* @param locals additional info to pass in to page through state.local (optional)
|
|
76
99
|
*/
|
|
77
|
-
dispatch<P extends Path = Path>(interaction
|
|
78
|
-
|
|
100
|
+
dispatch<P extends Path = Path>({ interaction, method, path, flags, locals, }: {
|
|
101
|
+
interaction: Interaction;
|
|
102
|
+
method?: Method;
|
|
103
|
+
path: P;
|
|
104
|
+
flags?: InteractionReplyOptions["flags"] | undefined;
|
|
105
|
+
locals?: L | undefined;
|
|
106
|
+
}): Promise<void>;
|
|
79
107
|
}
|
|
80
108
|
|
|
109
|
+
type SetOptions<P extends Path> = {
|
|
110
|
+
method?: Method;
|
|
111
|
+
path: P;
|
|
112
|
+
query?: ConstructorParameters<typeof URLSearchParams>[0] | undefined;
|
|
113
|
+
};
|
|
114
|
+
|
|
81
115
|
declare class RouteButtonBuilder<L> extends ButtonBuilder {
|
|
82
|
-
private
|
|
116
|
+
#private;
|
|
83
117
|
/**
|
|
84
118
|
*
|
|
85
119
|
* @param embedRouter the router you want to route with
|
|
86
120
|
* @param data the data to construct a component out of
|
|
87
121
|
*/
|
|
88
|
-
constructor(embedRouter: EmbedRouter<L>, data?: Omit<Partial<APIButtonComponent>, "custom_id" | "url">);
|
|
122
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Omit<Partial<APIButtonComponent>, "custom_id" | "url"> | undefined);
|
|
89
123
|
/**
|
|
90
124
|
* Not supported for RouteButtonBuilder
|
|
91
125
|
*
|
|
@@ -105,18 +139,18 @@ declare class RouteButtonBuilder<L> extends ButtonBuilder {
|
|
|
105
139
|
*
|
|
106
140
|
* @param path the path to route to
|
|
107
141
|
* @param query any query parameters you want to add
|
|
142
|
+
* @param method method to send to route
|
|
108
143
|
*/
|
|
109
|
-
setTo<P extends Path>(
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionBuilder {
|
|
144
|
+
setTo<P extends Path>({ method, path, query }: SetOptions<P>): this;
|
|
113
145
|
/**
|
|
146
|
+
* Sets the path to route to when clicked
|
|
114
147
|
*
|
|
115
|
-
* @param
|
|
148
|
+
* @param path the path to route to
|
|
116
149
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
150
|
+
setTo<P extends Path>(path: P): this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionBuilder {
|
|
120
154
|
/**
|
|
121
155
|
* Not supported for RouteStringSelectMenuOptionBuilder (use setTo)
|
|
122
156
|
*
|
|
@@ -129,12 +163,19 @@ declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionB
|
|
|
129
163
|
*
|
|
130
164
|
* @param path the path to route to
|
|
131
165
|
* @param query any query parameters you want to add
|
|
166
|
+
* @param method method to send to route
|
|
132
167
|
*/
|
|
133
|
-
setTo<P extends Path>(
|
|
168
|
+
setTo<P extends Path>({ method, path, query }: SetOptions<P>): this;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the path to route to when clicked
|
|
171
|
+
*
|
|
172
|
+
* @param path the path to route to
|
|
173
|
+
*/
|
|
174
|
+
setTo<P extends Path>(path: P): this;
|
|
134
175
|
}
|
|
135
176
|
|
|
136
|
-
declare class RouteStringSelectMenuBuilder<L
|
|
137
|
-
private
|
|
177
|
+
declare class RouteStringSelectMenuBuilder<L> extends StringSelectMenuBuilder {
|
|
178
|
+
#private;
|
|
138
179
|
/**
|
|
139
180
|
*
|
|
140
181
|
* @param embedRouter the router you want to route with
|
|
@@ -142,7 +183,7 @@ declare class RouteStringSelectMenuBuilder<L, P extends Path> extends StringSele
|
|
|
142
183
|
* @param query any query parameters you want to add, :to will be replaced with the selected user's id
|
|
143
184
|
* @param data the data to construct a component out of
|
|
144
185
|
*/
|
|
145
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
186
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<StringSelectMenuComponentData | APIStringSelectComponent> | undefined);
|
|
146
187
|
/**
|
|
147
188
|
* Not supported for RouteStringSelectMenuBuilder (customId set from embedRouter)
|
|
148
189
|
*
|
|
@@ -176,18 +217,30 @@ declare class RouteStringSelectMenuBuilder<L, P extends Path> extends StringSele
|
|
|
176
217
|
* @param tos the list of route select menu options
|
|
177
218
|
*/
|
|
178
219
|
setTos(...tos: RestOrArray<RouteStringSelectMenuOptionBuilder | ConstructorParameters<typeof RouteStringSelectMenuOptionBuilder>[0]>): this;
|
|
220
|
+
/**
|
|
221
|
+
* Sets the pattern to redirect to (Required)
|
|
222
|
+
*
|
|
223
|
+
* @param path the path to redirect to, :to or *to in path will be replaced with the selected user's id
|
|
224
|
+
* @param query any query parameters you want to add, :to will be replaced with the selected user's id
|
|
225
|
+
* @param method method to send to route
|
|
226
|
+
*/
|
|
227
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the path to route to when clicked
|
|
230
|
+
*
|
|
231
|
+
* @param path the path to route to
|
|
232
|
+
*/
|
|
233
|
+
setPattern<P extends Path>(path: P): this;
|
|
179
234
|
}
|
|
180
235
|
|
|
181
|
-
declare class RouteChannelSelectMenuBuilder<L
|
|
182
|
-
private
|
|
236
|
+
declare class RouteChannelSelectMenuBuilder<L> extends ChannelSelectMenuBuilder {
|
|
237
|
+
#private;
|
|
183
238
|
/**
|
|
184
239
|
*
|
|
185
240
|
* @param embedRouter the router you want to route with
|
|
186
|
-
* @param path the path to redirect to, :channelId in path will be replaced with the selected user's id
|
|
187
|
-
* @param query any query parameters you want to add, :channelId will be replaced with the selected user's id
|
|
188
241
|
* @param data the data to construct a component out of
|
|
189
242
|
*/
|
|
190
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
243
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<ChannelSelectMenuComponentData | APIChannelSelectComponent> | undefined);
|
|
191
244
|
/**
|
|
192
245
|
* Not supported for RouteChannelSelectMenuBuilder (customId set from embedRouter)
|
|
193
246
|
*
|
|
@@ -195,18 +248,30 @@ declare class RouteChannelSelectMenuBuilder<L, P extends Path> extends ChannelSe
|
|
|
195
248
|
* @param
|
|
196
249
|
*/
|
|
197
250
|
setCustomId(): this;
|
|
251
|
+
/**
|
|
252
|
+
* Sets the pattern to redirect to (Required)
|
|
253
|
+
*
|
|
254
|
+
* @param path the path to redirect to, :channelId in path will be replaced with the selected user's id
|
|
255
|
+
* @param query any query parameters you want to add, :channelId will be replaced with the selected user's id
|
|
256
|
+
* @param method method to send to route
|
|
257
|
+
*/
|
|
258
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
259
|
+
/**
|
|
260
|
+
* Sets the path to route to when clicked
|
|
261
|
+
*
|
|
262
|
+
* @param path the path to route to
|
|
263
|
+
*/
|
|
264
|
+
setPattern<P extends Path>(path: P): this;
|
|
198
265
|
}
|
|
199
266
|
|
|
200
|
-
declare class RouteRoleSelectMenuBuilder<L
|
|
201
|
-
private
|
|
267
|
+
declare class RouteRoleSelectMenuBuilder<L> extends RoleSelectMenuBuilder {
|
|
268
|
+
#private;
|
|
202
269
|
/**
|
|
203
270
|
*
|
|
204
271
|
* @param embedRouter the router you want to route with
|
|
205
|
-
* @param path the path to redirect to, :roleId in path will be replaced with the selected user's id
|
|
206
|
-
* @param query any query parameters you want to add, :roleId will be replaced with the selected user's id
|
|
207
272
|
* @param data the data to construct a component out of
|
|
208
273
|
*/
|
|
209
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
274
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<RoleSelectMenuComponentData | APIRoleSelectComponent> | undefined);
|
|
210
275
|
/**
|
|
211
276
|
* Not supported for RouteRoleSelectMenuBuilder (customId set from embedRouter)
|
|
212
277
|
*
|
|
@@ -214,18 +279,30 @@ declare class RouteRoleSelectMenuBuilder<L, P extends Path> extends RoleSelectMe
|
|
|
214
279
|
* @param
|
|
215
280
|
*/
|
|
216
281
|
setCustomId(): this;
|
|
282
|
+
/**
|
|
283
|
+
* Sets the pattern to redirect to (Required)
|
|
284
|
+
*
|
|
285
|
+
* @param path the path to redirect to, :roleId in path will be replaced with the selected user's id
|
|
286
|
+
* @param query any query parameters you want to add, :roleId will be replaced with the selected user's id
|
|
287
|
+
* @param method method to send to route
|
|
288
|
+
*/
|
|
289
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
290
|
+
/**
|
|
291
|
+
* Sets the path to route to when clicked
|
|
292
|
+
*
|
|
293
|
+
* @param path the path to route to
|
|
294
|
+
*/
|
|
295
|
+
setPattern<P extends Path>(path: P): this;
|
|
217
296
|
}
|
|
218
297
|
|
|
219
|
-
declare class RouteUserSelectMenuBuilder<L
|
|
220
|
-
private
|
|
298
|
+
declare class RouteUserSelectMenuBuilder<L> extends UserSelectMenuBuilder {
|
|
299
|
+
#private;
|
|
221
300
|
/**
|
|
222
301
|
*
|
|
223
302
|
* @param embedRouter the router you want to route with
|
|
224
|
-
* @param path the path to redirect to, :userId in path will be replaced with the selected user's id
|
|
225
|
-
* @param query any query parameters you want to add, :userId will be replaced with the selected user's id
|
|
226
303
|
* @param data the data to construct a component out of
|
|
227
304
|
*/
|
|
228
|
-
constructor(embedRouter: EmbedRouter<L>,
|
|
305
|
+
constructor(embedRouter: EmbedRouter<L>, data?: Partial<UserSelectMenuComponentData | APIUserSelectComponent> | undefined);
|
|
229
306
|
/**
|
|
230
307
|
* Not supported for RouteUserSelectMenuBuilder (customId set from embedRouter)
|
|
231
308
|
*
|
|
@@ -233,6 +310,20 @@ declare class RouteUserSelectMenuBuilder<L, P extends Path> extends UserSelectMe
|
|
|
233
310
|
* @param
|
|
234
311
|
*/
|
|
235
312
|
setCustomId(): this;
|
|
313
|
+
/**
|
|
314
|
+
* Sets the pattern to redirect to (Required)
|
|
315
|
+
*
|
|
316
|
+
* @param path the path to redirect to, :userId in path will be replaced with the selected user's id
|
|
317
|
+
* @param query any query parameters you want to add, :userId will be replaced with the selected user's id
|
|
318
|
+
* @param method method to send to route
|
|
319
|
+
*/
|
|
320
|
+
setPattern<P extends Path>({ method, path, query, }: SetOptions<P>): this;
|
|
321
|
+
/**
|
|
322
|
+
* Sets the path to route to when clicked
|
|
323
|
+
*
|
|
324
|
+
* @param path the path to route to
|
|
325
|
+
*/
|
|
326
|
+
setPattern<P extends Path>(path: P): this;
|
|
236
327
|
}
|
|
237
328
|
|
|
238
|
-
export { type CompiledRoute, EmbedRouter, type
|
|
329
|
+
export { type CompiledRoute, EmbedRouter, type Method, RouteButtonBuilder, RouteChannelSelectMenuBuilder, type RouteHandler, type RouteResponse, RouteRoleSelectMenuBuilder, RouteStringSelectMenuBuilder, RouteStringSelectMenuOptionBuilder, RouteUserSelectMenuBuilder, type State };
|