@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
|
+
import "reflect-metadata";
|
|
1
2
|
import { SeedcordErrorCode } from "@seedcord/errors";
|
|
2
3
|
import { SeedcordError, SeedcordRangeError, SeedcordTypeError } from "@seedcord/errors/internal";
|
|
3
|
-
import {
|
|
4
|
+
import { ApplicationCommandType, InteractionContextType, PermissionFlagsBits } from "discord-api-types/v10";
|
|
4
5
|
import { ActionRowBuilder, ButtonBuilder, ChannelSelectMenuBuilder, CheckboxBuilder, CheckboxGroupBuilder, CheckboxGroupOptionBuilder, ContainerBuilder, ContextMenuCommandBuilder, EmbedBuilder, FileBuilder, FileUploadBuilder, LabelBuilder, MediaGalleryBuilder, MentionableSelectMenuBuilder, ModalBuilder, RadioGroupBuilder, RadioGroupOptionBuilder, RoleSelectMenuBuilder, SectionBuilder, SeparatorBuilder, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, TextDisplayBuilder, TextInputBuilder, UserSelectMenuBuilder } from "@discordjs/builders";
|
|
5
|
-
import {
|
|
6
|
+
import { prettify, toEpochSeconds } from "@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:${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
|
/**
|
|
@@ -816,5 +732,340 @@ function decodeFor(defs, wire) {
|
|
|
816
732
|
}
|
|
817
733
|
|
|
818
734
|
//#endregion
|
|
819
|
-
|
|
820
|
-
|
|
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 SeedcordError(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 === 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:${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(PermissionFlagsBits).map(([key, bit]) => [bit, prettify(key)]));
|
|
1001
|
+
const ADMINISTRATOR = 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
|
+
|
|
1069
|
+
//#endregion
|
|
1070
|
+
export { decodeComponentRoute as A, EventMetadataKey as B, areRoutes as C, storeComponentRoute as D, selectMenuRouteOf as E, BuilderComponent as F, MiddlewareMetadataKey as G, InteractionMetadataKey as H, RowComponent as I, SubscribeMetadataKey as K, setBotColor as L, decodeFor as M, prefixOf as N, storeInteractionRoute as O, NoticeCard as P, Notice as R, SelectMenuKind as S, interactionRoutesOf as T, InteractionRouteKeys as U, GatedMetadataKey as V, InteractionRoutes as W, NotInGuild as _, pickNotice as a, defineEffectGate as b, rollbackCommits as c, GateNotice as d, MissingPermissions as f, NotInDm as g, NotAllowed as h, RequireRole as i, CustomId as j, ComponentDefsKey as k, runCheck as l, NeedsAny as m, RequireBotPermissions as n, discardCommits as o, MissingRole as p, WebhookUrlMetadataKey as q, RequirePermissions as r, markCommits as s, PermissionNames as t, runCommits as u, NotOwner as v, contextMenuRouteOf as w, defineGate as x, OnCooldown as y, CommandMetadataKey as z };
|
|
1071
|
+
//# sourceMappingURL=permissions-RVCBhL2n.mjs.map
|