discord-embed-router 0.2.3 → 0.2.5

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 CHANGED
@@ -1,13 +1,21 @@
1
1
  import { ParamData, Path, MatchFunction, MatchResult, TokenData } from 'path-to-regexp';
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';
2
+ import { InteractionEditReplyOptions, Interaction, 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 | undefined;
9
+ type RouteResponse = InteractionEditReplyOptions & ({
10
+ cleanup?: undefined;
11
+ timeout?: undefined;
12
+ } | {
13
+ cleanup: CleanupHandler;
14
+ timeout: number;
15
+ });
10
16
  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;
17
+ type CleanupHandler = () => Promise<InteractionEditReplyOptions | undefined> | InteractionEditReplyOptions | undefined;
18
+ type ApplyHandler = (options: string | InteractionEditReplyOptions) => Promise<unknown>;
11
19
  type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
12
20
  type CompiledRoute<M extends Method, L, P extends ParamData = ParamData> = {
13
21
  method: Method;
@@ -81,7 +89,7 @@ declare class EmbedRouter<L> {
81
89
  * @param routePath path of the router
82
90
  * @param embedRouter router to add at the path
83
91
  */
84
- use<P extends Path = Path>(routePath: P, embedRouter: EmbedRouter<L>): void;
92
+ use<P extends Path = Path>(routePath: P, embedRouter: EmbedRouter<Partial<L>>): void;
85
93
  /**
86
94
  * Must be attached to "interactionCreate" event for RouteButtonBuilder to work
87
95
  *
@@ -97,18 +105,15 @@ declare class EmbedRouter<L> {
97
105
  * @param flags discord flags to send with message (optional, only allowed on first reply)
98
106
  * @param locals additional info to pass in to page through state.local (optional)
99
107
  */
100
- dispatch<P extends Path = Path>({ interaction, method, path, flags, locals, }: {
101
- interaction: Interaction;
108
+ dispatch<P extends Path = Path>(interaction: Interaction, path: P, { method, flags, locals, }?: {
102
109
  method?: Method;
103
- path: P;
104
110
  flags?: InteractionReplyOptions["flags"] | undefined;
105
111
  locals?: L | undefined;
106
112
  }): Promise<void>;
107
113
  }
108
114
 
109
- type SetOptions<P extends Path> = {
110
- method?: Method;
111
- path: P;
115
+ type RouteOptions<AllowEmptyMethod extends boolean = false> = {
116
+ method?: AllowEmptyMethod extends false ? Method : Method | "";
112
117
  query?: ConstructorParameters<typeof URLSearchParams>[0] | undefined;
113
118
  };
114
119
 
@@ -137,17 +142,11 @@ declare class RouteButtonBuilder<L> extends ButtonBuilder {
137
142
  /**
138
143
  * Sets the path to route to when clicked
139
144
  *
140
- * @param path the path to route to
141
- * @param query any query parameters you want to add
145
+ * @param path the path to route to, can include :ts
146
+ * @param query any query parameters you want to add, can include :ts
142
147
  * @param method method to send to route
143
148
  */
144
- setTo<P extends Path>({ method, path, query }: SetOptions<P>): this;
145
- /**
146
- * Sets the path to route to when clicked
147
- *
148
- * @param path the path to route to
149
- */
150
- setTo<P extends Path>(path: P): this;
149
+ setTo<P extends Path>(path: P, { method, query }?: RouteOptions): this;
151
150
  }
152
151
 
153
152
  declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionBuilder {
@@ -159,19 +158,13 @@ declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionB
159
158
  */
160
159
  setValue(): this;
161
160
  /**
162
- * Sets the path to route to when clicked
161
+ * Sets the path to route to when selected
163
162
  *
164
- * @param path the path to route to
165
- * @param query any query parameters you want to add
163
+ * @param path the path to route to, can include :ts
164
+ * @param query any query parameters you want to add, can include :ts
166
165
  * @param method method to send to route
167
166
  */
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;
167
+ setTo<P extends Path>(path: P, { method, query }?: RouteOptions<true>): this;
175
168
  }
176
169
 
177
170
  declare class RouteStringSelectMenuBuilder<L> extends StringSelectMenuBuilder {
@@ -220,17 +213,11 @@ declare class RouteStringSelectMenuBuilder<L> extends StringSelectMenuBuilder {
220
213
  /**
221
214
  * Sets the pattern to redirect to (Required)
222
215
  *
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
216
+ * @param path the path to redirect to, can include :ts :to *to
217
+ * @param query any query parameters you want to add, can include :ts :to *to
225
218
  * @param method method to send to route
226
219
  */
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;
220
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
234
221
  }
235
222
 
236
223
  declare class RouteChannelSelectMenuBuilder<L> extends ChannelSelectMenuBuilder {
@@ -251,17 +238,11 @@ declare class RouteChannelSelectMenuBuilder<L> extends ChannelSelectMenuBuilder
251
238
  /**
252
239
  * Sets the pattern to redirect to (Required)
253
240
  *
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
241
+ * @param path the path to redirect to, can include :ts :channelId
242
+ * @param query any query parameters you want to add, can include :ts :channelId
256
243
  * @param method method to send to route
257
244
  */
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;
245
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
265
246
  }
266
247
 
267
248
  declare class RouteRoleSelectMenuBuilder<L> extends RoleSelectMenuBuilder {
@@ -282,17 +263,11 @@ declare class RouteRoleSelectMenuBuilder<L> extends RoleSelectMenuBuilder {
282
263
  /**
283
264
  * Sets the pattern to redirect to (Required)
284
265
  *
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
266
+ * @param path the path to redirect to, can include :ts :roleId
267
+ * @param query any query parameters you want to add, can include :ts :roleId
287
268
  * @param method method to send to route
288
269
  */
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;
270
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
296
271
  }
297
272
 
298
273
  declare class RouteUserSelectMenuBuilder<L> extends UserSelectMenuBuilder {
@@ -313,17 +288,11 @@ declare class RouteUserSelectMenuBuilder<L> extends UserSelectMenuBuilder {
313
288
  /**
314
289
  * Sets the pattern to redirect to (Required)
315
290
  *
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
291
+ * @param path the path to redirect to, can include :ts :userId
292
+ * @param query any query parameters you want to add, can include :ts :userId
318
293
  * @param method method to send to route
319
294
  */
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;
295
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
327
296
  }
328
297
 
329
- export { type CompiledRoute, EmbedRouter, type Method, RouteButtonBuilder, RouteChannelSelectMenuBuilder, type RouteHandler, type RouteResponse, RouteRoleSelectMenuBuilder, RouteStringSelectMenuBuilder, RouteStringSelectMenuOptionBuilder, RouteUserSelectMenuBuilder, type State };
298
+ export { type ApplyHandler, type CleanupHandler, type CompiledRoute, EmbedRouter, type Method, RouteButtonBuilder, RouteChannelSelectMenuBuilder, type RouteHandler, type RouteResponse, RouteRoleSelectMenuBuilder, RouteStringSelectMenuBuilder, RouteStringSelectMenuOptionBuilder, RouteUserSelectMenuBuilder, type State };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,21 @@
1
1
  import { ParamData, Path, MatchFunction, MatchResult, TokenData } from 'path-to-regexp';
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';
2
+ import { InteractionEditReplyOptions, Interaction, 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 | undefined;
9
+ type RouteResponse = InteractionEditReplyOptions & ({
10
+ cleanup?: undefined;
11
+ timeout?: undefined;
12
+ } | {
13
+ cleanup: CleanupHandler;
14
+ timeout: number;
15
+ });
10
16
  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;
17
+ type CleanupHandler = () => Promise<InteractionEditReplyOptions | undefined> | InteractionEditReplyOptions | undefined;
18
+ type ApplyHandler = (options: string | InteractionEditReplyOptions) => Promise<unknown>;
11
19
  type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
12
20
  type CompiledRoute<M extends Method, L, P extends ParamData = ParamData> = {
13
21
  method: Method;
@@ -81,7 +89,7 @@ declare class EmbedRouter<L> {
81
89
  * @param routePath path of the router
82
90
  * @param embedRouter router to add at the path
83
91
  */
84
- use<P extends Path = Path>(routePath: P, embedRouter: EmbedRouter<L>): void;
92
+ use<P extends Path = Path>(routePath: P, embedRouter: EmbedRouter<Partial<L>>): void;
85
93
  /**
86
94
  * Must be attached to "interactionCreate" event for RouteButtonBuilder to work
87
95
  *
@@ -97,18 +105,15 @@ declare class EmbedRouter<L> {
97
105
  * @param flags discord flags to send with message (optional, only allowed on first reply)
98
106
  * @param locals additional info to pass in to page through state.local (optional)
99
107
  */
100
- dispatch<P extends Path = Path>({ interaction, method, path, flags, locals, }: {
101
- interaction: Interaction;
108
+ dispatch<P extends Path = Path>(interaction: Interaction, path: P, { method, flags, locals, }?: {
102
109
  method?: Method;
103
- path: P;
104
110
  flags?: InteractionReplyOptions["flags"] | undefined;
105
111
  locals?: L | undefined;
106
112
  }): Promise<void>;
107
113
  }
108
114
 
109
- type SetOptions<P extends Path> = {
110
- method?: Method;
111
- path: P;
115
+ type RouteOptions<AllowEmptyMethod extends boolean = false> = {
116
+ method?: AllowEmptyMethod extends false ? Method : Method | "";
112
117
  query?: ConstructorParameters<typeof URLSearchParams>[0] | undefined;
113
118
  };
114
119
 
@@ -137,17 +142,11 @@ declare class RouteButtonBuilder<L> extends ButtonBuilder {
137
142
  /**
138
143
  * Sets the path to route to when clicked
139
144
  *
140
- * @param path the path to route to
141
- * @param query any query parameters you want to add
145
+ * @param path the path to route to, can include :ts
146
+ * @param query any query parameters you want to add, can include :ts
142
147
  * @param method method to send to route
143
148
  */
144
- setTo<P extends Path>({ method, path, query }: SetOptions<P>): this;
145
- /**
146
- * Sets the path to route to when clicked
147
- *
148
- * @param path the path to route to
149
- */
150
- setTo<P extends Path>(path: P): this;
149
+ setTo<P extends Path>(path: P, { method, query }?: RouteOptions): this;
151
150
  }
152
151
 
153
152
  declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionBuilder {
@@ -159,19 +158,13 @@ declare class RouteStringSelectMenuOptionBuilder extends StringSelectMenuOptionB
159
158
  */
160
159
  setValue(): this;
161
160
  /**
162
- * Sets the path to route to when clicked
161
+ * Sets the path to route to when selected
163
162
  *
164
- * @param path the path to route to
165
- * @param query any query parameters you want to add
163
+ * @param path the path to route to, can include :ts
164
+ * @param query any query parameters you want to add, can include :ts
166
165
  * @param method method to send to route
167
166
  */
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;
167
+ setTo<P extends Path>(path: P, { method, query }?: RouteOptions<true>): this;
175
168
  }
176
169
 
177
170
  declare class RouteStringSelectMenuBuilder<L> extends StringSelectMenuBuilder {
@@ -220,17 +213,11 @@ declare class RouteStringSelectMenuBuilder<L> extends StringSelectMenuBuilder {
220
213
  /**
221
214
  * Sets the pattern to redirect to (Required)
222
215
  *
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
216
+ * @param path the path to redirect to, can include :ts :to *to
217
+ * @param query any query parameters you want to add, can include :ts :to *to
225
218
  * @param method method to send to route
226
219
  */
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;
220
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
234
221
  }
235
222
 
236
223
  declare class RouteChannelSelectMenuBuilder<L> extends ChannelSelectMenuBuilder {
@@ -251,17 +238,11 @@ declare class RouteChannelSelectMenuBuilder<L> extends ChannelSelectMenuBuilder
251
238
  /**
252
239
  * Sets the pattern to redirect to (Required)
253
240
  *
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
241
+ * @param path the path to redirect to, can include :ts :channelId
242
+ * @param query any query parameters you want to add, can include :ts :channelId
256
243
  * @param method method to send to route
257
244
  */
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;
245
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
265
246
  }
266
247
 
267
248
  declare class RouteRoleSelectMenuBuilder<L> extends RoleSelectMenuBuilder {
@@ -282,17 +263,11 @@ declare class RouteRoleSelectMenuBuilder<L> extends RoleSelectMenuBuilder {
282
263
  /**
283
264
  * Sets the pattern to redirect to (Required)
284
265
  *
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
266
+ * @param path the path to redirect to, can include :ts :roleId
267
+ * @param query any query parameters you want to add, can include :ts :roleId
287
268
  * @param method method to send to route
288
269
  */
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;
270
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
296
271
  }
297
272
 
298
273
  declare class RouteUserSelectMenuBuilder<L> extends UserSelectMenuBuilder {
@@ -313,17 +288,11 @@ declare class RouteUserSelectMenuBuilder<L> extends UserSelectMenuBuilder {
313
288
  /**
314
289
  * Sets the pattern to redirect to (Required)
315
290
  *
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
291
+ * @param path the path to redirect to, can include :ts :userId
292
+ * @param query any query parameters you want to add, can include :ts :userId
318
293
  * @param method method to send to route
319
294
  */
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;
295
+ setPattern<P extends Path>(path: P, { method, query }?: RouteOptions): this;
327
296
  }
328
297
 
329
- export { type CompiledRoute, EmbedRouter, type Method, RouteButtonBuilder, RouteChannelSelectMenuBuilder, type RouteHandler, type RouteResponse, RouteRoleSelectMenuBuilder, RouteStringSelectMenuBuilder, RouteStringSelectMenuOptionBuilder, RouteUserSelectMenuBuilder, type State };
298
+ export { type ApplyHandler, type CleanupHandler, type CompiledRoute, EmbedRouter, type Method, RouteButtonBuilder, RouteChannelSelectMenuBuilder, type RouteHandler, type RouteResponse, RouteRoleSelectMenuBuilder, RouteStringSelectMenuBuilder, RouteStringSelectMenuOptionBuilder, RouteUserSelectMenuBuilder, type State };