discord-embed-router 0.1.0 → 0.2.2
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/README.md +1 -1
- package/dist/index.d.mts +260 -25
- package/dist/index.d.ts +260 -25
- package/dist/index.js +517 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +519 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,17 +31,40 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
EmbedRouter: () => EmbedRouter,
|
|
34
|
-
RouteButtonBuilder: () => RouteButtonBuilder
|
|
34
|
+
RouteButtonBuilder: () => RouteButtonBuilder,
|
|
35
|
+
RouteChannelSelectMenuBuilder: () => RouteChannelSelectMenuBuilder,
|
|
36
|
+
RouteRoleSelectMenuBuilder: () => RouteRoleSelectMenuBuilder,
|
|
37
|
+
RouteStringSelectMenuBuilder: () => RouteStringSelectMenuBuilder,
|
|
38
|
+
RouteStringSelectMenuOptionBuilder: () => RouteStringSelectMenuOptionBuilder,
|
|
39
|
+
RouteUserSelectMenuBuilder: () => RouteUserSelectMenuBuilder
|
|
35
40
|
});
|
|
36
41
|
module.exports = __toCommonJS(index_exports);
|
|
37
42
|
|
|
38
43
|
// src/EmbedRouter.ts
|
|
39
44
|
var import_node_path = __toESM(require("path"));
|
|
40
|
-
var
|
|
45
|
+
var import_node_crypto = require("crypto");
|
|
46
|
+
var import_path_to_regexp3 = require("path-to-regexp");
|
|
41
47
|
|
|
42
48
|
// src/consts.ts
|
|
43
49
|
var ID_PREFIX = "der";
|
|
44
|
-
var
|
|
50
|
+
var METHOD_TO_ENCODING = {
|
|
51
|
+
GET: "G",
|
|
52
|
+
POST: "P",
|
|
53
|
+
PUT: "U",
|
|
54
|
+
PATCH: "A",
|
|
55
|
+
DELETE: "D"
|
|
56
|
+
};
|
|
57
|
+
var ENCODING_TO_METHOD = {
|
|
58
|
+
G: "GET",
|
|
59
|
+
P: "POST",
|
|
60
|
+
U: "PUT",
|
|
61
|
+
A: "PATCH",
|
|
62
|
+
D: "DELETE"
|
|
63
|
+
};
|
|
64
|
+
var BASE_URL = "discord://embed.router";
|
|
65
|
+
var PUA_START = 57344;
|
|
66
|
+
var PUA_END = 63743;
|
|
67
|
+
var PUA_RANGE = PUA_END - PUA_START + 1;
|
|
45
68
|
|
|
46
69
|
// src/helpers/pathToString.ts
|
|
47
70
|
var import_path_to_regexp = require("path-to-regexp");
|
|
@@ -52,36 +75,127 @@ var pathToString = (path2, checkValidity = true) => {
|
|
|
52
75
|
return typeof path2 === "string" ? path2 : (0, import_path_to_regexp.stringify)(path2);
|
|
53
76
|
};
|
|
54
77
|
|
|
78
|
+
// src/helpers/decodePath.ts
|
|
79
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
80
|
+
var decodePath = ({
|
|
81
|
+
idPrefix,
|
|
82
|
+
interaction
|
|
83
|
+
}) => {
|
|
84
|
+
const customId = interaction.customId;
|
|
85
|
+
if (!customId.startsWith(idPrefix)) return false;
|
|
86
|
+
if (interaction.isButton()) {
|
|
87
|
+
return parseMethodAndPath(customId.slice(idPrefix.length));
|
|
88
|
+
} else if (interaction.isAnySelectMenu()) {
|
|
89
|
+
if (interaction.values.length === 0) return false;
|
|
90
|
+
const res = parseMethodAndPath(customId.slice(idPrefix.length));
|
|
91
|
+
if (!res) return false;
|
|
92
|
+
const { method, path: path2 } = res;
|
|
93
|
+
return {
|
|
94
|
+
method,
|
|
95
|
+
path: fillParams(path2, {
|
|
96
|
+
[interaction.isStringSelectMenu() ? "to" : interaction.isChannelSelectMenu() ? "channelId" : interaction.isRoleSelectMenu() ? "roleId" : "userId"]: interaction.values[0].split("/").slice(1)
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
var parseMethodAndPath = (pathWithMethod) => {
|
|
103
|
+
const firstSlash = pathWithMethod.indexOf("/");
|
|
104
|
+
if (firstSlash <= 0) return false;
|
|
105
|
+
const method = ENCODING_TO_METHOD[pathWithMethod.slice(0, firstSlash)];
|
|
106
|
+
if (method === void 0) return false;
|
|
107
|
+
return {
|
|
108
|
+
method,
|
|
109
|
+
path: pathWithMethod.slice(firstSlash)
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
var fillParams = (path2, params = {}) => {
|
|
113
|
+
const url = new URL(path2, BASE_URL);
|
|
114
|
+
const toPath = (0, import_path_to_regexp2.compile)(url.pathname);
|
|
115
|
+
url.pathname = toPath(params);
|
|
116
|
+
for (const [key, value] of url.searchParams) {
|
|
117
|
+
if (value.startsWith(":") && key.slice(1) in params) {
|
|
118
|
+
const paramValue = params?.[key.slice(1)];
|
|
119
|
+
if (paramValue) {
|
|
120
|
+
url.searchParams.set(
|
|
121
|
+
key,
|
|
122
|
+
Array.isArray(paramValue) ? paramValue.join("/") : paramValue
|
|
123
|
+
);
|
|
124
|
+
} else {
|
|
125
|
+
url.searchParams.delete(key);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return `${url.pathname}${url.search}`;
|
|
130
|
+
};
|
|
131
|
+
|
|
55
132
|
// src/EmbedRouter.ts
|
|
56
133
|
var EmbedRouter = class _EmbedRouter {
|
|
57
|
-
|
|
58
|
-
static
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
let char;
|
|
62
|
-
do {
|
|
63
|
-
const codepoint = PUA_START + Math.floor(Math.random() * (PUA_END - PUA_START + 1));
|
|
64
|
-
char = String.fromCodePoint(codepoint);
|
|
65
|
-
} while (_EmbedRouter.usedIdentifiers.has(char));
|
|
66
|
-
_EmbedRouter.usedIdentifiers.add(char);
|
|
67
|
-
return char;
|
|
68
|
-
}
|
|
134
|
+
// identifier -> embedRouter
|
|
135
|
+
static #usedIdentifiers = /* @__PURE__ */ new Map();
|
|
136
|
+
// Name used to generate prefixes
|
|
137
|
+
#name = "";
|
|
69
138
|
// Prefix for customIds of RouteButtonBuilders
|
|
70
|
-
idPrefix;
|
|
139
|
+
#idPrefix;
|
|
140
|
+
#identifier = "";
|
|
71
141
|
getIdPrefix() {
|
|
72
|
-
return this
|
|
142
|
+
return `${this.#idPrefix}${this.#identifier}`;
|
|
73
143
|
}
|
|
74
144
|
// All added routes
|
|
75
|
-
routes =
|
|
145
|
+
#routes = /* @__PURE__ */ new Map();
|
|
76
146
|
/**
|
|
77
147
|
*
|
|
148
|
+
* @param name the name to give the router. ensures buttons stay connected across restarts
|
|
78
149
|
* @param idPrefix the prefix for RouteButtonBuilder customIds
|
|
79
150
|
*/
|
|
80
|
-
constructor(
|
|
151
|
+
constructor({
|
|
152
|
+
name = "",
|
|
153
|
+
idPrefix = ID_PREFIX
|
|
154
|
+
} = {}) {
|
|
155
|
+
if (_EmbedRouter.#usedIdentifiers.size >= PUA_RANGE) {
|
|
156
|
+
throw new Error(`You can not have more than ${PUA_RANGE} routers`);
|
|
157
|
+
}
|
|
81
158
|
if (idPrefix.includes("/")) {
|
|
82
159
|
throw new Error(`Prefix can't contain "/": ${idPrefix}`);
|
|
83
160
|
}
|
|
84
|
-
this
|
|
161
|
+
this.#idPrefix = idPrefix;
|
|
162
|
+
this.#name = name;
|
|
163
|
+
this.#updateIdentifier();
|
|
164
|
+
}
|
|
165
|
+
#updateIdentifier() {
|
|
166
|
+
const hash = (0, import_node_crypto.createHash)("sha256").update(this.#name).digest();
|
|
167
|
+
let raw = hash.readUint32BE(0);
|
|
168
|
+
let char;
|
|
169
|
+
const nameCollisions = [];
|
|
170
|
+
while (true) {
|
|
171
|
+
const codepoint = PUA_START + raw++ % PUA_RANGE;
|
|
172
|
+
char = String.fromCodePoint(codepoint);
|
|
173
|
+
const collisionRouter = _EmbedRouter.#usedIdentifiers.get(char);
|
|
174
|
+
if (collisionRouter === void 0) break;
|
|
175
|
+
if (this.#name.length > 0 && collisionRouter.#name.length === 0) {
|
|
176
|
+
collisionRouter.#updateIdentifier();
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
nameCollisions.push(collisionRouter);
|
|
180
|
+
}
|
|
181
|
+
_EmbedRouter.#usedIdentifiers.set(char, this);
|
|
182
|
+
if (nameCollisions.length > 0 && this.#name.length > 0) {
|
|
183
|
+
process.emitWarning(
|
|
184
|
+
`EmbedRouter identifier collision for name "${this.#name}" with ${nameCollisions.map((c) => `"${c.#name}"`).join(", ")}`,
|
|
185
|
+
"EmbedRouterWarning"
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
this.#identifier = char;
|
|
189
|
+
}
|
|
190
|
+
#addRoute(method, routePath, handler) {
|
|
191
|
+
const methodRoutes = this.#routes.get(method) ?? [];
|
|
192
|
+
methodRoutes.push({
|
|
193
|
+
method,
|
|
194
|
+
path: Array.isArray(routePath) ? routePath : [routePath],
|
|
195
|
+
matchFunction: (0, import_path_to_regexp3.match)(routePath),
|
|
196
|
+
handler
|
|
197
|
+
});
|
|
198
|
+
this.#routes.set(method, methodRoutes);
|
|
85
199
|
}
|
|
86
200
|
/**
|
|
87
201
|
* Registers a path with the router
|
|
@@ -89,12 +203,44 @@ var EmbedRouter = class _EmbedRouter {
|
|
|
89
203
|
* @param routePath path to match with
|
|
90
204
|
* @param handler function that generates the message when a path is matched
|
|
91
205
|
*/
|
|
92
|
-
|
|
93
|
-
this
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
206
|
+
get(routePath, handler) {
|
|
207
|
+
this.#addRoute("GET", routePath, handler);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Registers a path with the router
|
|
211
|
+
*
|
|
212
|
+
* @param routePath path to match with
|
|
213
|
+
* @param handler function that generates the message when a path is matched
|
|
214
|
+
*/
|
|
215
|
+
post(routePath, handler) {
|
|
216
|
+
this.#addRoute("POST", routePath, handler);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Registers a path with the router
|
|
220
|
+
*
|
|
221
|
+
* @param routePath path to match with
|
|
222
|
+
* @param handler function that generates the message when a path is matched
|
|
223
|
+
*/
|
|
224
|
+
put(routePath, handler) {
|
|
225
|
+
this.#addRoute("PUT", routePath, handler);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Registers a path with the router
|
|
229
|
+
*
|
|
230
|
+
* @param routePath path to match with
|
|
231
|
+
* @param handler function that generates the message when a path is matched
|
|
232
|
+
*/
|
|
233
|
+
patch(routePath, handler) {
|
|
234
|
+
this.#addRoute("PATCH", routePath, handler);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Registers a path with the router
|
|
238
|
+
*
|
|
239
|
+
* @param routePath path to match with
|
|
240
|
+
* @param handler function that generates the message when a path is matched
|
|
241
|
+
*/
|
|
242
|
+
delete(routePath, handler) {
|
|
243
|
+
this.#addRoute("DELETE", routePath, handler);
|
|
98
244
|
}
|
|
99
245
|
/**
|
|
100
246
|
* Adds a subrouter to the router
|
|
@@ -104,11 +250,14 @@ var EmbedRouter = class _EmbedRouter {
|
|
|
104
250
|
*/
|
|
105
251
|
use(routePath, embedRouter) {
|
|
106
252
|
const pathString = pathToString(routePath);
|
|
107
|
-
for (const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
253
|
+
for (const [method, routes] of embedRouter.#routes) {
|
|
254
|
+
for (const route of routes) {
|
|
255
|
+
this.#addRoute(
|
|
256
|
+
method,
|
|
257
|
+
route.path.map((p) => import_node_path.default.posix.join(pathString, pathToString(p))),
|
|
258
|
+
route.handler
|
|
259
|
+
);
|
|
260
|
+
}
|
|
112
261
|
}
|
|
113
262
|
}
|
|
114
263
|
/**
|
|
@@ -116,30 +265,36 @@ var EmbedRouter = class _EmbedRouter {
|
|
|
116
265
|
*
|
|
117
266
|
* @param interaction interactions from "interactionCreate" (filter for ButtonInteractions)
|
|
118
267
|
*/
|
|
119
|
-
async listener(interaction) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.dispatch(interaction, path2);
|
|
268
|
+
async listener(interaction, locals) {
|
|
269
|
+
const res = decodePath({ idPrefix: this.getIdPrefix(), interaction });
|
|
270
|
+
if (!res)
|
|
271
|
+
throw new Error(`Invalid component found: id ${interaction.customId}`);
|
|
272
|
+
this.dispatch({ interaction, method: res.method, path: res.path, locals });
|
|
125
273
|
}
|
|
126
274
|
/**
|
|
127
275
|
* Connect or update an interaction message to a path
|
|
128
276
|
*
|
|
129
277
|
* @param interaction interaction to connect to
|
|
130
278
|
* @param path path to route the interaction to
|
|
279
|
+
* @param method method to send to route
|
|
131
280
|
* @param flags optional discord flags to send with message (only allowed on first reply)
|
|
132
281
|
*/
|
|
133
|
-
async dispatch(
|
|
282
|
+
async dispatch({
|
|
283
|
+
interaction,
|
|
284
|
+
method = "GET",
|
|
285
|
+
path: path2,
|
|
286
|
+
flags,
|
|
287
|
+
locals
|
|
288
|
+
}) {
|
|
134
289
|
if (interaction.isAutocomplete())
|
|
135
290
|
throw new Error("Autocomplete Interactions aren't supported");
|
|
136
|
-
const resolvedRoute = this
|
|
291
|
+
const resolvedRoute = this.#resolve(method, pathToString(path2, false));
|
|
137
292
|
if (!resolvedRoute)
|
|
138
293
|
throw new Error(`No route found for ${pathToString(path2, false)}`);
|
|
139
|
-
const routeResponse = resolvedRoute.handler(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
294
|
+
const routeResponse = await resolvedRoute.handler(interaction, {
|
|
295
|
+
...resolvedRoute.state,
|
|
296
|
+
locals
|
|
297
|
+
});
|
|
143
298
|
if (interaction.replied || interaction.deferred) {
|
|
144
299
|
if (flags)
|
|
145
300
|
throw new Error(
|
|
@@ -159,27 +314,61 @@ var EmbedRouter = class _EmbedRouter {
|
|
|
159
314
|
});
|
|
160
315
|
}
|
|
161
316
|
}
|
|
162
|
-
resolve(routePath) {
|
|
317
|
+
#resolve(method, routePath) {
|
|
163
318
|
const url = new URL(routePath, BASE_URL);
|
|
164
|
-
for (const route of this.
|
|
319
|
+
for (const route of this.#routes.get(method) ?? []) {
|
|
165
320
|
const result = route.matchFunction(url.pathname);
|
|
166
321
|
if (result) {
|
|
167
322
|
return {
|
|
168
323
|
state: {
|
|
169
324
|
...result,
|
|
170
|
-
|
|
325
|
+
query: url.searchParams,
|
|
326
|
+
embedRouter: this
|
|
171
327
|
},
|
|
172
328
|
handler: route.handler
|
|
173
329
|
};
|
|
174
330
|
}
|
|
175
331
|
}
|
|
176
|
-
return
|
|
332
|
+
return false;
|
|
177
333
|
}
|
|
178
334
|
};
|
|
179
335
|
|
|
180
|
-
// src/RouteButtonBuilder.ts
|
|
336
|
+
// src/componentBuilders/RouteButtonBuilder.ts
|
|
181
337
|
var import_discord = require("discord.js");
|
|
338
|
+
|
|
339
|
+
// src/helpers/encodePath.ts
|
|
340
|
+
var encodePath = ({
|
|
341
|
+
idPrefix,
|
|
342
|
+
method,
|
|
343
|
+
path: path2,
|
|
344
|
+
query
|
|
345
|
+
}) => {
|
|
346
|
+
const url = new URL(pathToString(path2), BASE_URL);
|
|
347
|
+
if (query) {
|
|
348
|
+
for (const [key, value] of new URLSearchParams(query)) {
|
|
349
|
+
url.searchParams.set(key, value);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return `${idPrefix}${METHOD_TO_ENCODING[method]}${url.pathname}${url.search}`;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/types/componentBuilders.ts
|
|
356
|
+
var isSetOptions = (u) => {
|
|
357
|
+
return typeof u === "object" && u !== null && (!("method" in u) || "method" in u && typeof u.method === "string" || u.method === void 0) && "path" in u && typeof u.path === "string" && (!("query" in u) || "query" in u && typeof u.query in ["object", "string"] || u.query === void 0);
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// src/componentBuilders/RouteButtonBuilder.ts
|
|
182
361
|
var RouteButtonBuilder = class extends import_discord.ButtonBuilder {
|
|
362
|
+
#embedRouter;
|
|
363
|
+
/**
|
|
364
|
+
*
|
|
365
|
+
* @param embedRouter the router you want to route with
|
|
366
|
+
* @param data the data to construct a component out of
|
|
367
|
+
*/
|
|
368
|
+
constructor(embedRouter, data) {
|
|
369
|
+
super(data);
|
|
370
|
+
this.#embedRouter = embedRouter;
|
|
371
|
+
}
|
|
183
372
|
/**
|
|
184
373
|
* Not supported for RouteButtonBuilder
|
|
185
374
|
*
|
|
@@ -190,7 +379,7 @@ var RouteButtonBuilder = class extends import_discord.ButtonBuilder {
|
|
|
190
379
|
throw new Error("setURL is not supported on RouteButtonBuilder");
|
|
191
380
|
}
|
|
192
381
|
/**
|
|
193
|
-
* Not supported for RouteButtonBuilder (setTo
|
|
382
|
+
* Not supported for RouteButtonBuilder (use setTo)
|
|
194
383
|
*
|
|
195
384
|
* @remarks
|
|
196
385
|
* @param
|
|
@@ -198,22 +387,292 @@ var RouteButtonBuilder = class extends import_discord.ButtonBuilder {
|
|
|
198
387
|
setCustomId() {
|
|
199
388
|
throw new Error("setCustomId is not supported on RouteButtonBuilder");
|
|
200
389
|
}
|
|
390
|
+
setTo(arg) {
|
|
391
|
+
const {
|
|
392
|
+
method = "GET",
|
|
393
|
+
path: path2,
|
|
394
|
+
query
|
|
395
|
+
} = isSetOptions(arg) ? arg : { path: arg };
|
|
396
|
+
super.setCustomId(
|
|
397
|
+
encodePath({
|
|
398
|
+
idPrefix: this.#embedRouter.getIdPrefix(),
|
|
399
|
+
method,
|
|
400
|
+
path: path2,
|
|
401
|
+
query
|
|
402
|
+
})
|
|
403
|
+
);
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// src/componentBuilders/RouteStringSelectMenuBuilder.ts
|
|
409
|
+
var import_discord3 = require("discord.js");
|
|
410
|
+
|
|
411
|
+
// src/componentBuilders/RouteStringMenuOptionBuilder.ts
|
|
412
|
+
var import_discord2 = require("discord.js");
|
|
413
|
+
var RouteStringSelectMenuOptionBuilder = class extends import_discord2.StringSelectMenuOptionBuilder {
|
|
414
|
+
/**
|
|
415
|
+
* Not supported for RouteStringSelectMenuOptionBuilder (use setTo)
|
|
416
|
+
*
|
|
417
|
+
* @remarks
|
|
418
|
+
* @param
|
|
419
|
+
*/
|
|
420
|
+
setValue() {
|
|
421
|
+
throw new Error(
|
|
422
|
+
"setValue is not supported on RouteStringSelectMenuOptionBuilder"
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
setTo(arg) {
|
|
426
|
+
const {
|
|
427
|
+
method = "GET",
|
|
428
|
+
path: path2,
|
|
429
|
+
query
|
|
430
|
+
} = isSetOptions(arg) ? arg : { path: arg };
|
|
431
|
+
super.setValue(
|
|
432
|
+
encodePath({
|
|
433
|
+
idPrefix: "",
|
|
434
|
+
method,
|
|
435
|
+
path: path2,
|
|
436
|
+
query
|
|
437
|
+
})
|
|
438
|
+
);
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/componentBuilders/RouteStringSelectMenuBuilder.ts
|
|
444
|
+
var RouteStringSelectMenuBuilder = class extends import_discord3.StringSelectMenuBuilder {
|
|
445
|
+
#embedRouter;
|
|
446
|
+
/**
|
|
447
|
+
*
|
|
448
|
+
* @param embedRouter the router you want to route with
|
|
449
|
+
* @param path the path to redirect to, :to or *to in path will be replaced with the selected user's id
|
|
450
|
+
* @param query any query parameters you want to add, :to will be replaced with the selected user's id
|
|
451
|
+
* @param data the data to construct a component out of
|
|
452
|
+
*/
|
|
453
|
+
constructor(embedRouter, data) {
|
|
454
|
+
super(data);
|
|
455
|
+
this.#embedRouter = embedRouter;
|
|
456
|
+
super.setCustomId(
|
|
457
|
+
encodePath({
|
|
458
|
+
idPrefix: this.#embedRouter.getIdPrefix(),
|
|
459
|
+
method: "GET",
|
|
460
|
+
path: "/*to"
|
|
461
|
+
})
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Not supported for RouteStringSelectMenuBuilder (customId set from embedRouter)
|
|
466
|
+
*
|
|
467
|
+
* @remarks
|
|
468
|
+
* @param
|
|
469
|
+
*/
|
|
470
|
+
setCustomId() {
|
|
471
|
+
throw new Error(
|
|
472
|
+
"setCustomId is not supported on RouteStringSelectMenuBuilder"
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Not supported for RouteStringSelectMenuBuilder (use addTos)
|
|
477
|
+
*
|
|
478
|
+
* @remarks
|
|
479
|
+
* @param
|
|
480
|
+
*/
|
|
481
|
+
addOptions() {
|
|
482
|
+
throw new Error(
|
|
483
|
+
"addOptions is not supported on RouteStringSelectMenuBuilder"
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Not supported for RouteStringSelectMenuBuilder (use setTos)
|
|
488
|
+
*
|
|
489
|
+
* @remarks
|
|
490
|
+
* @param
|
|
491
|
+
*/
|
|
492
|
+
setOptions() {
|
|
493
|
+
throw new Error(
|
|
494
|
+
"setOptions is not supported on RouteStringSelectMenuBuilder"
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Adds route select menu options to builder
|
|
499
|
+
*
|
|
500
|
+
* @param tos the list of route select menu options
|
|
501
|
+
*/
|
|
502
|
+
addTos(...tos) {
|
|
503
|
+
const resolved = (0, import_discord3.normalizeArray)(tos);
|
|
504
|
+
super.addOptions(
|
|
505
|
+
resolved.map(
|
|
506
|
+
(o) => o instanceof RouteStringSelectMenuOptionBuilder ? o : new RouteStringSelectMenuOptionBuilder(o)
|
|
507
|
+
)
|
|
508
|
+
);
|
|
509
|
+
return this;
|
|
510
|
+
}
|
|
201
511
|
/**
|
|
202
|
-
* Sets
|
|
512
|
+
* Sets route select menu options to builder
|
|
203
513
|
*
|
|
204
|
-
* @param
|
|
205
|
-
* @param idPrefix the prefix to add before the custom_id
|
|
514
|
+
* @param tos the list of route select menu options
|
|
206
515
|
*/
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
516
|
+
setTos(...tos) {
|
|
517
|
+
const resolved = (0, import_discord3.normalizeArray)(tos);
|
|
518
|
+
super.setOptions(
|
|
519
|
+
resolved.map(
|
|
520
|
+
(o) => o instanceof RouteStringSelectMenuOptionBuilder ? o : new RouteStringSelectMenuOptionBuilder(o)
|
|
521
|
+
)
|
|
522
|
+
);
|
|
523
|
+
return this;
|
|
524
|
+
}
|
|
525
|
+
setPattern(arg) {
|
|
526
|
+
const {
|
|
527
|
+
method = "GET",
|
|
528
|
+
path: path2,
|
|
529
|
+
query
|
|
530
|
+
} = isSetOptions(arg) ? arg : { path: arg };
|
|
531
|
+
super.setCustomId(
|
|
532
|
+
encodePath({
|
|
533
|
+
idPrefix: this.#embedRouter.getIdPrefix(),
|
|
534
|
+
method,
|
|
535
|
+
path: path2,
|
|
536
|
+
query
|
|
537
|
+
})
|
|
538
|
+
);
|
|
539
|
+
return this;
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// src/componentBuilders/RouteChannelSelectMenuBuilder.ts
|
|
544
|
+
var import_discord4 = require("discord.js");
|
|
545
|
+
var RouteChannelSelectMenuBuilder = class extends import_discord4.ChannelSelectMenuBuilder {
|
|
546
|
+
#embedRouter;
|
|
547
|
+
/**
|
|
548
|
+
*
|
|
549
|
+
* @param embedRouter the router you want to route with
|
|
550
|
+
* @param data the data to construct a component out of
|
|
551
|
+
*/
|
|
552
|
+
constructor(embedRouter, data) {
|
|
553
|
+
super(data);
|
|
554
|
+
this.#embedRouter = embedRouter;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Not supported for RouteChannelSelectMenuBuilder (customId set from embedRouter)
|
|
558
|
+
*
|
|
559
|
+
* @remarks
|
|
560
|
+
* @param
|
|
561
|
+
*/
|
|
562
|
+
setCustomId() {
|
|
563
|
+
throw new Error(
|
|
564
|
+
"setCustomId is not supported on RouteChannelSelectMenuBuilder"
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
setPattern(arg) {
|
|
568
|
+
const {
|
|
569
|
+
method = "GET",
|
|
570
|
+
path: path2,
|
|
571
|
+
query
|
|
572
|
+
} = isSetOptions(arg) ? arg : { path: arg };
|
|
573
|
+
super.setCustomId(
|
|
574
|
+
encodePath({
|
|
575
|
+
idPrefix: this.#embedRouter.getIdPrefix(),
|
|
576
|
+
method,
|
|
577
|
+
path: path2,
|
|
578
|
+
query
|
|
579
|
+
})
|
|
580
|
+
);
|
|
581
|
+
return this;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/componentBuilders/RouteRoleSelectMenuBuilder.ts
|
|
586
|
+
var import_discord5 = require("discord.js");
|
|
587
|
+
var RouteRoleSelectMenuBuilder = class extends import_discord5.RoleSelectMenuBuilder {
|
|
588
|
+
#embedRouter;
|
|
589
|
+
/**
|
|
590
|
+
*
|
|
591
|
+
* @param embedRouter the router you want to route with
|
|
592
|
+
* @param data the data to construct a component out of
|
|
593
|
+
*/
|
|
594
|
+
constructor(embedRouter, data) {
|
|
595
|
+
super(data);
|
|
596
|
+
this.#embedRouter = embedRouter;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Not supported for RouteRoleSelectMenuBuilder (customId set from embedRouter)
|
|
600
|
+
*
|
|
601
|
+
* @remarks
|
|
602
|
+
* @param
|
|
603
|
+
*/
|
|
604
|
+
setCustomId() {
|
|
605
|
+
throw new Error(
|
|
606
|
+
"setCustomId is not supported on RouteRoleSelectMenuBuilder"
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
setPattern(arg) {
|
|
610
|
+
const {
|
|
611
|
+
method = "GET",
|
|
612
|
+
path: path2,
|
|
613
|
+
query
|
|
614
|
+
} = isSetOptions(arg) ? arg : { path: arg };
|
|
615
|
+
super.setCustomId(
|
|
616
|
+
encodePath({
|
|
617
|
+
idPrefix: this.#embedRouter.getIdPrefix(),
|
|
618
|
+
method,
|
|
619
|
+
path: path2,
|
|
620
|
+
query
|
|
621
|
+
})
|
|
622
|
+
);
|
|
623
|
+
return this;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
// src/componentBuilders/RouteUserSelectMenuBuilder.ts
|
|
628
|
+
var import_discord6 = require("discord.js");
|
|
629
|
+
var RouteUserSelectMenuBuilder = class extends import_discord6.UserSelectMenuBuilder {
|
|
630
|
+
#embedRouter;
|
|
631
|
+
/**
|
|
632
|
+
*
|
|
633
|
+
* @param embedRouter the router you want to route with
|
|
634
|
+
* @param data the data to construct a component out of
|
|
635
|
+
*/
|
|
636
|
+
constructor(embedRouter, data) {
|
|
637
|
+
super(data);
|
|
638
|
+
this.#embedRouter = embedRouter;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Not supported for RouteUserSelectMenuBuilder (customId set from embedRouter)
|
|
642
|
+
*
|
|
643
|
+
* @remarks
|
|
644
|
+
* @param
|
|
645
|
+
*/
|
|
646
|
+
setCustomId() {
|
|
647
|
+
throw new Error(
|
|
648
|
+
"setCustomId is not supported on RouteUserSelectMenuBuilder"
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
setPattern(arg) {
|
|
652
|
+
const {
|
|
653
|
+
method = "GET",
|
|
654
|
+
path: path2,
|
|
655
|
+
query
|
|
656
|
+
} = isSetOptions(arg) ? arg : { path: arg };
|
|
657
|
+
super.setCustomId(
|
|
658
|
+
encodePath({
|
|
659
|
+
idPrefix: this.#embedRouter.getIdPrefix(),
|
|
660
|
+
method,
|
|
661
|
+
path: path2,
|
|
662
|
+
query
|
|
663
|
+
})
|
|
664
|
+
);
|
|
665
|
+
return this;
|
|
212
666
|
}
|
|
213
667
|
};
|
|
214
668
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
669
|
0 && (module.exports = {
|
|
216
670
|
EmbedRouter,
|
|
217
|
-
RouteButtonBuilder
|
|
671
|
+
RouteButtonBuilder,
|
|
672
|
+
RouteChannelSelectMenuBuilder,
|
|
673
|
+
RouteRoleSelectMenuBuilder,
|
|
674
|
+
RouteStringSelectMenuBuilder,
|
|
675
|
+
RouteStringSelectMenuOptionBuilder,
|
|
676
|
+
RouteUserSelectMenuBuilder
|
|
218
677
|
});
|
|
219
678
|
//# sourceMappingURL=index.js.map
|