@seedcord/core 0.1.0-next.4 → 0.1.0-next.6
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/{CustomId--QizzBOn.d.mts → AutocompleteOptions-eKhIe6Qt.d.mts} +496 -163
- package/dist/Plugin-C2-VHrsX.cjs +114 -0
- package/dist/Plugin-C2-VHrsX.cjs.map +1 -0
- package/dist/Plugin-CNyRKDHT.d.mts +226 -0
- package/dist/Plugin-PcdPjAzc.mjs +97 -0
- package/dist/Plugin-PcdPjAzc.mjs.map +1 -0
- package/dist/devChannel-CQU7hq7Q.mjs +14 -0
- package/dist/devChannel-CQU7hq7Q.mjs.map +1 -0
- package/dist/devChannel-CoCmAVDx.cjs +26 -0
- package/dist/devChannel-CoCmAVDx.cjs.map +1 -0
- package/dist/index.cjs +239 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +182 -25
- package/dist/index.mjs +199 -79
- package/dist/index.mjs.map +1 -1
- package/dist/internal.index.cjs +463 -57
- package/dist/internal.index.cjs.map +1 -1
- package/dist/internal.index.d.mts +146 -28
- package/dist/internal.index.mjs +415 -29
- package/dist/internal.index.mjs.map +1 -1
- package/dist/is-never-Ddaba1Su.d.mts +58 -0
- package/dist/node-internal.index.cjs +645 -0
- package/dist/node-internal.index.cjs.map +1 -0
- package/dist/node-internal.index.d.cts +1 -0
- package/dist/node-internal.index.d.mts +2352 -0
- package/dist/node-internal.index.mjs +636 -0
- package/dist/node-internal.index.mjs.map +1 -0
- package/dist/{CustomId-DV7daU7r.cjs → permissions-DSW_EZfN.cjs} +448 -89
- package/dist/permissions-DSW_EZfN.cjs.map +1 -0
- package/dist/{CustomId-epJayEGO.mjs → permissions-RVCBhL2n.mjs} +341 -90
- package/dist/permissions-RVCBhL2n.mjs.map +1 -0
- package/dist/phases-BfpAG6w3.mjs +31 -0
- package/dist/phases-BfpAG6w3.mjs.map +1 -0
- package/dist/phases-C_BGNyVo.cjs +43 -0
- package/dist/phases-C_BGNyVo.cjs.map +1 -0
- package/dist/plugin.index.cjs +4 -0
- package/dist/plugin.index.d.cts +1 -0
- package/dist/plugin.index.d.mts +3 -0
- package/dist/plugin.index.mjs +3 -0
- package/package.json +32 -10
- package/dist/CustomId-DV7daU7r.cjs.map +0 -1
- package/dist/CustomId-epJayEGO.mjs.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
require("reflect-metadata");
|
|
1
2
|
let _seedcord_errors = require("@seedcord/errors");
|
|
2
3
|
let _seedcord_errors_internal = require("@seedcord/errors/internal");
|
|
3
|
-
let _seedcord_utils = require("@seedcord/utils");
|
|
4
|
-
let _discordjs_builders = require("@discordjs/builders");
|
|
5
4
|
let discord_api_types_v10 = require("discord-api-types/v10");
|
|
5
|
+
let _discordjs_builders = require("@discordjs/builders");
|
|
6
|
+
let _seedcord_utils = require("@seedcord/utils");
|
|
6
7
|
|
|
7
8
|
//#region src/metadataKeys.ts
|
|
8
9
|
let InteractionRoutes = /* @__PURE__ */ function(InteractionRoutes) {
|
|
@@ -38,6 +39,7 @@ const EventMetadataKey = Symbol("seedcord:event:metadata");
|
|
|
38
39
|
const CommandMetadataKey = Symbol("seedcord:command:metadata");
|
|
39
40
|
const GatedMetadataKey = Symbol("seedcord:gated:metadata");
|
|
40
41
|
const SubscribeMetadataKey = Symbol("seedcord:subscribe:metadata");
|
|
42
|
+
const WebhookUrlMetadataKey = Symbol("seedcord:webhookUrl:metadata");
|
|
41
43
|
|
|
42
44
|
//#endregion
|
|
43
45
|
//#region src/stops/Notice.ts
|
|
@@ -314,92 +316,6 @@ var NoticeCard = class extends BuilderComponent {
|
|
|
314
316
|
}
|
|
315
317
|
};
|
|
316
318
|
|
|
317
|
-
//#endregion
|
|
318
|
-
//#region src/notices/index.ts
|
|
319
|
-
var GateNotice = class extends Notice {
|
|
320
|
-
render() {
|
|
321
|
-
return { components: [new NoticeCard(this.message).component] };
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
var NotOwner = class extends GateNotice {
|
|
325
|
-
constructor(message = "Only the bot owner can use this.") {
|
|
326
|
-
super(message);
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
var NotInGuild = class extends GateNotice {
|
|
330
|
-
constructor(message = "This can only be used in a server.") {
|
|
331
|
-
super(message);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
var NotInDm = class extends GateNotice {
|
|
335
|
-
constructor(message = "This can only be used in a direct message.") {
|
|
336
|
-
super(message);
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
var OnCooldown = class extends GateNotice {
|
|
340
|
-
resetAt;
|
|
341
|
-
constructor(resetAt, message) {
|
|
342
|
-
super(message ?? `You are doing that too fast. Try again <t:${(0, _seedcord_utils.toEpochSeconds)(resetAt)}:R>.`);
|
|
343
|
-
this.resetAt = resetAt;
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
var NotAllowed = class extends Notice {
|
|
347
|
-
constructor() {
|
|
348
|
-
super("not allowed");
|
|
349
|
-
}
|
|
350
|
-
render() {
|
|
351
|
-
return { components: [new NoticeCard("You are not allowed to use this command.").component] };
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
var NeedsAny = class extends Notice {
|
|
355
|
-
summaries;
|
|
356
|
-
constructor(summaries) {
|
|
357
|
-
super("not allowed");
|
|
358
|
-
this.summaries = summaries;
|
|
359
|
-
}
|
|
360
|
-
render() {
|
|
361
|
-
return { components: [new NoticeCard(`You need any of:\n${this.summaries.map((summary) => `• ${summary}`).join("\n")}`).component] };
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
//#endregion
|
|
366
|
-
//#region src/gates/effects.ts
|
|
367
|
-
const commitQueues = /* @__PURE__ */ new WeakMap();
|
|
368
|
-
function isEffectGate(gate) {
|
|
369
|
-
return typeof gate.commit === "function";
|
|
370
|
-
}
|
|
371
|
-
async function runCheck(gate, ctx) {
|
|
372
|
-
await gate.check(ctx);
|
|
373
|
-
if (!isEffectGate(gate)) return;
|
|
374
|
-
let queue = commitQueues.get(ctx);
|
|
375
|
-
if (!queue) {
|
|
376
|
-
queue = [];
|
|
377
|
-
commitQueues.set(ctx, queue);
|
|
378
|
-
}
|
|
379
|
-
queue.push(() => gate.commit(ctx));
|
|
380
|
-
}
|
|
381
|
-
async function runCommits(ctx) {
|
|
382
|
-
const queue = commitQueues.get(ctx);
|
|
383
|
-
if (!queue) return;
|
|
384
|
-
for (const commit of queue) await commit();
|
|
385
|
-
}
|
|
386
|
-
function discardCommits(ctx) {
|
|
387
|
-
commitQueues.delete(ctx);
|
|
388
|
-
}
|
|
389
|
-
function markCommits(ctx) {
|
|
390
|
-
return commitQueues.get(ctx)?.length ?? 0;
|
|
391
|
-
}
|
|
392
|
-
function rollbackCommits(ctx, mark) {
|
|
393
|
-
const queue = commitQueues.get(ctx);
|
|
394
|
-
if (queue && queue.length > mark) queue.length = mark;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
//#endregion
|
|
398
|
-
//#region src/gates/catalog/options.ts
|
|
399
|
-
function pickNotice(options, makeDefault) {
|
|
400
|
-
return options?.notice ?? makeDefault(options?.message);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
319
|
//#endregion
|
|
404
320
|
//#region src/customId/Errors.ts
|
|
405
321
|
/**
|
|
@@ -815,6 +731,341 @@ function decodeFor(defs, wire) {
|
|
|
815
731
|
};
|
|
816
732
|
}
|
|
817
733
|
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/customId/routing.ts
|
|
736
|
+
/**
|
|
737
|
+
* The route decorators store a handler's customId definitions here so the component base can decode
|
|
738
|
+
* against them at runtime.
|
|
739
|
+
*
|
|
740
|
+
* @internal
|
|
741
|
+
*/
|
|
742
|
+
const ComponentDefsKey = Symbol("seedcord:customId:componentDefs");
|
|
743
|
+
/**
|
|
744
|
+
* Throws `CustomIdHandlerRouteMissing` when the class has no stored defs. A drifted or corrupt wire
|
|
745
|
+
* throws `StaleCustomId` or `InvalidCustomId`.
|
|
746
|
+
*
|
|
747
|
+
* @internal
|
|
748
|
+
*/
|
|
749
|
+
function decodeComponentRoute(handlerClass, wire) {
|
|
750
|
+
const defs = Reflect.getMetadata(ComponentDefsKey, handlerClass);
|
|
751
|
+
if (!defs) throw new _seedcord_errors_internal.SeedcordError(_seedcord_errors.SeedcordErrorCode.CustomIdHandlerRouteMissing, [handlerClass.name]);
|
|
752
|
+
return decodeFor(defs, wire);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region src/decorators/interactionRoutes.ts
|
|
757
|
+
/** The select menu kinds the select route decorators take. */
|
|
758
|
+
let SelectMenuKind = /* @__PURE__ */ function(SelectMenuKind) {
|
|
759
|
+
SelectMenuKind["String"] = "string";
|
|
760
|
+
SelectMenuKind["User"] = "user";
|
|
761
|
+
SelectMenuKind["Role"] = "role";
|
|
762
|
+
SelectMenuKind["Channel"] = "channel";
|
|
763
|
+
SelectMenuKind["Mentionable"] = "mentionable";
|
|
764
|
+
return SelectMenuKind;
|
|
765
|
+
}({});
|
|
766
|
+
function areRoutes(routes) {
|
|
767
|
+
return Array.isArray(routes) && routes.every((route) => typeof route === "string");
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Every stored route kind and its route strings on a decorated constructor. The build's manifest
|
|
771
|
+
* emitter reads the same pairs.
|
|
772
|
+
*/
|
|
773
|
+
function interactionRoutesOf(constructor) {
|
|
774
|
+
const pairs = [];
|
|
775
|
+
for (const route of Object.values(InteractionRoutes)) {
|
|
776
|
+
const meta = Reflect.getMetadata(InteractionRouteKeys[route], constructor);
|
|
777
|
+
if (areRoutes(meta)) pairs.push([route, meta]);
|
|
778
|
+
}
|
|
779
|
+
return pairs;
|
|
780
|
+
}
|
|
781
|
+
function storeInteractionRoute(route, routes, constructor) {
|
|
782
|
+
const key = InteractionRouteKeys[route];
|
|
783
|
+
const saved = Reflect.getMetadata(key, constructor);
|
|
784
|
+
const existing = areRoutes(saved) ? saved : [];
|
|
785
|
+
const toStore = typeof routes === "string" ? [routes] : routes;
|
|
786
|
+
Reflect.defineMetadata(key, [...existing, ...toStore], constructor);
|
|
787
|
+
Reflect.defineMetadata(InteractionMetadataKey, true, constructor);
|
|
788
|
+
}
|
|
789
|
+
function storeComponentRoute(route, defs, constructor) {
|
|
790
|
+
storeInteractionRoute(route, defs.map((def) => def.prefix), constructor);
|
|
791
|
+
Reflect.defineMetadata(ComponentDefsKey, defs, constructor);
|
|
792
|
+
}
|
|
793
|
+
const SELECT_ROUTES = {
|
|
794
|
+
["string"]: "stringMenu",
|
|
795
|
+
["user"]: "userMenu",
|
|
796
|
+
["role"]: "roleMenu",
|
|
797
|
+
["channel"]: "channelMenu",
|
|
798
|
+
["mentionable"]: "mentionableMenu"
|
|
799
|
+
};
|
|
800
|
+
function selectMenuRouteOf(kind) {
|
|
801
|
+
return SELECT_ROUTES[kind];
|
|
802
|
+
}
|
|
803
|
+
function contextMenuRouteOf(kind) {
|
|
804
|
+
return kind === discord_api_types_v10.ApplicationCommandType.User ? "userContextMenu" : "messageContextMenu";
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region src/gates/Gate.ts
|
|
809
|
+
/**
|
|
810
|
+
* Builds a {@link Gate} from a check. The check refuses by throwing a Notice or a Silence and passes
|
|
811
|
+
* by returning. The required context is inferred from `ctx`, so annotate it as narrowly as the fields
|
|
812
|
+
* the check reads. No annotation defaults to {@link GateContextBase}, an agnostic gate that fits every
|
|
813
|
+
* handler.
|
|
814
|
+
*
|
|
815
|
+
* @typeParam Name - The gate's name captured as a literal, so a mismatch error can name the gate.
|
|
816
|
+
* @typeParam Ctx - The context the check reads, inferred from the `ctx` annotation.
|
|
817
|
+
*
|
|
818
|
+
* @param name - The gate's name, used in mismatch errors.
|
|
819
|
+
* @param fn - The check, which refuses by throwing a Notice or a Silence and passes by returning.
|
|
820
|
+
*
|
|
821
|
+
* @see {@link defineEffectGate}
|
|
822
|
+
* @see the `@Gated` decorator from `seedcord`
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* ```ts
|
|
826
|
+
* // a gate factory that takes its own option and closes over it
|
|
827
|
+
* function MinRoles(min: number): Gate<GateContextBase, 'MinRoles'> {
|
|
828
|
+
* return defineGate('MinRoles', (ctx) => {
|
|
829
|
+
* if (ctx.memberRoleIds.length < min) throw new NotEnoughRoles(min);
|
|
830
|
+
* });
|
|
831
|
+
* }
|
|
832
|
+
* ```
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* ```ts
|
|
836
|
+
* // agnostic gate (no ctx annotation): fits any handler
|
|
837
|
+
* const Owner = defineGate('owner', (ctx) => {
|
|
838
|
+
* if (!ctx.userId) throw new NotOwner();
|
|
839
|
+
* });
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
function defineGate(name, fn) {
|
|
843
|
+
return {
|
|
844
|
+
name,
|
|
845
|
+
check: async (ctx) => fn(ctx)
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Builds an {@link EffectGate} from a `check` and a `commit`. `check` peeks and refuses by throwing, and
|
|
850
|
+
* `commit` applies the side effect, running only once the whole gate set passes so a later refusal never
|
|
851
|
+
* commits. In an `or`, a refusing arm's queued commit is rolled back. This is how {@link Cooldown} peeks
|
|
852
|
+
* in `check` and charges the slot in `commit`.
|
|
853
|
+
*
|
|
854
|
+
* @typeParam Name - The gate's name captured as a literal, so a mismatch error can name the gate.
|
|
855
|
+
* @typeParam Ctx - The context both `check` and `commit` read, inferred from the `ctx` annotation.
|
|
856
|
+
*
|
|
857
|
+
* @param name - The gate's name, used in mismatch errors.
|
|
858
|
+
* @param check - Peeks and refuses by throwing, without applying the side effect.
|
|
859
|
+
* @param commit - Applies the side effect, running only after the whole gate set passes.
|
|
860
|
+
*
|
|
861
|
+
* @see {@link defineGate}
|
|
862
|
+
* @see the `@Gated` decorator from `seedcord`
|
|
863
|
+
* @see {@link Cooldown}
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* ```ts
|
|
867
|
+
* // an effect-gate factory that takes its own limit and closes over it
|
|
868
|
+
* function UsesPerDay(max: number): EffectGate<GateContextBase, 'UsesPerDay'> {
|
|
869
|
+
* return defineEffectGate(
|
|
870
|
+
* 'UsesPerDay',
|
|
871
|
+
* (ctx) => {
|
|
872
|
+
* // peek and refuse by throwing, do not mutate yet
|
|
873
|
+
* if (usedToday(ctx.userId) >= max) throw new OutOfUsesNotice(max);
|
|
874
|
+
* },
|
|
875
|
+
* (ctx) => {
|
|
876
|
+
* // runs only after the whole gate set passes
|
|
877
|
+
* recordUse(ctx.userId);
|
|
878
|
+
* }
|
|
879
|
+
* );
|
|
880
|
+
* }
|
|
881
|
+
* ```
|
|
882
|
+
*/
|
|
883
|
+
function defineEffectGate(name, check, commit) {
|
|
884
|
+
return {
|
|
885
|
+
name,
|
|
886
|
+
check: async (ctx) => check(ctx),
|
|
887
|
+
commit: async (ctx) => commit(ctx)
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
//#endregion
|
|
892
|
+
//#region src/notices/index.ts
|
|
893
|
+
var GateNotice = class extends Notice {
|
|
894
|
+
render() {
|
|
895
|
+
return { components: [new NoticeCard(this.message).component] };
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
var NotOwner = class extends GateNotice {
|
|
899
|
+
constructor(message = "Only the bot owner can use this.") {
|
|
900
|
+
super(message);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
var NotInGuild = class extends GateNotice {
|
|
904
|
+
constructor(message = "This can only be used in a server.") {
|
|
905
|
+
super(message);
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
var NotInDm = class extends GateNotice {
|
|
909
|
+
constructor(message = "This can only be used in a direct message.") {
|
|
910
|
+
super(message);
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
var OnCooldown = class extends GateNotice {
|
|
914
|
+
resetAt;
|
|
915
|
+
constructor(resetAt, message) {
|
|
916
|
+
super(message ?? `You are doing that too fast. Try again <t:${(0, _seedcord_utils.toEpochSeconds)(resetAt)}:R>.`);
|
|
917
|
+
this.resetAt = resetAt;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
var NotAllowed = class extends Notice {
|
|
921
|
+
constructor() {
|
|
922
|
+
super("not allowed");
|
|
923
|
+
}
|
|
924
|
+
render() {
|
|
925
|
+
return { components: [new NoticeCard("You are not allowed to use this command.").component] };
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
var NeedsAny = class extends Notice {
|
|
929
|
+
summaries;
|
|
930
|
+
constructor(summaries) {
|
|
931
|
+
super("not allowed");
|
|
932
|
+
this.summaries = summaries;
|
|
933
|
+
}
|
|
934
|
+
render() {
|
|
935
|
+
return { components: [new NoticeCard(`You need any of:\n${this.summaries.map((summary) => `• ${summary}`).join("\n")}`).component] };
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
var MissingRole = class extends GateNotice {
|
|
939
|
+
constructor(message, roleId) {
|
|
940
|
+
super(message ?? (roleId ? `You need the <@&${roleId}> role to use this.` : "You do not have the required role."));
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
var MissingPermissions = class extends Notice {
|
|
944
|
+
subject;
|
|
945
|
+
missingPerms;
|
|
946
|
+
customLead;
|
|
947
|
+
constructor(message, subject, missingPerms) {
|
|
948
|
+
super(message ?? "A required permission is missing.");
|
|
949
|
+
this.subject = subject;
|
|
950
|
+
this.missingPerms = missingPerms;
|
|
951
|
+
this.customLead = message;
|
|
952
|
+
}
|
|
953
|
+
render() {
|
|
954
|
+
const bullets = this.missingPerms.map((perm) => `• ${perm}`).join("\n");
|
|
955
|
+
return { components: [new NoticeCard(`${this.customLead ?? `${this.subject === null ? "You are" : `${this.subject} is`} missing the following permission entries:`}\n\n${bullets}`).component] };
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
//#endregion
|
|
960
|
+
//#region src/gates/effects.ts
|
|
961
|
+
const commitQueues = /* @__PURE__ */ new WeakMap();
|
|
962
|
+
function isEffectGate(gate) {
|
|
963
|
+
return typeof gate.commit === "function";
|
|
964
|
+
}
|
|
965
|
+
async function runCheck(gate, ctx) {
|
|
966
|
+
await gate.check(ctx);
|
|
967
|
+
if (!isEffectGate(gate)) return;
|
|
968
|
+
let queue = commitQueues.get(ctx);
|
|
969
|
+
if (!queue) {
|
|
970
|
+
queue = [];
|
|
971
|
+
commitQueues.set(ctx, queue);
|
|
972
|
+
}
|
|
973
|
+
queue.push(() => gate.commit(ctx));
|
|
974
|
+
}
|
|
975
|
+
async function runCommits(ctx) {
|
|
976
|
+
const queue = commitQueues.get(ctx);
|
|
977
|
+
if (!queue) return;
|
|
978
|
+
for (const commit of queue) await commit();
|
|
979
|
+
}
|
|
980
|
+
function discardCommits(ctx) {
|
|
981
|
+
commitQueues.delete(ctx);
|
|
982
|
+
}
|
|
983
|
+
function markCommits(ctx) {
|
|
984
|
+
return commitQueues.get(ctx)?.length ?? 0;
|
|
985
|
+
}
|
|
986
|
+
function rollbackCommits(ctx, mark) {
|
|
987
|
+
const queue = commitQueues.get(ctx);
|
|
988
|
+
if (queue && queue.length > mark) queue.length = mark;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
//#endregion
|
|
992
|
+
//#region src/gates/catalog/options.ts
|
|
993
|
+
function pickNotice(options, makeDefault) {
|
|
994
|
+
return options?.notice ?? makeDefault(options?.message);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
//#endregion
|
|
998
|
+
//#region src/gates/catalog/permissions.ts
|
|
999
|
+
/** Permission bit to its prettified human-readable name, for the missing-permission refusal. */
|
|
1000
|
+
const PermissionNames = new Map(Object.entries(discord_api_types_v10.PermissionFlagsBits).map(([key, bit]) => [bit, (0, _seedcord_utils.prettify)(key)]));
|
|
1001
|
+
const ADMINISTRATOR = discord_api_types_v10.PermissionFlagsBits.Administrator;
|
|
1002
|
+
const MEMBER_CHECK = {
|
|
1003
|
+
unresolved: "Your server member data could not be resolved. Try again.",
|
|
1004
|
+
subject: null
|
|
1005
|
+
};
|
|
1006
|
+
const BOT_CHECK = {
|
|
1007
|
+
unresolved: "The bot's permissions could not be resolved. Try again.",
|
|
1008
|
+
subject: "The bot"
|
|
1009
|
+
};
|
|
1010
|
+
function hasAll(held, scope) {
|
|
1011
|
+
if ((held & ADMINISTRATOR) === ADMINISTRATOR) return true;
|
|
1012
|
+
return scope.every((bit) => (held & bit) === bit);
|
|
1013
|
+
}
|
|
1014
|
+
function missingNames(held, scope) {
|
|
1015
|
+
return scope.reduce((names, bit) => {
|
|
1016
|
+
if ((held & bit) !== bit) names.push(PermissionNames.get(bit) ?? String(bit));
|
|
1017
|
+
return names;
|
|
1018
|
+
}, []);
|
|
1019
|
+
}
|
|
1020
|
+
function refusePermissions(held, scope, options, guildId, kind) {
|
|
1021
|
+
if (held === null) throw pickNotice(options?.notInGuild, (message) => new NotInGuild(message ?? (guildId ? kind.unresolved : void 0)));
|
|
1022
|
+
if (hasAll(held, scope)) return;
|
|
1023
|
+
throw pickNotice(options?.missing, (message) => new MissingPermissions(message, kind.subject, missingNames(held, scope)));
|
|
1024
|
+
}
|
|
1025
|
+
function RequirePermissions(scope, options) {
|
|
1026
|
+
if (options?.in === "guild") return defineGate("RequirePermissions", (ctx) => {
|
|
1027
|
+
refusePermissions(ctx.memberGuildPermissions, scope, options, ctx.guildId, MEMBER_CHECK);
|
|
1028
|
+
});
|
|
1029
|
+
return defineGate("RequirePermissions", (ctx) => {
|
|
1030
|
+
refusePermissions(ctx.memberPermissions, scope, options, ctx.guildId, MEMBER_CHECK);
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
function RequireBotPermissions(scope, options) {
|
|
1034
|
+
if (options?.in === "guild") return defineGate("RequireBotPermissions", (ctx) => {
|
|
1035
|
+
refusePermissions(ctx.appGuildPermissions, scope, options, ctx.guildId, BOT_CHECK);
|
|
1036
|
+
});
|
|
1037
|
+
return defineGate("RequireBotPermissions", (ctx) => {
|
|
1038
|
+
refusePermissions(ctx.appPermissions, scope, options, ctx.guildId, BOT_CHECK);
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Requires the caller to hold `roleId`, read from the member's role ids. Refuses outside a guild first,
|
|
1043
|
+
* then when the role is missing. Roles are guild-global, so there is no scope dimension.
|
|
1044
|
+
*
|
|
1045
|
+
* @param roleId - The role snowflake the caller must hold.
|
|
1046
|
+
* @param options - Override each refusal, the outside-guild one with `notInGuild` and the missing-role one with `missingRole`.
|
|
1047
|
+
*
|
|
1048
|
+
* @see the `@Gated` decorator from `seedcord`
|
|
1049
|
+
*
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```ts
|
|
1052
|
+
* \@Gated(RequireRole('123456789012345678'))
|
|
1053
|
+
* \@SlashRoute('vip')
|
|
1054
|
+
* class VipHandler extends SlashHandler<'vip'> {
|
|
1055
|
+
* async execute() {
|
|
1056
|
+
* // ...
|
|
1057
|
+
* }
|
|
1058
|
+
* }
|
|
1059
|
+
* ```
|
|
1060
|
+
*/
|
|
1061
|
+
function RequireRole(roleId, options) {
|
|
1062
|
+
return defineGate("RequireRole", (ctx) => {
|
|
1063
|
+
if (!ctx.guildId) throw pickNotice(options?.notInGuild, (message) => new NotInGuild(message));
|
|
1064
|
+
if (ctx.memberRoleIds.includes(roleId)) return;
|
|
1065
|
+
throw pickNotice(options?.missingRole, (message) => new MissingRole(message, roleId));
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
|
|
818
1069
|
//#endregion
|
|
819
1070
|
Object.defineProperty(exports, 'BuilderComponent', {
|
|
820
1071
|
enumerable: true,
|
|
@@ -828,6 +1079,12 @@ Object.defineProperty(exports, 'CommandMetadataKey', {
|
|
|
828
1079
|
return CommandMetadataKey;
|
|
829
1080
|
}
|
|
830
1081
|
});
|
|
1082
|
+
Object.defineProperty(exports, 'ComponentDefsKey', {
|
|
1083
|
+
enumerable: true,
|
|
1084
|
+
get: function () {
|
|
1085
|
+
return ComponentDefsKey;
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
831
1088
|
Object.defineProperty(exports, 'CustomId', {
|
|
832
1089
|
enumerable: true,
|
|
833
1090
|
get: function () {
|
|
@@ -876,6 +1133,18 @@ Object.defineProperty(exports, 'MiddlewareMetadataKey', {
|
|
|
876
1133
|
return MiddlewareMetadataKey;
|
|
877
1134
|
}
|
|
878
1135
|
});
|
|
1136
|
+
Object.defineProperty(exports, 'MissingPermissions', {
|
|
1137
|
+
enumerable: true,
|
|
1138
|
+
get: function () {
|
|
1139
|
+
return MissingPermissions;
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
Object.defineProperty(exports, 'MissingRole', {
|
|
1143
|
+
enumerable: true,
|
|
1144
|
+
get: function () {
|
|
1145
|
+
return MissingRole;
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
879
1148
|
Object.defineProperty(exports, 'NeedsAny', {
|
|
880
1149
|
enumerable: true,
|
|
881
1150
|
get: function () {
|
|
@@ -924,30 +1193,102 @@ Object.defineProperty(exports, 'OnCooldown', {
|
|
|
924
1193
|
return OnCooldown;
|
|
925
1194
|
}
|
|
926
1195
|
});
|
|
1196
|
+
Object.defineProperty(exports, 'PermissionNames', {
|
|
1197
|
+
enumerable: true,
|
|
1198
|
+
get: function () {
|
|
1199
|
+
return PermissionNames;
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
Object.defineProperty(exports, 'RequireBotPermissions', {
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
get: function () {
|
|
1205
|
+
return RequireBotPermissions;
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
Object.defineProperty(exports, 'RequirePermissions', {
|
|
1209
|
+
enumerable: true,
|
|
1210
|
+
get: function () {
|
|
1211
|
+
return RequirePermissions;
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
Object.defineProperty(exports, 'RequireRole', {
|
|
1215
|
+
enumerable: true,
|
|
1216
|
+
get: function () {
|
|
1217
|
+
return RequireRole;
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
927
1220
|
Object.defineProperty(exports, 'RowComponent', {
|
|
928
1221
|
enumerable: true,
|
|
929
1222
|
get: function () {
|
|
930
1223
|
return RowComponent;
|
|
931
1224
|
}
|
|
932
1225
|
});
|
|
1226
|
+
Object.defineProperty(exports, 'SelectMenuKind', {
|
|
1227
|
+
enumerable: true,
|
|
1228
|
+
get: function () {
|
|
1229
|
+
return SelectMenuKind;
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
933
1232
|
Object.defineProperty(exports, 'SubscribeMetadataKey', {
|
|
934
1233
|
enumerable: true,
|
|
935
1234
|
get: function () {
|
|
936
1235
|
return SubscribeMetadataKey;
|
|
937
1236
|
}
|
|
938
1237
|
});
|
|
1238
|
+
Object.defineProperty(exports, 'WebhookUrlMetadataKey', {
|
|
1239
|
+
enumerable: true,
|
|
1240
|
+
get: function () {
|
|
1241
|
+
return WebhookUrlMetadataKey;
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
Object.defineProperty(exports, 'areRoutes', {
|
|
1245
|
+
enumerable: true,
|
|
1246
|
+
get: function () {
|
|
1247
|
+
return areRoutes;
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
Object.defineProperty(exports, 'contextMenuRouteOf', {
|
|
1251
|
+
enumerable: true,
|
|
1252
|
+
get: function () {
|
|
1253
|
+
return contextMenuRouteOf;
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
Object.defineProperty(exports, 'decodeComponentRoute', {
|
|
1257
|
+
enumerable: true,
|
|
1258
|
+
get: function () {
|
|
1259
|
+
return decodeComponentRoute;
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
939
1262
|
Object.defineProperty(exports, 'decodeFor', {
|
|
940
1263
|
enumerable: true,
|
|
941
1264
|
get: function () {
|
|
942
1265
|
return decodeFor;
|
|
943
1266
|
}
|
|
944
1267
|
});
|
|
1268
|
+
Object.defineProperty(exports, 'defineEffectGate', {
|
|
1269
|
+
enumerable: true,
|
|
1270
|
+
get: function () {
|
|
1271
|
+
return defineEffectGate;
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
Object.defineProperty(exports, 'defineGate', {
|
|
1275
|
+
enumerable: true,
|
|
1276
|
+
get: function () {
|
|
1277
|
+
return defineGate;
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
945
1280
|
Object.defineProperty(exports, 'discardCommits', {
|
|
946
1281
|
enumerable: true,
|
|
947
1282
|
get: function () {
|
|
948
1283
|
return discardCommits;
|
|
949
1284
|
}
|
|
950
1285
|
});
|
|
1286
|
+
Object.defineProperty(exports, 'interactionRoutesOf', {
|
|
1287
|
+
enumerable: true,
|
|
1288
|
+
get: function () {
|
|
1289
|
+
return interactionRoutesOf;
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
951
1292
|
Object.defineProperty(exports, 'markCommits', {
|
|
952
1293
|
enumerable: true,
|
|
953
1294
|
get: function () {
|
|
@@ -984,10 +1325,28 @@ Object.defineProperty(exports, 'runCommits', {
|
|
|
984
1325
|
return runCommits;
|
|
985
1326
|
}
|
|
986
1327
|
});
|
|
1328
|
+
Object.defineProperty(exports, 'selectMenuRouteOf', {
|
|
1329
|
+
enumerable: true,
|
|
1330
|
+
get: function () {
|
|
1331
|
+
return selectMenuRouteOf;
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
987
1334
|
Object.defineProperty(exports, 'setBotColor', {
|
|
988
1335
|
enumerable: true,
|
|
989
1336
|
get: function () {
|
|
990
1337
|
return setBotColor;
|
|
991
1338
|
}
|
|
992
1339
|
});
|
|
993
|
-
|
|
1340
|
+
Object.defineProperty(exports, 'storeComponentRoute', {
|
|
1341
|
+
enumerable: true,
|
|
1342
|
+
get: function () {
|
|
1343
|
+
return storeComponentRoute;
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
Object.defineProperty(exports, 'storeInteractionRoute', {
|
|
1347
|
+
enumerable: true,
|
|
1348
|
+
get: function () {
|
|
1349
|
+
return storeInteractionRoute;
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
//# sourceMappingURL=permissions-DSW_EZfN.cjs.map
|