@seedcord/core 0.12.0-next.0 → 0.12.0-next.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 +3 -3
- package/dist/{Bus-W1K-uMeO.mjs → Bus-VJw-QpoY.mjs} +110 -54
- package/dist/Bus-VJw-QpoY.mjs.map +1 -0
- package/dist/{CoordinatedShutdown-BVtNNSsF.d.mts → CoordinatedShutdown-fPKLWjc5.d.mts} +2 -2
- package/dist/{CoordinatedStartup-DA3gW8op.mjs → CoordinatedStartup-Zw_Lk7Zk.mjs} +3 -3
- package/dist/{CoordinatedStartup-DA3gW8op.mjs.map → CoordinatedStartup-Zw_Lk7Zk.mjs.map} +1 -1
- package/dist/HmrModuleHandler-Btgu8r96.mjs +165 -0
- package/dist/HmrModuleHandler-Btgu8r96.mjs.map +1 -0
- package/dist/{PluginHost-DWBgBS6Q.d.mts → PluginHost-DFnkIldj.d.mts} +10 -9
- package/dist/{PluginHost-CYe-UVpp.mjs → PluginHost-DTtxWRiL.mjs} +4 -4
- package/dist/PluginHost-DTtxWRiL.mjs.map +1 -0
- package/dist/{PluginLifecycle-DdwRzcDj.mjs → PluginLifecycle-hx5zUc-P.mjs} +4 -4
- package/dist/PluginLifecycle-hx5zUc-P.mjs.map +1 -0
- package/dist/{ServerHost-whpI0h4d.d.mts → ServerHost-B5o3ScCF.d.mts} +3 -3
- package/dist/{ServerHost-DHg-Y2_q.mjs → ServerHost-CDaEDR4C.mjs} +4 -4
- package/dist/{ServerHost-DHg-Y2_q.mjs.map → ServerHost-CDaEDR4C.mjs.map} +1 -1
- package/dist/hmr.index.d.mts +20 -20
- package/dist/hmr.index.mjs +1 -1
- package/dist/{index-Boo33hh3.d.mts → index-DGHng1IN.d.mts} +108 -193
- package/dist/index.d.mts +216 -71
- package/dist/index.mjs +215 -100
- package/dist/index.mjs.map +1 -1
- package/dist/internal.index.d.mts +204 -82
- package/dist/internal.index.mjs +572 -73
- package/dist/internal.index.mjs.map +1 -1
- package/dist/node-internal.index.d.mts +4 -3
- package/dist/node-internal.index.mjs +3 -3
- package/dist/node.index.d.mts +2 -2
- package/dist/node.index.mjs +4 -4
- package/dist/{phases-Dojnr-ng.d.mts → phases-C2QCSqRu.d.mts} +60 -50
- package/dist/plugin.index.d.mts +1 -1
- package/dist/plugin.index.mjs +1 -1
- package/dist/{subscribers-D4_HZcgw.mjs → subscribers-CGuVjbrg.mjs} +139 -253
- package/dist/subscribers-CGuVjbrg.mjs.map +1 -0
- package/package.json +10 -9
- package/dist/Bus-W1K-uMeO.mjs.map +0 -1
- package/dist/HmrModuleHandler-BMD7dg8N.mjs +0 -162
- package/dist/HmrModuleHandler-BMD7dg8N.mjs.map +0 -1
- package/dist/PluginHost-CYe-UVpp.mjs.map +0 -1
- package/dist/PluginLifecycle-DdwRzcDj.mjs.map +0 -1
- package/dist/subscribers-D4_HZcgw.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
import { $ as
|
|
1
|
+
import { C as AckState, F as KvCollection, H as InteractionKind, I as DispatchContext, K as MiddlewareKind, P as Kv, X as NoticeConstructor, Y as Notice, _ as ResponseSent, a as Bus, b as Subscriptions, d as DispatchOutcome, f as FaultSource, g as ResponseOutcome, h as ResponseFailed, i as CoreBase, l as AttemptedWrite, m as ResponseAttempt, n as StartupPhase, t as ShutdownPhase, v as SubscriptionData, x as ReplyTelemetry, y as SubscriptionKey } from "./phases-C2QCSqRu.mjs";
|
|
2
|
+
import { $ as ContextMenuInfo, A as RequiredOf, C as JoinNames, Ct as BuilderComponent, D as Gate, E as EffectGate, Et as RowType, F as DispatchResult, Ft as MessageContextMenuRegistry, G as ComponentDefsBrand, H as RegisterInteractionMiddleware, I as EventDispatchResult, It as NamesFor, J as ContextMenuNamesBrand, K as ComponentKindBrand, L as HandlerOutcome, Lt as UserContextMenuRegistry, M as defineGate, N as SerializedReply, Nt as ContextMenuKind, O as GateContextBase, Q as Commands, R as HandlerResult, S as IntersectRequired, St as RegisterCommand, T as AppPermissionsContext, Tt as BuilderType, V as InteractionMiddlewareOptions, W as AutocompleteRouteBrand, X as SlashRouteBrand, Z as CommandInfo, a as Subscribe, b as ResolvedEmoji, et as ContextMenus, g as AutocompleteOptions, i as WebhookFile, j as defineEffectGate, jt as SlashRegistry, k as GuildPermissionsContext, n as WebhookLog, nt as InjectedContextMenuMap, o as SubscribeOptions, p as PageCursor, q as ContextMenuKindBrand, r as WebhookReport, s as Subscriber, t as WebhookUrl, tt as InjectedCommandMap, w as TwoOrMore, wt as RowComponent, xt as GuildTarget } from "./index-DGHng1IN.mjs";
|
|
3
3
|
import { n as PluginTypes, t as Generated } from "./Generated-ByC53_A2.mjs";
|
|
4
4
|
import "reflect-metadata";
|
|
5
5
|
import { AnyCustomId, AnyCustomId as AnyCustomId$1, CustomId, CustomIdField, CustomIdShape, DecodedParams, DecodedRoute, FieldOptions, decodeFor, prefixOf, setCustomIdErrors } from "@seedcord/custom-id";
|
|
@@ -7,8 +7,9 @@ import { ActionRowBuilder, ButtonBuilder } from "@discordjs/builders";
|
|
|
7
7
|
import { APIMessageComponentEmoji, APIModalInteractionResponseCallbackData, ApplicationCommandType, ButtonStyle } from "discord-api-types/v10";
|
|
8
8
|
import { Logger } from "@seedcord/logger";
|
|
9
9
|
import { ValidDuration } from "@seedcord/utils";
|
|
10
|
+
import { REST } from "@discordjs/rest";
|
|
10
11
|
import { DeferOpts, EpochMs, KvDriver, KvEntry, LoggerChannelId, RenderContext, ReplyResponse, SendOpts, TypedExtract } from "@seedcord/types";
|
|
11
|
-
import { Constructor, Promisable } from "type-fest";
|
|
12
|
+
import { Constructor, LiteralUnion, Promisable } from "type-fest";
|
|
12
13
|
//#region src/decorators/routes.d.ts
|
|
13
14
|
type ComponentBrand = TypedExtract<InteractionKind, InteractionKind.Button | InteractionKind.Modal | InteractionKind.StringMenu | InteractionKind.UserMenu | InteractionKind.RoleMenu | InteractionKind.ChannelMenu | InteractionKind.MentionableMenu>;
|
|
14
15
|
type AnyHandlerCtor = new (...args: never[]) => unknown;
|
|
@@ -30,15 +31,21 @@ type ComponentOf<TCtor extends AnyHandlerCtor> = InstanceType<TCtor> extends {
|
|
|
30
31
|
type DefsOf<TCtor extends AnyHandlerCtor> = InstanceType<TCtor> extends {
|
|
31
32
|
[ComponentDefsBrand]?: infer Defs extends readonly AnyCustomId$1[];
|
|
32
33
|
} ? Defs : never;
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
type SameSet<Left, Right> = [Left] extends [Right] ? ([Right] extends [Left] ? true : false) : false;
|
|
35
|
+
type Mismatch<Message extends string, Decorator, Generic> = Constructor<[Message, {
|
|
36
|
+
decorator: Decorator;
|
|
37
|
+
generic: Generic;
|
|
38
|
+
}]>;
|
|
39
|
+
type AssertNames<Names extends string, Registered, Declared, Decorator extends string, Handler extends string, TCtor extends AnyHandlerCtor> = [Names] extends [Registered] ? SameSet<Names, Declared> extends true ? TCtor : Mismatch<`${Decorator} does not match the ${Handler} generic`, Names, Declared> : Constructor<[`${Decorator} lists a command that is not registered`, Exclude<Names, Registered>]>;
|
|
40
|
+
type AssertSlashRoute<Route extends string, TCtor extends AnyHandlerCtor> = AssertNames<Route, keyof SlashRegistry, SlashRouteOf<TCtor>, 'SlashRoute', 'SlashHandler', TCtor>;
|
|
41
|
+
type AssertAutocompleteRoute<Route extends string, TCtor extends AnyHandlerCtor> = AssertNames<Route, keyof SlashRegistry, AutocompleteRouteOf<TCtor>, 'AutocompleteRoute', 'AutocompleteHandler', TCtor>;
|
|
42
|
+
type AssertContextMenuRoute<Kind extends ContextMenuKind, Names extends string, TCtor extends AnyHandlerCtor> = SameSet<Kind, ContextMenuKindOf<TCtor>> extends true ? AssertNames<Names, NamesFor<Kind>, ContextMenuNamesOf<TCtor>, 'ContextMenuRoute', 'ContextMenuHandler', TCtor> : Mismatch<'ContextMenuRoute does not match the ContextMenuHandler kind', Kind, ContextMenuKindOf<TCtor>>;
|
|
43
|
+
type AssertComponentRoute<Brand extends ComponentBrand, Defs extends readonly AnyCustomId$1[], TCtor extends AnyHandlerCtor> = SameSet<Brand, ComponentOf<TCtor>> extends true ? [DefsOf<TCtor>] extends [Defs] ? TCtor : Mismatch<'the customId definitions do not match the handler generic', Defs, DefsOf<TCtor>> : Mismatch<'the decorator does not match the handler kind', Brand, ComponentOf<TCtor>>;
|
|
37
44
|
/**
|
|
38
45
|
* Routes one or more slash commands to a `SlashHandler`.
|
|
39
46
|
*
|
|
40
|
-
* Pass the same route string(s) as the handler's generic.
|
|
41
|
-
*
|
|
47
|
+
* Pass the same route string(s) as the handler's generic. On a handler for one command, read
|
|
48
|
+
* `this.options`. On a handler for several, branch with `this.match`. The decorator routes and the generic must match exactly. Listing
|
|
42
49
|
* fewer or more than the handler declares is a compile error. Subcommands use a slash path.
|
|
43
50
|
*
|
|
44
51
|
* @param routes - The route string(s) this handler serves, e.g. `'ban'`, `'ban', 'kick'`, or `'demo/setup'`.
|
|
@@ -53,12 +60,12 @@ type AssertComponentRoute<Brand extends ComponentBrand, Defs extends readonly An
|
|
|
53
60
|
* }
|
|
54
61
|
* ```
|
|
55
62
|
*/
|
|
56
|
-
export declare function SlashRoute<const Route extends keyof SlashRegistry
|
|
63
|
+
export declare function SlashRoute<const Route extends LiteralUnion<keyof SlashRegistry, string>>(...routes: Route[]): <TCtor extends AnyHandlerCtor>(constructor: AssertSlashRoute<Route, TCtor>) => void;
|
|
57
64
|
/**
|
|
58
65
|
* Routes one or more commands' autocomplete to an `AutocompleteHandler`.
|
|
59
66
|
*
|
|
60
67
|
* Pass the same command route string(s) as the handler's generic. One command branches with `this.match`
|
|
61
|
-
* over its autocompletable fields, several commands share one handler whose
|
|
68
|
+
* over its autocompletable fields, several commands share one handler whose cases span every command's
|
|
62
69
|
* fields. Listing fewer or more commands than the handler declares is a compile error, since the
|
|
63
70
|
* decorator routes and the generic must match exactly.
|
|
64
71
|
*
|
|
@@ -74,7 +81,7 @@ export declare function SlashRoute<const Route extends keyof SlashRegistry>(...r
|
|
|
74
81
|
* }
|
|
75
82
|
* ```
|
|
76
83
|
*/
|
|
77
|
-
export declare function AutocompleteRoute<const Route extends keyof SlashRegistry
|
|
84
|
+
export declare function AutocompleteRoute<const Route extends LiteralUnion<keyof SlashRegistry, string>>(...routes: Route[]): <TCtor extends AnyHandlerCtor>(constructor: AssertAutocompleteRoute<Route, TCtor>) => void;
|
|
78
85
|
/**
|
|
79
86
|
* Routes one or more user context-menu commands to a `UserContextMenuHandler`.
|
|
80
87
|
*
|
|
@@ -93,7 +100,7 @@ export declare function AutocompleteRoute<const Route extends keyof SlashRegistr
|
|
|
93
100
|
* }
|
|
94
101
|
* ```
|
|
95
102
|
*/
|
|
96
|
-
export declare function UserContextMenuRoute<const Names extends NamesFor<ApplicationCommandType.User>>(...names: Names[]): <TCtor extends AnyHandlerCtor>(constructor: AssertContextMenuRoute<ApplicationCommandType.User, Names, TCtor>) => void;
|
|
103
|
+
export declare function UserContextMenuRoute<const Names extends LiteralUnion<NamesFor<ApplicationCommandType.User>, string>>(...names: Names[]): <TCtor extends AnyHandlerCtor>(constructor: AssertContextMenuRoute<ApplicationCommandType.User, Names, TCtor>) => void;
|
|
97
104
|
/**
|
|
98
105
|
* Routes one or more message context-menu commands to a `MessageContextMenuHandler`.
|
|
99
106
|
*
|
|
@@ -112,7 +119,7 @@ export declare function UserContextMenuRoute<const Names extends NamesFor<Applic
|
|
|
112
119
|
* }
|
|
113
120
|
* ```
|
|
114
121
|
*/
|
|
115
|
-
export declare function MessageContextMenuRoute<const Names extends NamesFor<ApplicationCommandType.Message>>(...names: Names[]): <TCtor extends AnyHandlerCtor>(constructor: AssertContextMenuRoute<ApplicationCommandType.Message, Names, TCtor>) => void;
|
|
122
|
+
export declare function MessageContextMenuRoute<const Names extends LiteralUnion<NamesFor<ApplicationCommandType.Message>, string>>(...names: Names[]): <TCtor extends AnyHandlerCtor>(constructor: AssertContextMenuRoute<ApplicationCommandType.Message, Names, TCtor>) => void;
|
|
116
123
|
/**
|
|
117
124
|
* Routes button interactions to handler classes.
|
|
118
125
|
*
|
|
@@ -140,7 +147,7 @@ export declare function ModalRoute<const Defs extends readonly AnyCustomId$1[]>(
|
|
|
140
147
|
* Routes string select menu interactions to a `StringMenuHandler`.
|
|
141
148
|
*
|
|
142
149
|
* Pass the {@link CustomId} definition(s) this handler decodes and list the same ones in the handler's
|
|
143
|
-
* generic.
|
|
150
|
+
* generic. Read the chosen option values from `this.values`.
|
|
144
151
|
*
|
|
145
152
|
* @param defs - The customId definition(s) this handler decodes, one per route.
|
|
146
153
|
* @decorator
|
|
@@ -249,12 +256,14 @@ export declare abstract class BaseHandler<Event, TCore extends CoreBase> {
|
|
|
249
256
|
protected readonly logger: Logger;
|
|
250
257
|
/** The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag. */
|
|
251
258
|
protected readonly dispatch: DispatchContext;
|
|
259
|
+
/** The route that started this dispatch. Each handler base narrows it to its own routes. */
|
|
260
|
+
protected readonly route: string;
|
|
252
261
|
protected constructor(event: Event, core: TCore, dispatch: DispatchContext, channel?: LoggerChannelId);
|
|
253
262
|
/**
|
|
254
263
|
* Holds the main logic of your handler. The dispatcher calls it after the handler's gates pass, so a
|
|
255
264
|
* gate that refuses stops `execute()` from running.
|
|
256
265
|
*/
|
|
257
|
-
abstract execute():
|
|
266
|
+
abstract execute(): Promisable<void>;
|
|
258
267
|
}
|
|
259
268
|
//#endregion
|
|
260
269
|
//#region src/reply/BaseReplySender.d.ts
|
|
@@ -320,7 +329,7 @@ export declare abstract class BaseReplySender<TMessage extends {
|
|
|
320
329
|
//#region src/handlers/RepliableHandler.d.ts
|
|
321
330
|
/**
|
|
322
331
|
* Shared base the repliable handlers on both transports extend. Defines the reply members over one sender.
|
|
323
|
-
*
|
|
332
|
+
* The dispatch run builds that sender and passes it to the handler and each middleware.
|
|
324
333
|
*
|
|
325
334
|
* @typeParam Event - The repliable interaction type this handler processes
|
|
326
335
|
* @typeParam TCore - The transport's Core
|
|
@@ -333,8 +342,7 @@ export declare abstract class RepliableHandler<Event, TCore extends CoreBase, TM
|
|
|
333
342
|
}, TNative, TSender extends BaseReplySender<TMessage, TNative>> extends BaseHandler<Event, TCore> {
|
|
334
343
|
/** The reply surface for this interaction. Pass the handler to reply from outside its class. */
|
|
335
344
|
readonly sender: TSender;
|
|
336
|
-
protected constructor(event: Event, core: TCore, dispatch: DispatchContext, sender
|
|
337
|
-
protected abstract buildSender(event: Event, core: TCore, dispatch: DispatchContext): TSender;
|
|
345
|
+
protected constructor(event: Event, core: TCore, dispatch: DispatchContext, sender: TSender);
|
|
338
346
|
/** Send the initial response, exactly once. */
|
|
339
347
|
protected reply(response: ReplyResponse<TNative> | string, opts?: SendOpts): Promise<TMessage>;
|
|
340
348
|
/** Show a "thinking" placeholder, then fill it later with {@link edit}. */
|
|
@@ -352,12 +360,12 @@ export declare abstract class RepliableHandler<Event, TCore extends CoreBase, TM
|
|
|
352
360
|
//#endregion
|
|
353
361
|
//#region src/gates/combinators.d.ts
|
|
354
362
|
/**
|
|
355
|
-
* Runs each gate in order and refuses on the first refusal. Takes two or more
|
|
356
|
-
* context is the intersection of
|
|
363
|
+
* Runs each gate in order and refuses on the first refusal. Takes two or more gates. The required
|
|
364
|
+
* context is the intersection of their contexts, so an event-only and an interaction-only gate cannot be
|
|
357
365
|
* combined.
|
|
358
366
|
*
|
|
359
|
-
* @typeParam Gates - The tuple of two or more
|
|
360
|
-
* @param gates - The
|
|
367
|
+
* @typeParam Gates - The tuple of two or more gates, run left to right.
|
|
368
|
+
* @param gates - The gates to run in order, all refused on the first refusal.
|
|
361
369
|
*
|
|
362
370
|
* @see {@link or}
|
|
363
371
|
*
|
|
@@ -379,13 +387,13 @@ interface OrOptions {
|
|
|
379
387
|
fail: Notice | ((ctx: GateContextBase) => Notice);
|
|
380
388
|
}
|
|
381
389
|
/**
|
|
382
|
-
* Runs each gate in order and passes on the first
|
|
383
|
-
* required context is the union of
|
|
384
|
-
*
|
|
385
|
-
* refusal's `summary`, else a default refusal. The trailing options object does not count as
|
|
390
|
+
* Runs each gate in order and passes on the first gate that passes. Takes two or more gates. The
|
|
391
|
+
* required context is the union of their contexts. A handler that matches any one gate fits. When every
|
|
392
|
+
* gate refuses it throws the trailing {@link OrOptions} `fail` if given, else a list built from each
|
|
393
|
+
* refusal's `summary`, else a default refusal. The trailing options object does not count as a gate.
|
|
386
394
|
*
|
|
387
|
-
* @typeParam Gates - The tuple of two or more
|
|
388
|
-
* @param gates - The
|
|
395
|
+
* @typeParam Gates - The tuple of two or more gates, tried left to right.
|
|
396
|
+
* @param gates - The gates to try in order, with an optional trailing {@link OrOptions} object.
|
|
389
397
|
*
|
|
390
398
|
* @see {@link and}
|
|
391
399
|
*
|
|
@@ -404,19 +412,26 @@ export declare function or<Gates extends TwoOrMore<Gate<GateContextBase>>>(...ga
|
|
|
404
412
|
/**
|
|
405
413
|
* @example
|
|
406
414
|
* ```ts
|
|
407
|
-
* // custom refusal when every
|
|
415
|
+
* // custom refusal when every gate refuses
|
|
408
416
|
* or(OwnerOnly(), RequireRole('123456789012345678'), { fail: new NotAllowedNotice() });
|
|
409
417
|
* ```
|
|
410
418
|
*/
|
|
411
419
|
export declare function or<Gates extends TwoOrMore<Gate<GateContextBase>>>(...args: [...Gates, OrOptions]): Gate<RequiredOf<Gates[number]>, JoinNames<Gates, ' | '>>;
|
|
412
420
|
//#endregion
|
|
421
|
+
//#region src/gates/catalog/options.d.ts
|
|
422
|
+
/** The override a gate with a single refusal accepts. */
|
|
423
|
+
interface GateNoticeOptions {
|
|
424
|
+
/** Your Notice class, constructed and thrown in place of the default refusal. */
|
|
425
|
+
notice?: NoticeConstructor;
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
413
428
|
//#region src/gates/catalog/access.d.ts
|
|
414
429
|
/**
|
|
415
430
|
* Passes only for a user id listed in `config.ownerIds`, else refuses.
|
|
416
431
|
*
|
|
417
|
-
* Agnostic, so it attaches to interaction and event handlers alike. With no `ownerIds` configured it refuses every caller. Pass
|
|
432
|
+
* Agnostic, so it attaches to interaction and event handlers alike. With no `ownerIds` configured it refuses every caller. Pass a Notice class as `notice` to replace the refusal.
|
|
418
433
|
*
|
|
419
|
-
* @param options -
|
|
434
|
+
* @param options - Replace the refusal with a Notice class as `notice`.
|
|
420
435
|
*
|
|
421
436
|
* @see the `@Gated` decorator from your transport package
|
|
422
437
|
*
|
|
@@ -433,8 +448,8 @@ export declare function or<Gates extends TwoOrMore<Gate<GateContextBase>>>(...ar
|
|
|
433
448
|
*
|
|
434
449
|
* @example
|
|
435
450
|
* ```ts
|
|
436
|
-
* //
|
|
437
|
-
* OwnerOnly({
|
|
451
|
+
* // OwnersOnly is your own Notice class
|
|
452
|
+
* OwnerOnly({ notice: OwnersOnly });
|
|
438
453
|
* ```
|
|
439
454
|
*/
|
|
440
455
|
export declare function OwnerOnly(options?: GateNoticeOptions): Gate<GateContextBase, 'OwnerOnly'>;
|
|
@@ -443,7 +458,7 @@ export declare function OwnerOnly(options?: GateNoticeOptions): Gate<GateContext
|
|
|
443
458
|
*
|
|
444
459
|
* Agnostic. Attaches to any handler kind. Often paired with `RequirePermissions` in an {@link and}.
|
|
445
460
|
*
|
|
446
|
-
* @param options -
|
|
461
|
+
* @param options - Replace the refusal with a Notice class as `notice`.
|
|
447
462
|
*
|
|
448
463
|
* @see the `@Gated` decorator from your transport package
|
|
449
464
|
*
|
|
@@ -466,7 +481,7 @@ export declare function GuildOnly(options?: GateNoticeOptions): Gate<GateContext
|
|
|
466
481
|
*
|
|
467
482
|
* Agnostic, fitting any handler kind. The inverse of {@link GuildOnly}, so combining the two in an {@link and} can never pass.
|
|
468
483
|
*
|
|
469
|
-
* @param options -
|
|
484
|
+
* @param options - Replace the refusal with a Notice class as `notice`.
|
|
470
485
|
*
|
|
471
486
|
* @see the `@Gated` decorator from your transport package
|
|
472
487
|
*
|
|
@@ -486,16 +501,18 @@ export declare function DmOnly(options?: GateNoticeOptions): Gate<GateContextBas
|
|
|
486
501
|
//#region src/gates/catalog/Cooldown.d.ts
|
|
487
502
|
/**
|
|
488
503
|
* Options for {@link Cooldown}. `per` sets the bucket the window applies to and `limit` the uses allowed per
|
|
489
|
-
* window. `
|
|
490
|
-
* up so the refusal can show the retry time.
|
|
504
|
+
* window. `notice` replaces the refusal.
|
|
491
505
|
*
|
|
492
506
|
* @example
|
|
493
507
|
* ```ts
|
|
494
|
-
* // one use per channel,
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
508
|
+
* // one use per channel, refusing with your own Notice class
|
|
509
|
+
* class SlowDown extends Notice {
|
|
510
|
+
* public constructor(resetAt: EpochMs) {
|
|
511
|
+
* super(`Slow down. Try again <t:${toEpochSeconds(resetAt)}:R>.`);
|
|
512
|
+
* }
|
|
513
|
+
* }
|
|
514
|
+
*
|
|
515
|
+
* Cooldown('10s', { per: 'channel', notice: SlowDown });
|
|
499
516
|
* ```
|
|
500
517
|
*
|
|
501
518
|
* @example
|
|
@@ -517,16 +534,8 @@ interface CooldownOptions {
|
|
|
517
534
|
* @defaultValue `1`
|
|
518
535
|
*/
|
|
519
536
|
limit?: number;
|
|
520
|
-
/**
|
|
521
|
-
|
|
522
|
-
* show the retry time with `<t:${Math.round(resetAt / 1000)}:R>`.
|
|
523
|
-
*/
|
|
524
|
-
message?: (resetAt: EpochMs) => string;
|
|
525
|
-
/**
|
|
526
|
-
* Replace the refusal Notice entirely, for full control or a translated copy. Receives the epoch ms the
|
|
527
|
-
* key frees up.
|
|
528
|
-
*/
|
|
529
|
-
notice?: (resetAt: EpochMs) => Notice;
|
|
537
|
+
/** Your Notice class, constructed with the epoch ms the key frees up and thrown in place of the default refusal. */
|
|
538
|
+
notice?: NoticeConstructor<[resetAt: EpochMs]>;
|
|
530
539
|
}
|
|
531
540
|
/**
|
|
532
541
|
* Allows `limit` uses per window, scoped by `per`. A number `duration` is **seconds**, and a string is
|
|
@@ -534,10 +543,10 @@ interface CooldownOptions {
|
|
|
534
543
|
* so a later refusal never burns the cooldown.
|
|
535
544
|
* That split also means two requests racing the same key can both pass before either charges the slot.
|
|
536
545
|
* The key combines the handler's route with the window settings, keeping two different handlers on separate
|
|
537
|
-
* windows.
|
|
546
|
+
* windows. Replace the refusal with {@link CooldownOptions.notice}.
|
|
538
547
|
*
|
|
539
548
|
* @param duration - A number is seconds, and a string is a duration like `30m` or `24h`.
|
|
540
|
-
* @param options - Sets the scope with `per`, the uses per window with `limit`, and the refusal
|
|
549
|
+
* @param options - Sets the scope with `per`, the uses per window with `limit`, and the refusal with `notice`.
|
|
541
550
|
* @throws A **SeedcordTypeError** when `duration` is a string that doesn't parse.
|
|
542
551
|
* @throws A **SeedcordRangeError** when `duration` is zero or negative.
|
|
543
552
|
*
|
|
@@ -576,26 +585,35 @@ interface CooldownOptions {
|
|
|
576
585
|
*/
|
|
577
586
|
export declare function Cooldown(duration: number | ValidDuration, options?: CooldownOptions): EffectGate<GateContextBase, 'Cooldown'>;
|
|
578
587
|
//#endregion
|
|
588
|
+
//#region src/permissions/bits.d.ts
|
|
589
|
+
/**
|
|
590
|
+
* The permission flag bits a caller or the bot must hold. Pass the `PermissionFlagsBits` values from
|
|
591
|
+
* `discord-api-types/v10` (or `discord.js`).
|
|
592
|
+
*/
|
|
593
|
+
type PermissionScope = readonly bigint[];
|
|
594
|
+
//#endregion
|
|
579
595
|
//#region src/permissions/assert.d.ts
|
|
580
|
-
/**
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
596
|
+
/**
|
|
597
|
+
* A Notice class for a permission refusal. seedcord constructs it with the subject and the permission names
|
|
598
|
+
* the refusal lists. A null subject is the caller.
|
|
599
|
+
*/
|
|
600
|
+
type PermissionNoticeConstructor = NoticeConstructor<[subject: string | null, permissions: readonly string[]]>;
|
|
585
601
|
/** The check {@link assertPermissions} runs. */
|
|
586
|
-
interface PermissionAssertion
|
|
587
|
-
/** Mention string for who is checked, used as the refusal's subject. */
|
|
588
|
-
subject: string;
|
|
602
|
+
interface PermissionAssertion {
|
|
603
|
+
/** Mention string for who is checked, used as the refusal's subject. Null addresses the caller. */
|
|
604
|
+
subject: string | null;
|
|
589
605
|
/** The effective permission bitfield the subject holds, computed by the caller. */
|
|
590
606
|
permissions: bigint;
|
|
591
607
|
/** The permission flag bits to check. */
|
|
592
608
|
scope: PermissionScope;
|
|
593
609
|
/** Refuse when the subject holds a scope bit. */
|
|
594
610
|
inverse?: boolean;
|
|
611
|
+
/** Your Notice class, thrown in place of the default refusal. seedcord constructs it with the missing names, or the held ones under `inverse`. */
|
|
612
|
+
notice?: PermissionNoticeConstructor | undefined;
|
|
595
613
|
}
|
|
596
614
|
/**
|
|
597
615
|
* Refuses when the subject is missing a permission in `scope`, or with `inverse` when it holds one.
|
|
598
|
-
* The Administrator bit passes any scope, and
|
|
616
|
+
* The Administrator bit passes any scope, and with `inverse` it reports every bit in `scope`.
|
|
599
617
|
*
|
|
600
618
|
* The caller computes `permissions`, gateway off a discord.js role, member, or channel, and HTTP off the
|
|
601
619
|
* bitfield the interaction payload carries.
|
|
@@ -640,14 +658,12 @@ interface PermissionAssertion extends PermissionNoticeOverrides {
|
|
|
640
658
|
* ```ts
|
|
641
659
|
* import { Notice } from '@seedcord/core';
|
|
642
660
|
*
|
|
643
|
-
* // a replacement notice takes the same three arguments the default one does
|
|
644
661
|
* class CannotBan extends Notice {
|
|
645
662
|
* public constructor(
|
|
646
|
-
*
|
|
647
|
-
* private readonly subject: string,
|
|
663
|
+
* private readonly subject: string | null,
|
|
648
664
|
* private readonly missing: readonly string[]
|
|
649
665
|
* ) {
|
|
650
|
-
* super(
|
|
666
|
+
* super('You cannot ban here.');
|
|
651
667
|
* }
|
|
652
668
|
*
|
|
653
669
|
* public render(): ReplyResponse {
|
|
@@ -659,11 +675,140 @@ interface PermissionAssertion extends PermissionNoticeOverrides {
|
|
|
659
675
|
* subject: `<@${member.id}>`,
|
|
660
676
|
* permissions: member.permissions.bitfield,
|
|
661
677
|
* scope: [PermissionFlagsBits.BanMembers],
|
|
662
|
-
*
|
|
678
|
+
* notice: CannotBan
|
|
663
679
|
* });
|
|
664
680
|
* ```
|
|
665
681
|
*/
|
|
666
|
-
export declare function assertPermissions(
|
|
682
|
+
export declare function assertPermissions({ subject, permissions, scope, inverse, notice }: PermissionAssertion): void;
|
|
683
|
+
//#endregion
|
|
684
|
+
//#region src/gates/catalog/permissions.d.ts
|
|
685
|
+
/**
|
|
686
|
+
* Options for {@link RequireBotPermissions}.
|
|
687
|
+
*/
|
|
688
|
+
interface RequireBotPermissionsOptions {
|
|
689
|
+
/**
|
|
690
|
+
* The set the check reads. `'channel'` reads the effective channel set the payload carries, what
|
|
691
|
+
* Discord enforces in the invoked channel. `'guild'` reads the base set from roles, available on the
|
|
692
|
+
* gateway transport only.
|
|
693
|
+
*
|
|
694
|
+
* @defaultValue `'channel'`
|
|
695
|
+
*/
|
|
696
|
+
in?: 'channel' | 'guild';
|
|
697
|
+
/** Your Notice class, constructed and thrown in place of the refusal outside a guild. */
|
|
698
|
+
notInGuild?: NoticeConstructor;
|
|
699
|
+
/** Your Notice class, constructed and thrown in place of the refusal when a permission is missing. */
|
|
700
|
+
missing?: PermissionNoticeConstructor;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Options for {@link RequirePermissions}.
|
|
704
|
+
*/
|
|
705
|
+
interface RequirePermissionsOptions extends RequireBotPermissionsOptions {
|
|
706
|
+
/** Your Notice class, constructed and thrown in place of the refusal when the member's permissions are unavailable inside a guild. */
|
|
707
|
+
unresolved?: NoticeConstructor;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Options for {@link RequireRole}.
|
|
711
|
+
*/
|
|
712
|
+
interface RequireRoleOptions {
|
|
713
|
+
/** Your Notice class, constructed and thrown in place of the refusal outside a guild. */
|
|
714
|
+
notInGuild?: NoticeConstructor;
|
|
715
|
+
/** Your Notice class, constructed with the role id and thrown in place of the refusal when the caller lacks the role. */
|
|
716
|
+
missingRole?: NoticeConstructor<[roleId: string]>;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Requires the caller to hold every permission in `scope`. Refuses outside a guild first, then when the
|
|
720
|
+
* member's permissions are unavailable, then when a permission is missing. The Administrator bit passes any
|
|
721
|
+
* scope.
|
|
722
|
+
*
|
|
723
|
+
* The default `'channel'` scope reads the effective channel set the payload carries, what Discord enforces
|
|
724
|
+
* in the invoked channel. The `'guild'` scope reads the base set from roles and requires a
|
|
725
|
+
* {@link GuildPermissionsContext}, so it fits a gateway handler only.
|
|
726
|
+
*
|
|
727
|
+
* @param scope - The permission flag bits the caller must all hold.
|
|
728
|
+
* @param options - Pick the scope with `in`. Replace a refusal with a Notice class as `notInGuild`, `unresolved`, or `missing`.
|
|
729
|
+
*
|
|
730
|
+
* @see the `@Gated` decorator from your transport package
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* ```ts
|
|
734
|
+
* import { PermissionFlagsBits } from 'discord-api-types/v10';
|
|
735
|
+
*
|
|
736
|
+
* \@Gated(RequirePermissions([PermissionFlagsBits.BanMembers]))
|
|
737
|
+
* \@SlashRoute('ban')
|
|
738
|
+
* class BanHandler extends SlashHandler<'ban'> {
|
|
739
|
+
* async execute() {
|
|
740
|
+
* // ...
|
|
741
|
+
* }
|
|
742
|
+
* }
|
|
743
|
+
* ```
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```ts
|
|
747
|
+
* // the base set from roles, on a gateway handler
|
|
748
|
+
* RequirePermissions([PermissionFlagsBits.BanMembers], { in: 'guild' });
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
export declare function RequirePermissions(scope: PermissionScope, options: RequirePermissionsOptions & {
|
|
752
|
+
in: 'guild';
|
|
753
|
+
}): Gate<GuildPermissionsContext, 'RequirePermissions'>;
|
|
754
|
+
export declare function RequirePermissions(scope: PermissionScope, options?: RequirePermissionsOptions & {
|
|
755
|
+
in?: 'channel';
|
|
756
|
+
}): Gate<GateContextBase, 'RequirePermissions'>;
|
|
757
|
+
/**
|
|
758
|
+
* Requires the bot to hold every permission in `scope`. Refuses outside a guild first, then when a
|
|
759
|
+
* permission is missing. The Administrator bit passes any scope.
|
|
760
|
+
*
|
|
761
|
+
* The default `'channel'` scope reads the bot's effective channel set (wire `app_permissions`), what
|
|
762
|
+
* Discord enforces in the invoked channel. The `'guild'` scope reads the bot's base set from roles and
|
|
763
|
+
* requires a {@link GuildPermissionsContext}, fitting a gateway handler only. The channel scope requires an
|
|
764
|
+
* {@link AppPermissionsContext}. An event handler takes `in: 'guild'`.
|
|
765
|
+
*
|
|
766
|
+
* @param scope - The permission flag bits the bot must all hold.
|
|
767
|
+
* @param options - Pick the scope with `in`. Replace a refusal with a Notice class as `notInGuild` or `missing`.
|
|
768
|
+
* @throws A **SeedcordError** when the `'guild'` scope runs and the bot's own member isn't cached.
|
|
769
|
+
*
|
|
770
|
+
* @see the `@Gated` decorator from your transport package
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```ts
|
|
774
|
+
* import { PermissionFlagsBits } from 'discord-api-types/v10';
|
|
775
|
+
*
|
|
776
|
+
* \@Gated(RequireBotPermissions([PermissionFlagsBits.ManageMessages]))
|
|
777
|
+
* \@SlashRoute('purge')
|
|
778
|
+
* class PurgeHandler extends SlashHandler<'purge'> {
|
|
779
|
+
* async execute() {
|
|
780
|
+
* // ...
|
|
781
|
+
* }
|
|
782
|
+
* }
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
export declare function RequireBotPermissions(scope: PermissionScope, options: RequireBotPermissionsOptions & {
|
|
786
|
+
in: 'guild';
|
|
787
|
+
}): Gate<GuildPermissionsContext, 'RequireBotPermissions'>;
|
|
788
|
+
export declare function RequireBotPermissions(scope: PermissionScope, options?: RequireBotPermissionsOptions & {
|
|
789
|
+
in?: 'channel';
|
|
790
|
+
}): Gate<AppPermissionsContext, 'RequireBotPermissions'>;
|
|
791
|
+
/**
|
|
792
|
+
* Requires the caller to hold `roleId`, read from the member's role ids. Refuses outside a guild first,
|
|
793
|
+
* then when the role is missing. Roles are guild-global, so there is no scope dimension.
|
|
794
|
+
*
|
|
795
|
+
* @param roleId - The role snowflake the caller must hold.
|
|
796
|
+
* @param options - Replace a refusal with a Notice class as `notInGuild` or `missingRole`.
|
|
797
|
+
*
|
|
798
|
+
* @see the `@Gated` decorator from your transport package
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```ts
|
|
802
|
+
* \@Gated(RequireRole('123456789012345678'))
|
|
803
|
+
* \@SlashRoute('vip')
|
|
804
|
+
* class VipHandler extends SlashHandler<'vip'> {
|
|
805
|
+
* async execute() {
|
|
806
|
+
* // ...
|
|
807
|
+
* }
|
|
808
|
+
* }
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
export declare function RequireRole(roleId: string, options?: RequireRoleOptions): Gate<GateContextBase, 'RequireRole'>;
|
|
667
812
|
//#endregion
|
|
668
813
|
//#region src/permissions/mergeRoles.d.ts
|
|
669
814
|
/**
|
|
@@ -1001,5 +1146,5 @@ export declare function buildKey(prefix: string, ...parts: readonly (string | nu
|
|
|
1001
1146
|
/** Package version */
|
|
1002
1147
|
export declare const version: string;
|
|
1003
1148
|
//#endregion
|
|
1004
|
-
export { type AnyCustomId, type AttemptedWrite, type AutocompleteOptions, BuilderComponent, type BuilderType, Bus, type CommandInfo, Commands, type ContextMenuInfo, ContextMenus, type ControlCosmetics, type ControlKey, type CooldownOptions, type CoreBase, CustomId, type CustomIdField, type CustomIdShape, type DecodedParams, type DecodedRoute, DispatchContext, type DispatchOutcome, type DispatchResult, type EffectGate, type EventDispatchResult, type FaultSource, type FieldOptions, type Gate, type GateContextBase, type GateNoticeOptions, type Generated, type GuildPermissionsContext, type GuildTarget, type HandlerOutcome, type HandlerResult, type InjectedCommandMap, type InjectedContextMenuMap, InteractionKind, type InteractionMiddlewareOptions, type ItemRender, type Kv, type KvCollection, type MessageContextMenuRegistry, type MiddlewareKind, type ModalLike, Notice, type PageRender, type PageSourceBase, type PageView, type PaginatorConfig, type PaginatorControls, type PermissionAssertion, type
|
|
1149
|
+
export { type AnyCustomId, type AppPermissionsContext, type AttemptedWrite, type AutocompleteOptions, BuilderComponent, type BuilderType, Bus, type CommandInfo, Commands, type ContextMenuInfo, ContextMenus, type ControlCosmetics, type ControlKey, type CooldownOptions, type CoreBase, CustomId, type CustomIdField, type CustomIdShape, type DecodedParams, type DecodedRoute, type DispatchContext, type DispatchOutcome, type DispatchResult, type EffectGate, type EventDispatchResult, type FaultSource, type FieldOptions, type Gate, type GateContextBase, type GateNoticeOptions, type Generated, type GuildPermissionsContext, type GuildTarget, type HandlerOutcome, type HandlerResult, type InjectedCommandMap, type InjectedContextMenuMap, InteractionKind, type InteractionMiddlewareOptions, type ItemRender, type Kv, type KvCollection, type MessageContextMenuRegistry, type MiddlewareKind, type ModalLike, Notice, type NoticeConstructor, type PageRender, type PageSourceBase, type PageView, type PaginatorConfig, type PaginatorControls, type PermissionAssertion, type PermissionNoticeConstructor, type PermissionScope, type PluginTypes, type REST, RegisterCommand, RegisterInteractionMiddleware, type RequireBotPermissionsOptions, type RequirePermissionsOptions, type RequireRoleOptions, type RequiredOf, ResolvedEmoji, type ResponseAttempt, type ResponseFailed, type ResponseOutcome, type ResponseSent, RowComponent, type RowType, ShutdownPhase, type SlashRegistry, StartupPhase, Subscribe, type SubscribeOptions, Subscriber, type SubscriptionData, type SubscriptionKey, type Subscriptions, type UserContextMenuRegistry, type WebhookFile, WebhookLog, type WebhookReport, WebhookUrl, decodeFor, defineEffectGate, defineGate, prefixOf, setCustomIdErrors };
|
|
1005
1150
|
//# sourceMappingURL=index.d.mts.map
|