@seedcord/core 0.1.0-next.4 → 0.1.0-next.5
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-eB87SZ4a.d.mts} +494 -154
- package/dist/index.cjs +236 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +181 -25
- package/dist/index.mjs +198 -79
- package/dist/index.mjs.map +1 -1
- package/dist/internal.index.cjs +461 -45
- package/dist/internal.index.cjs.map +1 -1
- package/dist/internal.index.d.mts +145 -28
- package/dist/internal.index.mjs +417 -20
- package/dist/internal.index.mjs.map +1 -1
- package/dist/is-never-Ddaba1Su.d.mts +58 -0
- package/dist/node.index.cjs +521 -0
- package/dist/node.index.cjs.map +1 -0
- package/dist/node.index.d.cts +1 -0
- package/dist/node.index.d.mts +2391 -0
- package/dist/node.index.mjs +513 -0
- package/dist/node.index.mjs.map +1 -0
- package/dist/{CustomId-DV7daU7r.cjs → permissions-DQL5ViZn.cjs} +430 -89
- package/dist/permissions-DQL5ViZn.cjs.map +1 -0
- package/dist/{CustomId-epJayEGO.mjs → permissions-SokZLJMj.mjs} +329 -90
- package/dist/permissions-SokZLJMj.mjs.map +1 -0
- package/package.json +20 -9
- 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,329 @@ 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
|
+
function storeInteractionRoute(route, routes, constructor) {
|
|
770
|
+
const key = InteractionRouteKeys[route];
|
|
771
|
+
const saved = Reflect.getMetadata(key, constructor);
|
|
772
|
+
const existing = areRoutes(saved) ? saved : [];
|
|
773
|
+
const toStore = typeof routes === "string" ? [routes] : routes;
|
|
774
|
+
Reflect.defineMetadata(key, [...existing, ...toStore], constructor);
|
|
775
|
+
Reflect.defineMetadata(InteractionMetadataKey, true, constructor);
|
|
776
|
+
}
|
|
777
|
+
function storeComponentRoute(route, defs, constructor) {
|
|
778
|
+
storeInteractionRoute(route, defs.map((def) => def.prefix), constructor);
|
|
779
|
+
Reflect.defineMetadata(ComponentDefsKey, defs, constructor);
|
|
780
|
+
}
|
|
781
|
+
const SELECT_ROUTES = {
|
|
782
|
+
["string"]: "stringMenu",
|
|
783
|
+
["user"]: "userMenu",
|
|
784
|
+
["role"]: "roleMenu",
|
|
785
|
+
["channel"]: "channelMenu",
|
|
786
|
+
["mentionable"]: "mentionableMenu"
|
|
787
|
+
};
|
|
788
|
+
function selectMenuRouteOf(kind) {
|
|
789
|
+
return SELECT_ROUTES[kind];
|
|
790
|
+
}
|
|
791
|
+
function contextMenuRouteOf(kind) {
|
|
792
|
+
return kind === discord_api_types_v10.ApplicationCommandType.User ? "userContextMenu" : "messageContextMenu";
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region src/gates/Gate.ts
|
|
797
|
+
/**
|
|
798
|
+
* Builds a {@link Gate} from a check. The check refuses by throwing a Notice or a Silence and passes
|
|
799
|
+
* by returning. The required context is inferred from `ctx`, so annotate it as narrowly as the fields
|
|
800
|
+
* the check reads. No annotation defaults to {@link GateContextBase}, an agnostic gate that fits every
|
|
801
|
+
* handler.
|
|
802
|
+
*
|
|
803
|
+
* @typeParam Name - The gate's name captured as a literal, so a mismatch error can name the gate.
|
|
804
|
+
* @typeParam Ctx - The context the check reads, inferred from the `ctx` annotation.
|
|
805
|
+
*
|
|
806
|
+
* @param name - The gate's name, used in mismatch errors.
|
|
807
|
+
* @param fn - The check, which refuses by throwing a Notice or a Silence and passes by returning.
|
|
808
|
+
*
|
|
809
|
+
* @see {@link defineEffectGate}
|
|
810
|
+
* @see the `@Gated` decorator from `seedcord`
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```ts
|
|
814
|
+
* // a gate factory that takes its own option and closes over it
|
|
815
|
+
* function MinRoles(min: number): Gate<GateContextBase, 'MinRoles'> {
|
|
816
|
+
* return defineGate('MinRoles', (ctx) => {
|
|
817
|
+
* if (ctx.memberRoleIds.length < min) throw new NotEnoughRoles(min);
|
|
818
|
+
* });
|
|
819
|
+
* }
|
|
820
|
+
* ```
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```ts
|
|
824
|
+
* // agnostic gate (no ctx annotation): fits any handler
|
|
825
|
+
* const Owner = defineGate('owner', (ctx) => {
|
|
826
|
+
* if (!ctx.userId) throw new NotOwner();
|
|
827
|
+
* });
|
|
828
|
+
* ```
|
|
829
|
+
*/
|
|
830
|
+
function defineGate(name, fn) {
|
|
831
|
+
return {
|
|
832
|
+
name,
|
|
833
|
+
check: async (ctx) => fn(ctx)
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Builds an {@link EffectGate} from a `check` and a `commit`. `check` peeks and refuses by throwing, and
|
|
838
|
+
* `commit` applies the side effect, running only once the whole gate set passes so a later refusal never
|
|
839
|
+
* commits. In an `or`, a refusing arm's queued commit is rolled back. This is how {@link Cooldown} peeks
|
|
840
|
+
* in `check` and charges the slot in `commit`.
|
|
841
|
+
*
|
|
842
|
+
* @typeParam Name - The gate's name captured as a literal, so a mismatch error can name the gate.
|
|
843
|
+
* @typeParam Ctx - The context both `check` and `commit` read, inferred from the `ctx` annotation.
|
|
844
|
+
*
|
|
845
|
+
* @param name - The gate's name, used in mismatch errors.
|
|
846
|
+
* @param check - Peeks and refuses by throwing, without applying the side effect.
|
|
847
|
+
* @param commit - Applies the side effect, running only after the whole gate set passes.
|
|
848
|
+
*
|
|
849
|
+
* @see {@link defineGate}
|
|
850
|
+
* @see the `@Gated` decorator from `seedcord`
|
|
851
|
+
* @see {@link Cooldown}
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```ts
|
|
855
|
+
* // an effect-gate factory that takes its own limit and closes over it
|
|
856
|
+
* function UsesPerDay(max: number): EffectGate<GateContextBase, 'UsesPerDay'> {
|
|
857
|
+
* return defineEffectGate(
|
|
858
|
+
* 'UsesPerDay',
|
|
859
|
+
* (ctx) => {
|
|
860
|
+
* // peek and refuse by throwing, do not mutate yet
|
|
861
|
+
* if (usedToday(ctx.userId) >= max) throw new OutOfUsesNotice(max);
|
|
862
|
+
* },
|
|
863
|
+
* (ctx) => {
|
|
864
|
+
* // runs only after the whole gate set passes
|
|
865
|
+
* recordUse(ctx.userId);
|
|
866
|
+
* }
|
|
867
|
+
* );
|
|
868
|
+
* }
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
function defineEffectGate(name, check, commit) {
|
|
872
|
+
return {
|
|
873
|
+
name,
|
|
874
|
+
check: async (ctx) => check(ctx),
|
|
875
|
+
commit: async (ctx) => commit(ctx)
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
//#endregion
|
|
880
|
+
//#region src/notices/index.ts
|
|
881
|
+
var GateNotice = class extends Notice {
|
|
882
|
+
render() {
|
|
883
|
+
return { components: [new NoticeCard(this.message).component] };
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
var NotOwner = class extends GateNotice {
|
|
887
|
+
constructor(message = "Only the bot owner can use this.") {
|
|
888
|
+
super(message);
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
var NotInGuild = class extends GateNotice {
|
|
892
|
+
constructor(message = "This can only be used in a server.") {
|
|
893
|
+
super(message);
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
var NotInDm = class extends GateNotice {
|
|
897
|
+
constructor(message = "This can only be used in a direct message.") {
|
|
898
|
+
super(message);
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
var OnCooldown = class extends GateNotice {
|
|
902
|
+
resetAt;
|
|
903
|
+
constructor(resetAt, message) {
|
|
904
|
+
super(message ?? `You are doing that too fast. Try again <t:${(0, _seedcord_utils.toEpochSeconds)(resetAt)}:R>.`);
|
|
905
|
+
this.resetAt = resetAt;
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
var NotAllowed = class extends Notice {
|
|
909
|
+
constructor() {
|
|
910
|
+
super("not allowed");
|
|
911
|
+
}
|
|
912
|
+
render() {
|
|
913
|
+
return { components: [new NoticeCard("You are not allowed to use this command.").component] };
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
var NeedsAny = class extends Notice {
|
|
917
|
+
summaries;
|
|
918
|
+
constructor(summaries) {
|
|
919
|
+
super("not allowed");
|
|
920
|
+
this.summaries = summaries;
|
|
921
|
+
}
|
|
922
|
+
render() {
|
|
923
|
+
return { components: [new NoticeCard(`You need any of:\n${this.summaries.map((summary) => `• ${summary}`).join("\n")}`).component] };
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
var MissingRole = class extends GateNotice {
|
|
927
|
+
constructor(message, roleId) {
|
|
928
|
+
super(message ?? (roleId ? `You need the <@&${roleId}> role to use this.` : "You do not have the required role."));
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
var MissingPermissions = class extends Notice {
|
|
932
|
+
subject;
|
|
933
|
+
missingPerms;
|
|
934
|
+
customLead;
|
|
935
|
+
constructor(message, subject, missingPerms) {
|
|
936
|
+
super(message ?? "A required permission is missing.");
|
|
937
|
+
this.subject = subject;
|
|
938
|
+
this.missingPerms = missingPerms;
|
|
939
|
+
this.customLead = message;
|
|
940
|
+
}
|
|
941
|
+
render() {
|
|
942
|
+
const bullets = this.missingPerms.map((perm) => `• ${perm}`).join("\n");
|
|
943
|
+
return { components: [new NoticeCard(`${this.customLead ?? `${this.subject === null ? "You are" : `${this.subject} is`} missing the following permission entries:`}\n\n${bullets}`).component] };
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
//#endregion
|
|
948
|
+
//#region src/gates/effects.ts
|
|
949
|
+
const commitQueues = /* @__PURE__ */ new WeakMap();
|
|
950
|
+
function isEffectGate(gate) {
|
|
951
|
+
return typeof gate.commit === "function";
|
|
952
|
+
}
|
|
953
|
+
async function runCheck(gate, ctx) {
|
|
954
|
+
await gate.check(ctx);
|
|
955
|
+
if (!isEffectGate(gate)) return;
|
|
956
|
+
let queue = commitQueues.get(ctx);
|
|
957
|
+
if (!queue) {
|
|
958
|
+
queue = [];
|
|
959
|
+
commitQueues.set(ctx, queue);
|
|
960
|
+
}
|
|
961
|
+
queue.push(() => gate.commit(ctx));
|
|
962
|
+
}
|
|
963
|
+
async function runCommits(ctx) {
|
|
964
|
+
const queue = commitQueues.get(ctx);
|
|
965
|
+
if (!queue) return;
|
|
966
|
+
for (const commit of queue) await commit();
|
|
967
|
+
}
|
|
968
|
+
function discardCommits(ctx) {
|
|
969
|
+
commitQueues.delete(ctx);
|
|
970
|
+
}
|
|
971
|
+
function markCommits(ctx) {
|
|
972
|
+
return commitQueues.get(ctx)?.length ?? 0;
|
|
973
|
+
}
|
|
974
|
+
function rollbackCommits(ctx, mark) {
|
|
975
|
+
const queue = commitQueues.get(ctx);
|
|
976
|
+
if (queue && queue.length > mark) queue.length = mark;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region src/gates/catalog/options.ts
|
|
981
|
+
function pickNotice(options, makeDefault) {
|
|
982
|
+
return options?.notice ?? makeDefault(options?.message);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
//#endregion
|
|
986
|
+
//#region src/gates/catalog/permissions.ts
|
|
987
|
+
/** Permission bit to its prettified human-readable name, for the missing-permission refusal. */
|
|
988
|
+
const PermissionNames = new Map(Object.entries(discord_api_types_v10.PermissionFlagsBits).map(([key, bit]) => [bit, (0, _seedcord_utils.prettify)(key)]));
|
|
989
|
+
const ADMINISTRATOR = discord_api_types_v10.PermissionFlagsBits.Administrator;
|
|
990
|
+
const MEMBER_CHECK = {
|
|
991
|
+
unresolved: "Your server member data could not be resolved. Try again.",
|
|
992
|
+
subject: null
|
|
993
|
+
};
|
|
994
|
+
const BOT_CHECK = {
|
|
995
|
+
unresolved: "The bot's permissions could not be resolved. Try again.",
|
|
996
|
+
subject: "The bot"
|
|
997
|
+
};
|
|
998
|
+
function hasAll(held, scope) {
|
|
999
|
+
if ((held & ADMINISTRATOR) === ADMINISTRATOR) return true;
|
|
1000
|
+
return scope.every((bit) => (held & bit) === bit);
|
|
1001
|
+
}
|
|
1002
|
+
function missingNames(held, scope) {
|
|
1003
|
+
return scope.reduce((names, bit) => {
|
|
1004
|
+
if ((held & bit) !== bit) names.push(PermissionNames.get(bit) ?? String(bit));
|
|
1005
|
+
return names;
|
|
1006
|
+
}, []);
|
|
1007
|
+
}
|
|
1008
|
+
function refusePermissions(held, scope, options, guildId, kind) {
|
|
1009
|
+
if (held === null) throw pickNotice(options?.notInGuild, (message) => new NotInGuild(message ?? (guildId ? kind.unresolved : void 0)));
|
|
1010
|
+
if (hasAll(held, scope)) return;
|
|
1011
|
+
throw pickNotice(options?.missing, (message) => new MissingPermissions(message, kind.subject, missingNames(held, scope)));
|
|
1012
|
+
}
|
|
1013
|
+
function RequirePermissions(scope, options) {
|
|
1014
|
+
if (options?.in === "guild") return defineGate("RequirePermissions", (ctx) => {
|
|
1015
|
+
refusePermissions(ctx.memberGuildPermissions, scope, options, ctx.guildId, MEMBER_CHECK);
|
|
1016
|
+
});
|
|
1017
|
+
return defineGate("RequirePermissions", (ctx) => {
|
|
1018
|
+
refusePermissions(ctx.memberPermissions, scope, options, ctx.guildId, MEMBER_CHECK);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
function RequireBotPermissions(scope, options) {
|
|
1022
|
+
if (options?.in === "guild") return defineGate("RequireBotPermissions", (ctx) => {
|
|
1023
|
+
refusePermissions(ctx.appGuildPermissions, scope, options, ctx.guildId, BOT_CHECK);
|
|
1024
|
+
});
|
|
1025
|
+
return defineGate("RequireBotPermissions", (ctx) => {
|
|
1026
|
+
refusePermissions(ctx.appPermissions, scope, options, ctx.guildId, BOT_CHECK);
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Requires the caller to hold `roleId`, read from the member's role ids. Refuses outside a guild first,
|
|
1031
|
+
* then when the role is missing. Roles are guild-global, so there is no scope dimension.
|
|
1032
|
+
*
|
|
1033
|
+
* @param roleId - The role snowflake the caller must hold.
|
|
1034
|
+
* @param options - Override each refusal, the outside-guild one with `notInGuild` and the missing-role one with `missingRole`.
|
|
1035
|
+
*
|
|
1036
|
+
* @see the `@Gated` decorator from `seedcord`
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```ts
|
|
1040
|
+
* \@Gated(RequireRole('123456789012345678'))
|
|
1041
|
+
* \@SlashRoute('vip')
|
|
1042
|
+
* class VipHandler extends SlashHandler<'vip'> {
|
|
1043
|
+
* async execute() {
|
|
1044
|
+
* // ...
|
|
1045
|
+
* }
|
|
1046
|
+
* }
|
|
1047
|
+
* ```
|
|
1048
|
+
*/
|
|
1049
|
+
function RequireRole(roleId, options) {
|
|
1050
|
+
return defineGate("RequireRole", (ctx) => {
|
|
1051
|
+
if (!ctx.guildId) throw pickNotice(options?.notInGuild, (message) => new NotInGuild(message));
|
|
1052
|
+
if (ctx.memberRoleIds.includes(roleId)) return;
|
|
1053
|
+
throw pickNotice(options?.missingRole, (message) => new MissingRole(message, roleId));
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
|
|
818
1057
|
//#endregion
|
|
819
1058
|
Object.defineProperty(exports, 'BuilderComponent', {
|
|
820
1059
|
enumerable: true,
|
|
@@ -828,6 +1067,12 @@ Object.defineProperty(exports, 'CommandMetadataKey', {
|
|
|
828
1067
|
return CommandMetadataKey;
|
|
829
1068
|
}
|
|
830
1069
|
});
|
|
1070
|
+
Object.defineProperty(exports, 'ComponentDefsKey', {
|
|
1071
|
+
enumerable: true,
|
|
1072
|
+
get: function () {
|
|
1073
|
+
return ComponentDefsKey;
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
831
1076
|
Object.defineProperty(exports, 'CustomId', {
|
|
832
1077
|
enumerable: true,
|
|
833
1078
|
get: function () {
|
|
@@ -876,6 +1121,18 @@ Object.defineProperty(exports, 'MiddlewareMetadataKey', {
|
|
|
876
1121
|
return MiddlewareMetadataKey;
|
|
877
1122
|
}
|
|
878
1123
|
});
|
|
1124
|
+
Object.defineProperty(exports, 'MissingPermissions', {
|
|
1125
|
+
enumerable: true,
|
|
1126
|
+
get: function () {
|
|
1127
|
+
return MissingPermissions;
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
Object.defineProperty(exports, 'MissingRole', {
|
|
1131
|
+
enumerable: true,
|
|
1132
|
+
get: function () {
|
|
1133
|
+
return MissingRole;
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
879
1136
|
Object.defineProperty(exports, 'NeedsAny', {
|
|
880
1137
|
enumerable: true,
|
|
881
1138
|
get: function () {
|
|
@@ -924,24 +1181,90 @@ Object.defineProperty(exports, 'OnCooldown', {
|
|
|
924
1181
|
return OnCooldown;
|
|
925
1182
|
}
|
|
926
1183
|
});
|
|
1184
|
+
Object.defineProperty(exports, 'PermissionNames', {
|
|
1185
|
+
enumerable: true,
|
|
1186
|
+
get: function () {
|
|
1187
|
+
return PermissionNames;
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
Object.defineProperty(exports, 'RequireBotPermissions', {
|
|
1191
|
+
enumerable: true,
|
|
1192
|
+
get: function () {
|
|
1193
|
+
return RequireBotPermissions;
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
Object.defineProperty(exports, 'RequirePermissions', {
|
|
1197
|
+
enumerable: true,
|
|
1198
|
+
get: function () {
|
|
1199
|
+
return RequirePermissions;
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
Object.defineProperty(exports, 'RequireRole', {
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
get: function () {
|
|
1205
|
+
return RequireRole;
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
927
1208
|
Object.defineProperty(exports, 'RowComponent', {
|
|
928
1209
|
enumerable: true,
|
|
929
1210
|
get: function () {
|
|
930
1211
|
return RowComponent;
|
|
931
1212
|
}
|
|
932
1213
|
});
|
|
1214
|
+
Object.defineProperty(exports, 'SelectMenuKind', {
|
|
1215
|
+
enumerable: true,
|
|
1216
|
+
get: function () {
|
|
1217
|
+
return SelectMenuKind;
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
933
1220
|
Object.defineProperty(exports, 'SubscribeMetadataKey', {
|
|
934
1221
|
enumerable: true,
|
|
935
1222
|
get: function () {
|
|
936
1223
|
return SubscribeMetadataKey;
|
|
937
1224
|
}
|
|
938
1225
|
});
|
|
1226
|
+
Object.defineProperty(exports, 'WebhookUrlMetadataKey', {
|
|
1227
|
+
enumerable: true,
|
|
1228
|
+
get: function () {
|
|
1229
|
+
return WebhookUrlMetadataKey;
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
Object.defineProperty(exports, 'areRoutes', {
|
|
1233
|
+
enumerable: true,
|
|
1234
|
+
get: function () {
|
|
1235
|
+
return areRoutes;
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
Object.defineProperty(exports, 'contextMenuRouteOf', {
|
|
1239
|
+
enumerable: true,
|
|
1240
|
+
get: function () {
|
|
1241
|
+
return contextMenuRouteOf;
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
Object.defineProperty(exports, 'decodeComponentRoute', {
|
|
1245
|
+
enumerable: true,
|
|
1246
|
+
get: function () {
|
|
1247
|
+
return decodeComponentRoute;
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
939
1250
|
Object.defineProperty(exports, 'decodeFor', {
|
|
940
1251
|
enumerable: true,
|
|
941
1252
|
get: function () {
|
|
942
1253
|
return decodeFor;
|
|
943
1254
|
}
|
|
944
1255
|
});
|
|
1256
|
+
Object.defineProperty(exports, 'defineEffectGate', {
|
|
1257
|
+
enumerable: true,
|
|
1258
|
+
get: function () {
|
|
1259
|
+
return defineEffectGate;
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
Object.defineProperty(exports, 'defineGate', {
|
|
1263
|
+
enumerable: true,
|
|
1264
|
+
get: function () {
|
|
1265
|
+
return defineGate;
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
945
1268
|
Object.defineProperty(exports, 'discardCommits', {
|
|
946
1269
|
enumerable: true,
|
|
947
1270
|
get: function () {
|
|
@@ -984,10 +1307,28 @@ Object.defineProperty(exports, 'runCommits', {
|
|
|
984
1307
|
return runCommits;
|
|
985
1308
|
}
|
|
986
1309
|
});
|
|
1310
|
+
Object.defineProperty(exports, 'selectMenuRouteOf', {
|
|
1311
|
+
enumerable: true,
|
|
1312
|
+
get: function () {
|
|
1313
|
+
return selectMenuRouteOf;
|
|
1314
|
+
}
|
|
1315
|
+
});
|
|
987
1316
|
Object.defineProperty(exports, 'setBotColor', {
|
|
988
1317
|
enumerable: true,
|
|
989
1318
|
get: function () {
|
|
990
1319
|
return setBotColor;
|
|
991
1320
|
}
|
|
992
1321
|
});
|
|
993
|
-
|
|
1322
|
+
Object.defineProperty(exports, 'storeComponentRoute', {
|
|
1323
|
+
enumerable: true,
|
|
1324
|
+
get: function () {
|
|
1325
|
+
return storeComponentRoute;
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
Object.defineProperty(exports, 'storeInteractionRoute', {
|
|
1329
|
+
enumerable: true,
|
|
1330
|
+
get: function () {
|
|
1331
|
+
return storeInteractionRoute;
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
//# sourceMappingURL=permissions-DQL5ViZn.cjs.map
|