gralonium 0.4.0 → 0.5.0

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.
Files changed (40) hide show
  1. package/lib/classes/Client.d.ts +13 -3
  2. package/lib/classes/Client.js +23 -1
  3. package/lib/classes/Context.d.ts +2 -0
  4. package/lib/classes/Context.js +94 -21
  5. package/lib/classes/Cooldowns.d.ts +2 -0
  6. package/lib/classes/Cooldowns.js +28 -0
  7. package/lib/classes/Loader.d.ts +12 -3
  8. package/lib/classes/Loader.js +141 -19
  9. package/lib/classes/Plugins.js +3 -2
  10. package/lib/classes/Utils.d.ts +1 -1
  11. package/lib/classes/Utils.js +110 -20
  12. package/lib/classes/builders/CommandBuilder.d.ts +14 -0
  13. package/lib/classes/builders/CommandBuilder.js +50 -2
  14. package/lib/classes/builders/ComponentsV2Builder.d.ts +51 -3
  15. package/lib/classes/builders/ComponentsV2Builder.js +394 -72
  16. package/lib/classes/builders/GroupBuilder.d.ts +11 -0
  17. package/lib/classes/builders/GroupBuilder.js +21 -1
  18. package/lib/classes/builders/InteractionBuilder.d.ts +47 -0
  19. package/lib/classes/builders/InteractionBuilder.js +113 -2
  20. package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
  21. package/lib/classes/builders/ParamsBuilder.js +167 -1
  22. package/lib/classes/builders/components/StyleMapper.d.ts +13 -1
  23. package/lib/classes/builders/components/StyleMapper.js +33 -8
  24. package/lib/classes/builders/components/helpers.d.ts +3 -0
  25. package/lib/classes/builders/components/helpers.js +56 -3
  26. package/lib/classes/builders/components/linter.d.ts +61 -0
  27. package/lib/classes/builders/components/linter.js +252 -0
  28. package/lib/classes/builders/components/overflow.d.ts +151 -0
  29. package/lib/classes/builders/components/overflow.js +534 -0
  30. package/lib/classes/views/V2Adaptive.d.ts +103 -0
  31. package/lib/classes/views/V2Adaptive.js +502 -0
  32. package/lib/classes/views/V2PersistentRouter.d.ts +124 -0
  33. package/lib/classes/views/V2PersistentRouter.js +511 -0
  34. package/lib/classes/views/V2View.d.ts +1 -0
  35. package/lib/classes/views/V2View.js +53 -15
  36. package/lib/experiments.d.ts +2 -0
  37. package/lib/experiments.js +2 -0
  38. package/lib/main.d.ts +4 -0
  39. package/lib/main.js +4 -0
  40. package/package.json +1 -1
@@ -0,0 +1,502 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.V2Adaptive =
4
+ exports.OverflowMenuInteraction =
5
+ exports.ensureOverflowInteractionBridge =
6
+ exports.unwrapOverflowFallbackInteraction =
7
+ exports.OVERFLOW_SOURCE_SYMBOL =
8
+ void 0;
9
+
10
+ const discord_js_1 = require("discord.js");
11
+ const overflow_js_1 = require("../builders/components/overflow.js");
12
+
13
+ const OVERFLOW_SOURCE_SYMBOL = Symbol.for("gralonium.v2.overflowSource");
14
+ exports.OVERFLOW_SOURCE_SYMBOL = OVERFLOW_SOURCE_SYMBOL;
15
+
16
+ const DEFAULT_ADAPTIVE_TTL_MS = 6 * 60 * 60 * 1000;
17
+ const BRIDGED_CLIENTS = new WeakSet();
18
+ const CLIENT_SEEN_INTERACTIONS = new WeakMap();
19
+
20
+ const adaptiveState = {
21
+ ttlMs: DEFAULT_ADAPTIVE_TTL_MS,
22
+ overflowAvailable: true,
23
+ disabledUntil: 0,
24
+ forceMode: null,
25
+ fallbackCount: 0,
26
+ };
27
+
28
+ function rememberInteractionId(client, id) {
29
+ if (!client || !id) return;
30
+ let seen = CLIENT_SEEN_INTERACTIONS.get(client);
31
+ if (!seen) {
32
+ seen = new Set();
33
+ CLIENT_SEEN_INTERACTIONS.set(client, seen);
34
+ }
35
+ seen.add(String(id));
36
+ if (seen.size > 64) {
37
+ const oldest = seen.values().next().value;
38
+ if (oldest !== undefined) seen.delete(oldest);
39
+ }
40
+ }
41
+
42
+ function hasSeenInteractionId(client, id) {
43
+ if (!client || !id) return false;
44
+ return Boolean(CLIENT_SEEN_INTERACTIONS.get(client)?.has(String(id)));
45
+ }
46
+
47
+ /**
48
+ * Unwraps a synthetic `__ovf_sel:` fallback StringSelect interaction so its `customId`
49
+ * directly resolves to the chosen MenuActionItem's `custom_id` while preserving methods
50
+ * and `replied` / `deferred` state on the underlying Discord interaction.
51
+ */
52
+ function unwrapOverflowFallbackInteraction(interaction) {
53
+ if (!interaction || typeof interaction !== "object") return interaction;
54
+ const rawCustomId = interaction.customId;
55
+ if (
56
+ typeof rawCustomId === "string" &&
57
+ rawCustomId.startsWith(overflow_js_1.OVERFLOW_FALLBACK_SELECT_PREFIX) &&
58
+ Array.isArray(interaction.values) &&
59
+ interaction.values.length > 0
60
+ ) {
61
+ return new Proxy(interaction, {
62
+ get(target, prop) {
63
+ if (prop === "customId") return target.values[0];
64
+ if (prop === "overflowMenuCustomId") return target.customId;
65
+ if (prop === "rawInteraction") return target;
66
+ if (prop === "isOverflowMenu") return () => true;
67
+ const value = Reflect.get(target, prop, target);
68
+ return typeof value === "function" ? value.bind(target) : value;
69
+ },
70
+ set(target, prop, value) {
71
+ return Reflect.set(target, prop, value, target);
72
+ },
73
+ });
74
+ }
75
+ return interaction;
76
+ }
77
+ exports.unwrapOverflowFallbackInteraction = unwrapOverflowFallbackInteraction;
78
+
79
+ function resolveOverflowCustomIdAndValues(dataPayload) {
80
+ const values = Array.isArray(dataPayload?.values) ? dataPayload.values.map(String) : [];
81
+ const rawCustomId = dataPayload?.custom_id !== undefined ? String(dataPayload.custom_id) : "";
82
+
83
+ if (values.length > 0) {
84
+ return { customId: values[0], parentCustomId: rawCustomId || null, values };
85
+ }
86
+ return {
87
+ customId: rawCustomId,
88
+ parentCustomId: null,
89
+ values: rawCustomId ? [rawCustomId] : [],
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Synthesized interaction wrapper for Discord OverflowMenu (`component_type: 25 | 26`)
95
+ * gateway packets before `discord.js` natively maps the component enum.
96
+ */
97
+ class OverflowMenuInteraction {
98
+ constructor(client, rawPacketData) {
99
+ const dataPayload = rawPacketData?.data || {};
100
+ const { customId, parentCustomId, values } = resolveOverflowCustomIdAndValues(dataPayload);
101
+
102
+ this.client = client;
103
+ this.id = rawPacketData.id;
104
+ this.applicationId = rawPacketData.application_id ?? client?.user?.id ?? null;
105
+ this.type = rawPacketData.type ?? 3;
106
+ this.token = rawPacketData.token ?? null;
107
+ this.version = rawPacketData.version ?? 1;
108
+ this.componentType = dataPayload.component_type ?? overflow_js_1.OVERFLOW_MENU_TYPE;
109
+ this.customId = customId;
110
+ this.overflowMenuCustomId = parentCustomId;
111
+ this.values = values;
112
+ this.channelId = rawPacketData.channel_id ?? rawPacketData.channel?.id ?? null;
113
+ this.guildId = rawPacketData.guild_id ?? null;
114
+ this.guild = (this.guildId && client?.guilds?.cache?.get?.(this.guildId)) || null;
115
+ this.channel = (this.channelId && client?.channels?.cache?.get?.(this.channelId)) || rawPacketData.channel || null;
116
+ this.user = rawPacketData.user ?? rawPacketData.member?.user ?? null;
117
+ this.member = rawPacketData.member ?? null;
118
+ this.message = rawPacketData.message ?? null;
119
+ this.locale = rawPacketData.locale ?? null;
120
+ this.guildLocale = rawPacketData.guild_locale ?? null;
121
+ this.deferred = false;
122
+ this.replied = false;
123
+ this.ephemeral = null;
124
+ this.rawData = rawPacketData;
125
+ }
126
+
127
+ isOverflowMenu() {
128
+ return true;
129
+ }
130
+
131
+ isMessageComponent() {
132
+ return true;
133
+ }
134
+
135
+ isChatInputCommand() {
136
+ return false;
137
+ }
138
+
139
+ isAutocomplete() {
140
+ return false;
141
+ }
142
+
143
+ isButton() {
144
+ return false;
145
+ }
146
+
147
+ isModalSubmit() {
148
+ return false;
149
+ }
150
+
151
+ isMessageContextMenuCommand() {
152
+ return false;
153
+ }
154
+
155
+ isUserContextMenuCommand() {
156
+ return false;
157
+ }
158
+
159
+ isChannelSelectMenu() {
160
+ return false;
161
+ }
162
+
163
+ isMentionableSelectMenu() {
164
+ return false;
165
+ }
166
+
167
+ isRoleSelectMenu() {
168
+ return false;
169
+ }
170
+
171
+ isStringSelectMenu() {
172
+ return false;
173
+ }
174
+
175
+ isUserSelectMenu() {
176
+ return false;
177
+ }
178
+
179
+ async #sendCallback(type, bodyData) {
180
+ if (!this.client?.rest || !this.id || !this.token) {
181
+ throw new Error("[OverflowMenuInteraction] Client REST instance and interaction token are required.");
182
+ }
183
+ const route = discord_js_1.Routes.interactionCallback(this.id, this.token);
184
+ return this.client.rest.post(route, { body: { type, data: bodyData } });
185
+ }
186
+
187
+ async reply(payload) {
188
+ const body = typeof payload === "string" ? { content: payload } : { ...(payload || {}) };
189
+ this.replied = true;
190
+ this.ephemeral = Boolean(body.flags && (body.flags & discord_js_1.MessageFlags.Ephemeral));
191
+ return this.#sendCallback(4, body);
192
+ }
193
+
194
+ async deferReply(options = {}) {
195
+ this.deferred = true;
196
+ this.ephemeral = Boolean(options.flags && (options.flags & discord_js_1.MessageFlags.Ephemeral));
197
+ return this.#sendCallback(5, options.flags ? { flags: options.flags } : {});
198
+ }
199
+
200
+ async deferUpdate() {
201
+ this.deferred = true;
202
+ return this.#sendCallback(6);
203
+ }
204
+
205
+ async update(payload) {
206
+ const body = typeof payload === "string" ? { content: payload } : { ...(payload || {}) };
207
+ this.replied = true;
208
+ return this.#sendCallback(7, body);
209
+ }
210
+
211
+ async editReply(payload) {
212
+ if (!this.client?.rest || !this.applicationId || !this.token) {
213
+ throw new Error("[OverflowMenuInteraction] Missing REST credentials for editReply.");
214
+ }
215
+ const body = typeof payload === "string" ? { content: payload } : { ...(payload || {}) };
216
+ return this.client.rest.patch(discord_js_1.Routes.webhookMessage(this.applicationId, this.token), { body });
217
+ }
218
+
219
+ async followUp(payload) {
220
+ if (!this.client?.rest || !this.applicationId || !this.token) {
221
+ throw new Error("[OverflowMenuInteraction] Missing REST credentials for followUp.");
222
+ }
223
+ const body = typeof payload === "string" ? { content: payload } : { ...(payload || {}) };
224
+ return this.client.rest.post(discord_js_1.Routes.webhook(this.applicationId, this.token), { body });
225
+ }
226
+ }
227
+ exports.OverflowMenuInteraction = OverflowMenuInteraction;
228
+
229
+ let DiscordNativeMessageComponentCtor = null;
230
+ function getDiscordNativeOverflowCtor() {
231
+ if (DiscordNativeMessageComponentCtor) return DiscordNativeMessageComponentCtor;
232
+ if (typeof discord_js_1.MessageComponentInteraction !== "function") return null;
233
+
234
+ class DiscordOverflowMenuInteraction extends discord_js_1.MessageComponentInteraction {
235
+ constructor(client, rawData) {
236
+ const { customId, parentCustomId, values } = resolveOverflowCustomIdAndValues(rawData.data || {});
237
+ const normalized = {
238
+ ...rawData,
239
+ entitlements: Array.isArray(rawData.entitlements) ? rawData.entitlements : [],
240
+ authorizing_integration_owners: rawData.authorizing_integration_owners || {},
241
+ message: rawData.message || {
242
+ id: rawData.message?.id || "0",
243
+ channel_id: rawData.channel_id || rawData.channel?.id || "0",
244
+ components: [],
245
+ },
246
+ data: {
247
+ ...(rawData.data || {}),
248
+ custom_id: customId,
249
+ },
250
+ };
251
+ super(client, normalized);
252
+ this.values = values;
253
+ this.overflowMenuCustomId = parentCustomId;
254
+ this.componentType = rawData.data?.component_type ?? overflow_js_1.OVERFLOW_MENU_TYPE;
255
+ }
256
+
257
+ isOverflowMenu() {
258
+ return true;
259
+ }
260
+ }
261
+
262
+ DiscordNativeMessageComponentCtor = DiscordOverflowMenuInteraction;
263
+ return DiscordNativeMessageComponentCtor;
264
+ }
265
+
266
+ function buildSynthesizedOverflowInteraction(client, rawData) {
267
+ const canUseDjsClass = Boolean(
268
+ discord_js_1.MessageComponentInteraction &&
269
+ typeof client?.users?._add === "function" &&
270
+ typeof client?.application?.entitlements?._add === "function"
271
+ );
272
+
273
+ if (canUseDjsClass) {
274
+ try {
275
+ const Ctor = getDiscordNativeOverflowCtor();
276
+ if (Ctor) return new Ctor(client, rawData);
277
+ } catch {
278
+ // Fall back to lightweight OverflowMenuInteraction if partial gateway payload lacks internal DJS fields.
279
+ }
280
+ }
281
+
282
+ return new OverflowMenuInteraction(client, rawData);
283
+ }
284
+
285
+ /**
286
+ * Installs an idempotent gateway `raw` listener on `client` so `INTERACTION_CREATE` packets
287
+ * with `component_type` 25 (OverflowMenu) or 26 (MenuActionItem) emit `interactionCreate`
288
+ * on bots running `discord.js` versions without native enum support.
289
+ */
290
+ function ensureOverflowInteractionBridge(client) {
291
+ if (!client || typeof client.on !== "function" || typeof client.emit !== "function") {
292
+ return false;
293
+ }
294
+
295
+ if (BRIDGED_CLIENTS.has(client)) {
296
+ return false;
297
+ }
298
+ BRIDGED_CLIENTS.add(client);
299
+
300
+ client.on("interactionCreate", (interaction) => {
301
+ if (interaction?.id) {
302
+ rememberInteractionId(client, interaction.id);
303
+ }
304
+ });
305
+
306
+ client.on("raw", (packet) => {
307
+ if (!packet || packet.t !== "INTERACTION_CREATE") return;
308
+ const rawData = packet.d;
309
+ if (!rawData || rawData.type !== 3) return;
310
+
311
+ const compType = rawData.data?.component_type;
312
+ if (compType !== overflow_js_1.OVERFLOW_MENU_TYPE && compType !== overflow_js_1.MENU_ACTION_ITEM_TYPE) {
313
+ return;
314
+ }
315
+
316
+ const packetId = rawData.id;
317
+ queueMicrotask(() => {
318
+ if (packetId && hasSeenInteractionId(client, packetId)) {
319
+ return;
320
+ }
321
+ if (packetId) {
322
+ rememberInteractionId(client, packetId);
323
+ }
324
+ const interaction = buildSynthesizedOverflowInteraction(client, rawData);
325
+ client.emit("interactionCreate", interaction);
326
+ });
327
+ });
328
+
329
+ return true;
330
+ }
331
+ exports.ensureOverflowInteractionBridge = ensureOverflowInteractionBridge;
332
+
333
+ /**
334
+ * Adaptive compatibility controller for Discord's OverflowMenu (`type: 25`) rollout.
335
+ * Automatically detects REST `50035` component rejections, caches fallback state for 6h,
336
+ * and retries failed sends immediately using clean `StringSelectMenu` + link-button fallbacks.
337
+ */
338
+ class V2Adaptive {
339
+ static configure(options = {}) {
340
+ if (typeof options.ttlMs === "number" && Number.isFinite(options.ttlMs) && options.ttlMs > 0) {
341
+ adaptiveState.ttlMs = options.ttlMs;
342
+ }
343
+ if (options.forceMode === "native" || options.forceMode === "fallback" || options.forceMode === null) {
344
+ adaptiveState.forceMode = options.forceMode;
345
+ }
346
+ return V2Adaptive.getStatus();
347
+ }
348
+
349
+ static isOverflowAvailable(now = Date.now()) {
350
+ if (adaptiveState.forceMode === "native") return true;
351
+ if (adaptiveState.forceMode === "fallback") return false;
352
+
353
+ if (!adaptiveState.overflowAvailable && adaptiveState.disabledUntil > 0 && now >= adaptiveState.disabledUntil) {
354
+ adaptiveState.overflowAvailable = true;
355
+ adaptiveState.disabledUntil = 0;
356
+ }
357
+ return adaptiveState.overflowAvailable;
358
+ }
359
+
360
+ static markOverflowUnavailable(customTtlMs, now = Date.now()) {
361
+ const ttl =
362
+ typeof customTtlMs === "number" && Number.isFinite(customTtlMs) && customTtlMs > 0
363
+ ? customTtlMs
364
+ : adaptiveState.ttlMs;
365
+ adaptiveState.overflowAvailable = false;
366
+ adaptiveState.disabledUntil = now + ttl;
367
+ adaptiveState.fallbackCount += 1;
368
+ return V2Adaptive.getStatus(now);
369
+ }
370
+
371
+ static markOverflowAvailable() {
372
+ adaptiveState.overflowAvailable = true;
373
+ adaptiveState.disabledUntil = 0;
374
+ return V2Adaptive.getStatus();
375
+ }
376
+
377
+ static reset() {
378
+ adaptiveState.ttlMs = DEFAULT_ADAPTIVE_TTL_MS;
379
+ adaptiveState.overflowAvailable = true;
380
+ adaptiveState.disabledUntil = 0;
381
+ adaptiveState.forceMode = null;
382
+ adaptiveState.fallbackCount = 0;
383
+ }
384
+
385
+ static getStatus(now = Date.now()) {
386
+ const available = V2Adaptive.isOverflowAvailable(now);
387
+ return {
388
+ overflowAvailable: available,
389
+ disabledUntil: adaptiveState.disabledUntil,
390
+ ttlMs: adaptiveState.ttlMs,
391
+ forceMode: adaptiveState.forceMode,
392
+ fallbackCount: adaptiveState.fallbackCount,
393
+ };
394
+ }
395
+
396
+ static isOverflowRejectionError(error) {
397
+ if (!error) return false;
398
+ const code = error.code ?? error.rawError?.code ?? error.data?.code;
399
+ if (code === 50035) {
400
+ const nestedErrors = error.rawError?.errors ?? error.errors;
401
+ if (nestedErrors && typeof nestedErrors === "object" && Object.keys(nestedErrors).length > 0) {
402
+ if ("components" in nestedErrors) return true;
403
+ return /components|accessory|overflow|\b25\b|\b26\b|type/i.test(JSON.stringify(nestedErrors));
404
+ }
405
+ return true;
406
+ }
407
+ return /\b50035\b/i.test(String(error.message || ""));
408
+ }
409
+
410
+ static extractOverflowSource(payloadOrBuilder) {
411
+ if (!payloadOrBuilder || typeof payloadOrBuilder !== "object") return null;
412
+ if (payloadOrBuilder[OVERFLOW_SOURCE_SYMBOL]) {
413
+ return payloadOrBuilder[OVERFLOW_SOURCE_SYMBOL];
414
+ }
415
+ if (typeof payloadOrBuilder.toPayload === "function" && payloadOrBuilder.hasOverflowMenu) {
416
+ return {
417
+ builder: payloadOrBuilder,
418
+ options: {},
419
+ usedNativeOverflow: V2Adaptive.isOverflowAvailable(),
420
+ canFallback: true,
421
+ };
422
+ }
423
+ return null;
424
+ }
425
+
426
+ static attachOverflowSource(payload, sourceMeta) {
427
+ if (!payload || typeof payload !== "object") return payload;
428
+ Object.defineProperty(payload, OVERFLOW_SOURCE_SYMBOL, {
429
+ value: sourceMeta,
430
+ configurable: true,
431
+ enumerable: false,
432
+ writable: true,
433
+ });
434
+ return payload;
435
+ }
436
+
437
+ static async executeWithFallback(payloadOrBuilder, executorFn, payloadOptions = {}) {
438
+ const isBuilder = Boolean(payloadOrBuilder && typeof payloadOrBuilder.toPayload === "function");
439
+ const initialPayload = isBuilder ? payloadOrBuilder.toPayload(payloadOptions) : payloadOrBuilder;
440
+
441
+ try {
442
+ return await executorFn(initialPayload);
443
+ } catch (error) {
444
+ const source = V2Adaptive.extractOverflowSource(initialPayload) || V2Adaptive.extractOverflowSource(payloadOrBuilder);
445
+ if (!source || !source.usedNativeOverflow || !source.canFallback || !V2Adaptive.isOverflowRejectionError(error)) {
446
+ throw error;
447
+ }
448
+
449
+ V2Adaptive.markOverflowUnavailable();
450
+ const rebuilt = source.builder.toPayload({
451
+ ...(source.options || {}),
452
+ ...payloadOptions,
453
+ forceOverflowFallback: true,
454
+ });
455
+
456
+ if (initialPayload && typeof initialPayload === "object") {
457
+ for (const extraKey of ["withResponse", "reply", "fetchReply"]) {
458
+ if (extraKey in initialPayload && rebuilt[extraKey] === undefined) {
459
+ rebuilt[extraKey] = initialPayload[extraKey];
460
+ }
461
+ }
462
+ }
463
+
464
+ return executorFn(rebuilt);
465
+ }
466
+ }
467
+
468
+ static async send(target, builderOrPayload, options = {}) {
469
+ if (typeof target === "function") {
470
+ return V2Adaptive.executeWithFallback(builderOrPayload, target, options);
471
+ }
472
+
473
+ if (target && typeof target.reply === "function" && ("deferred" in target || "replied" in target)) {
474
+ return V2Adaptive.executeWithFallback(
475
+ builderOrPayload,
476
+ (payload) => {
477
+ if (target.deferred || target.replied) {
478
+ if (options.followUp && typeof target.followUp === "function") {
479
+ return target.followUp(payload);
480
+ }
481
+ if (typeof target.editReply === "function") {
482
+ return target.editReply(payload);
483
+ }
484
+ }
485
+ return target.reply(payload);
486
+ },
487
+ options
488
+ );
489
+ }
490
+
491
+ if (target && typeof target.send === "function") {
492
+ return V2Adaptive.executeWithFallback(
493
+ builderOrPayload,
494
+ (payload) => target.send(payload, options),
495
+ options
496
+ );
497
+ }
498
+
499
+ throw new TypeError("[V2Adaptive] send() requires a Context, TextBasedChannel, Interaction, or sender function.");
500
+ }
501
+ }
502
+ exports.V2Adaptive = V2Adaptive;
@@ -0,0 +1,124 @@
1
+ import type {
2
+ Client,
3
+ Guild,
4
+ GuildMember,
5
+ Message,
6
+ MessageComponentInteraction,
7
+ PermissionResolvable,
8
+ TextBasedChannel,
9
+ User,
10
+ } from "discord.js";
11
+ import type { ComponentsV2Builder, V2BuiltPayload, V2PayloadOptions } from "../builders/ComponentsV2Builder.js";
12
+ import type { ContextSendOptions } from "../Context.js";
13
+
14
+ export type V2PersistentLockScope =
15
+ | "action"
16
+ | "message"
17
+ | "user"
18
+ | "customId"
19
+ | "none"
20
+ | false
21
+ | ((ctx: V2PersistentContext<any>) => string | null | undefined);
22
+
23
+ export interface V2PersistentArgSpec {
24
+ name: string;
25
+ type?: "string" | "snowflake" | "id" | "int" | "integer" | "number" | "float" | "bool" | "boolean" | "rest";
26
+ optional?: boolean;
27
+ default?: unknown;
28
+ }
29
+
30
+ export type V2PersistentSchema = Array<string | V2PersistentArgSpec>;
31
+
32
+ export interface V2PersistentMessages {
33
+ guildOnly?: string;
34
+ notOwner?: string;
35
+ missingUserPerms?: string;
36
+ missingBotPerms?: string;
37
+ selfTarget?: string;
38
+ guildOwnerTarget?: string;
39
+ userHierarchy?: string;
40
+ botHierarchy?: string;
41
+ memberNotFound?: string;
42
+ invalidArgs?: string;
43
+ inFlight?: string;
44
+ error?: string;
45
+ }
46
+
47
+ export interface V2PersistentContext<A = Record<string, any>> {
48
+ bot: any;
49
+ client: any;
50
+ interaction: MessageComponentInteraction | any;
51
+ router: V2PersistentRouter;
52
+ namespace: string;
53
+ action: string;
54
+ customId: string;
55
+ parts: string[];
56
+ args: A;
57
+ values: string[];
58
+ guild: Guild | null;
59
+ channel: TextBasedChannel | null;
60
+ member: GuildMember | any;
61
+ user: User | any;
62
+ targetMember: GuildMember | null;
63
+ id: (action: string, ...args: Array<string | number>) => string;
64
+ reply: (payload: ComponentsV2Builder | V2BuiltPayload | Record<string, any> | string, opts?: V2PayloadOptions & ContextSendOptions) => Promise<Message<boolean> | any>;
65
+ replyEphemeral: (payload: ComponentsV2Builder | V2BuiltPayload | Record<string, any> | string, opts?: V2PayloadOptions & ContextSendOptions) => Promise<Message<boolean> | any>;
66
+ }
67
+
68
+ export type V2PersistentRouteHandler<A = Record<string, any>> = (ctx: V2PersistentContext<A>) => unknown | Promise<unknown>;
69
+
70
+ export interface V2PersistentRouteConfig<A = Record<string, any>> {
71
+ schema?: V2PersistentSchema;
72
+ guildOnly?: boolean;
73
+ ownerOnly?: boolean;
74
+ userPermissions?: PermissionResolvable;
75
+ permissions?: PermissionResolvable;
76
+ botPermissions?: PermissionResolvable;
77
+ hierarchy?: boolean | string | ((ctx: V2PersistentContext<A>) => string | GuildMember | null | undefined | Promise<string | GuildMember | null | undefined>);
78
+ allowSelf?: boolean;
79
+ requireMemberInGuild?: boolean;
80
+ checkBotHierarchy?: boolean;
81
+ inFlight?: V2PersistentLockScope;
82
+ inFlightSilent?: boolean;
83
+ inFlightMessage?: string;
84
+ filter?: (ctx: V2PersistentContext<A>) => boolean | Promise<boolean>;
85
+ handler?: V2PersistentRouteHandler<A>;
86
+ }
87
+
88
+ export interface V2PersistentRouterOptions {
89
+ separator?: string;
90
+ inFlight?: V2PersistentLockScope;
91
+ inFlightSilent?: boolean;
92
+ inFlightMessage?: string;
93
+ guildOnly?: boolean;
94
+ messages?: V2PersistentMessages;
95
+ onError?: (error: unknown, ctx: V2PersistentContext<any>) => unknown | Promise<unknown>;
96
+ }
97
+
98
+ export declare class V2PersistentRouter {
99
+ readonly namespace: string;
100
+ readonly separator: string;
101
+ readonly size: number;
102
+ readonly activeLocks: number;
103
+
104
+ constructor(namespace: string, options?: V2PersistentRouterOptions);
105
+ id(action: string, ...args: Array<string | number>): string;
106
+ scopedId(action: string, ...args: Array<string | number>): string;
107
+ matches(customId: string): boolean;
108
+ parse(customId: string): { action: string; parts: string[] } | null;
109
+
110
+ on<A = Record<string, any>>(action: string, handler: V2PersistentRouteHandler<A>): this;
111
+ on<A = Record<string, any>>(action: string, config: V2PersistentRouteConfig<A>, handler?: V2PersistentRouteHandler<A>): this;
112
+ route<A = Record<string, any>>(action: string, handler: V2PersistentRouteHandler<A>): this;
113
+ route<A = Record<string, any>>(action: string, config: V2PersistentRouteConfig<A>, handler?: V2PersistentRouteHandler<A>): this;
114
+ action<A = Record<string, any>>(action: string, handler: V2PersistentRouteHandler<A>): this;
115
+ action<A = Record<string, any>>(action: string, config: V2PersistentRouteConfig<A>, handler?: V2PersistentRouteHandler<A>): this;
116
+
117
+ handle(interaction: unknown, bot?: any): Promise<boolean>;
118
+ attach(client: Client | Record<string, any>): () => void;
119
+ }
120
+
121
+ export declare function createPersistentRouter(
122
+ namespace: string,
123
+ options?: V2PersistentRouterOptions
124
+ ): V2PersistentRouter;