@wolfstar/http-framework 5.1.1 → 6.0.0-next-20260929152320
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 +11 -129
- package/dist/esm/index.d.ts +45 -288
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +58 -362
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -5
package/dist/esm/index.js
CHANGED
|
@@ -440,7 +440,7 @@ let HttpCodes = /* @__PURE__ */ function(HttpCodes) {
|
|
|
440
440
|
}({});
|
|
441
441
|
|
|
442
442
|
//#endregion
|
|
443
|
-
//#region \0@oxc-project+runtime@0.
|
|
443
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/typeof.js
|
|
444
444
|
function _typeof(o) {
|
|
445
445
|
"@babel/helpers - typeof";
|
|
446
446
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -451,7 +451,7 @@ function _typeof(o) {
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
//#endregion
|
|
454
|
-
//#region \0@oxc-project+runtime@0.
|
|
454
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPrimitive.js
|
|
455
455
|
function toPrimitive(t, r) {
|
|
456
456
|
if ("object" != _typeof(t) || !t) return t;
|
|
457
457
|
var e = t[Symbol.toPrimitive];
|
|
@@ -464,14 +464,14 @@ function toPrimitive(t, r) {
|
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
//#endregion
|
|
467
|
-
//#region \0@oxc-project+runtime@0.
|
|
467
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPropertyKey.js
|
|
468
468
|
function toPropertyKey(t) {
|
|
469
469
|
var i = toPrimitive(t, "string");
|
|
470
470
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
//#endregion
|
|
474
|
-
//#region \0@oxc-project+runtime@0.
|
|
474
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/defineProperty.js
|
|
475
475
|
function _defineProperty(e, r, t) {
|
|
476
476
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
477
477
|
value: t,
|
|
@@ -482,32 +482,32 @@ function _defineProperty(e, r, t) {
|
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
//#endregion
|
|
485
|
-
//#region \0@oxc-project+runtime@0.
|
|
485
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/checkPrivateRedeclaration.js
|
|
486
486
|
function _checkPrivateRedeclaration(e, t) {
|
|
487
487
|
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
488
488
|
}
|
|
489
489
|
|
|
490
490
|
//#endregion
|
|
491
|
-
//#region \0@oxc-project+runtime@0.
|
|
491
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
492
492
|
function _classPrivateFieldInitSpec(e, t, a) {
|
|
493
493
|
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
494
494
|
}
|
|
495
495
|
|
|
496
496
|
//#endregion
|
|
497
|
-
//#region \0@oxc-project+runtime@0.
|
|
497
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/assertClassBrand.js
|
|
498
498
|
function _assertClassBrand(e, t, n) {
|
|
499
499
|
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
500
500
|
throw new TypeError("Private element is not present on this object");
|
|
501
501
|
}
|
|
502
502
|
|
|
503
503
|
//#endregion
|
|
504
|
-
//#region \0@oxc-project+runtime@0.
|
|
504
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateFieldGet2.js
|
|
505
505
|
function _classPrivateFieldGet2(s, a) {
|
|
506
506
|
return s.get(_assertClassBrand(s, a));
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
//#endregion
|
|
510
|
-
//#region \0@oxc-project+runtime@0.
|
|
510
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateFieldSet2.js
|
|
511
511
|
function _classPrivateFieldSet2(s, a, r) {
|
|
512
512
|
return s.set(_assertClassBrand(s, a), r), r;
|
|
513
513
|
}
|
|
@@ -747,23 +747,16 @@ var PluginManager = class {
|
|
|
747
747
|
};
|
|
748
748
|
|
|
749
749
|
//#endregion
|
|
750
|
-
//#region src/lib/decorators
|
|
750
|
+
//#region src/lib/utils/decorators.ts
|
|
751
751
|
/**
|
|
752
752
|
* Utility to make a method decorator from a function.
|
|
753
753
|
*
|
|
754
754
|
* @remarks The decorator is returned with the signature it was given, rather than widened to `MethodDecorator`, so a
|
|
755
755
|
* decorator built on top of this keeps whatever constraint it declares on its target.
|
|
756
|
+
* @remarks Internal to the `Register*` decorators; the public counterpart lives in `@wolfstar/decorators`.
|
|
756
757
|
* @param fn The method to decorate.
|
|
757
758
|
* @returns The decorator.
|
|
758
|
-
* @
|
|
759
|
-
* ```typescript
|
|
760
|
-
* // Enumerable function that will not append the property to the prototype:
|
|
761
|
-
* function enumerableMethod(value: boolean) {
|
|
762
|
-
* return createMethodDecorator((_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => {
|
|
763
|
-
* descriptor.enumerable = value;
|
|
764
|
-
* });
|
|
765
|
-
* }
|
|
766
|
-
* ```
|
|
759
|
+
* @internal
|
|
767
760
|
*/
|
|
768
761
|
function createMethodDecorator(fn) {
|
|
769
762
|
return fn;
|
|
@@ -774,58 +767,14 @@ function createMethodDecorator(fn) {
|
|
|
774
767
|
* @remarks The decorator is returned with the signature it was given, rather than widened to `ClassDecorator`, so a
|
|
775
768
|
* decorator built on top of this keeps whatever constraint it declares on its target. This is what lets
|
|
776
769
|
* {@linkcode RegisterCommand} and its siblings reject a target that is not a `Command`.
|
|
770
|
+
* @remarks Internal to the `Register*` decorators; the public counterpart lives in `@wolfstar/decorators`.
|
|
777
771
|
* @param fn The class to decorate.
|
|
778
772
|
* @returns The decorator.
|
|
779
|
-
* @
|
|
773
|
+
* @internal
|
|
780
774
|
*/
|
|
781
775
|
function createClassDecorator(fn) {
|
|
782
776
|
return fn;
|
|
783
777
|
}
|
|
784
|
-
/**
|
|
785
|
-
* Creates a new proxy to efficiently add properties to a class without creating subclasses.
|
|
786
|
-
*
|
|
787
|
-
* @param target The constructor of the class to modify.
|
|
788
|
-
* @param handler The handler function to modify the constructor behavior for the target.
|
|
789
|
-
* @returns The proxy.
|
|
790
|
-
*/
|
|
791
|
-
function createProxy(target, handler) {
|
|
792
|
-
return new Proxy(target, {
|
|
793
|
-
...handler,
|
|
794
|
-
get: (proxyTarget, property) => {
|
|
795
|
-
const value = Reflect.get(proxyTarget, property);
|
|
796
|
-
return typeof value === "function" ? (...args) => value.apply(proxyTarget, args) : value;
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Utility to make a method decorator with lighter syntax and inferred types.
|
|
802
|
-
*
|
|
803
|
-
* @remarks The decorated method is replaced by an `async` one, so it always returns a `Promise`, even when both the
|
|
804
|
-
* precondition and the original method are synchronous.
|
|
805
|
-
* @param precondition The predicate to run before the decorated method. It receives the same arguments as the method
|
|
806
|
-
* and is called with the same `this`.
|
|
807
|
-
* @param fallback The fallback to run when the precondition is not met. Defaults to a no-op returning `undefined`.
|
|
808
|
-
* @returns The decorator.
|
|
809
|
-
* @example
|
|
810
|
-
* ```typescript
|
|
811
|
-
* import { Command, RegisterCommand, createFunctionPrecondition } from '@wolfstar/http-framework';
|
|
812
|
-
*
|
|
813
|
-
* const RequiresOwner = createFunctionPrecondition(
|
|
814
|
-
* (interaction: Command.ChatInputInteraction) => interaction.user.id === process.env.OWNER_ID,
|
|
815
|
-
* (interaction: Command.ChatInputInteraction) => interaction.reply({ content: 'Owner only.' })
|
|
816
|
-
* );
|
|
817
|
-
* ```
|
|
818
|
-
*/
|
|
819
|
-
function createFunctionPrecondition(precondition, fallback = () => void 0) {
|
|
820
|
-
return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
821
|
-
const method = descriptor.value;
|
|
822
|
-
if (!method) throw new Error("Function preconditions require a [[value]].");
|
|
823
|
-
if (typeof method !== "function") throw new Error("Function preconditions can only be applied to functions.");
|
|
824
|
-
descriptor.value = async function value(...args) {
|
|
825
|
-
return await precondition.apply(this, args) ? method.apply(this, args) : fallback.apply(this, args);
|
|
826
|
-
};
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
778
|
|
|
830
779
|
//#endregion
|
|
831
780
|
//#region src/lib/interactions/decorators/_shared.ts
|
|
@@ -1135,7 +1084,7 @@ function getLinkedMethod(object) {
|
|
|
1135
1084
|
}
|
|
1136
1085
|
|
|
1137
1086
|
//#endregion
|
|
1138
|
-
//#region \0@oxc-project+runtime@0.
|
|
1087
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateMethodInitSpec.js
|
|
1139
1088
|
function _classPrivateMethodInitSpec(e, a) {
|
|
1140
1089
|
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
1141
1090
|
}
|
|
@@ -4127,159 +4076,40 @@ var Client = class Client extends AsyncEventEmitter {
|
|
|
4127
4076
|
_defineProperty(Client, "plugins", new PluginManager());
|
|
4128
4077
|
|
|
4129
4078
|
//#endregion
|
|
4130
|
-
//#region src/lib/
|
|
4131
|
-
/**
|
|
4132
|
-
* Decorator that sets the options of a `Piece`, such as a `Command`, a `Listener`, or an `InteractionHandler`.
|
|
4133
|
-
*
|
|
4134
|
-
* @remarks The options are merged on top of the ones the piece was constructed with, so a piece that also passes
|
|
4135
|
-
* options through `super(context, options)` will have the decorator's values win on conflicting keys.
|
|
4136
|
-
* @remarks Apply this decorator above (outside of) any other class decorator that keys metadata by class identity,
|
|
4137
|
-
* such as {@linkcode RegisterCommand} — as in the example below. This decorator returns a `Proxy` wrapping the class,
|
|
4138
|
-
* so a decorator applied above it (running after it, and therefore registering against the proxy) would register
|
|
4139
|
-
* metadata that instances constructed from the exported class — whose `.constructor` still resolves to the original,
|
|
4140
|
-
* unproxied class — can never be looked up by.
|
|
4141
|
-
* @param optionsOrFn The options to pass to the piece's constructor, or a function that builds them from the loader
|
|
4142
|
-
* context.
|
|
4143
|
-
* @returns A class decorator.
|
|
4144
|
-
* @example
|
|
4145
|
-
* ```typescript
|
|
4146
|
-
* import { ApplyOptions, Command, RegisterCommand } from '@wolfstar/http-framework';
|
|
4147
|
-
*
|
|
4148
|
-
* (at)ApplyOptions<Command.Options>({ name: 'ping', enabled: true })
|
|
4149
|
-
* (at)RegisterCommand({ name: 'ping', description: 'A simple ping pong command' })
|
|
4150
|
-
* export class UserCommand extends Command {
|
|
4151
|
-
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
4152
|
-
* return interaction.reply({ content: 'Pong!' });
|
|
4153
|
-
* }
|
|
4154
|
-
* }
|
|
4155
|
-
* ```
|
|
4156
|
-
* @example
|
|
4157
|
-
* ```typescript
|
|
4158
|
-
* (at)ApplyOptions<Command.Options>(({ name }) => ({ name: name.toLowerCase() }))
|
|
4159
|
-
* export class UserCommand extends Command {}
|
|
4160
|
-
* ```
|
|
4161
|
-
*/
|
|
4162
|
-
function ApplyOptions(optionsOrFn) {
|
|
4163
|
-
return createClassDecorator((target) => createProxy(target, { construct: (ctor, [context, baseOptions], newTarget) => Reflect.construct(ctor, [context, {
|
|
4164
|
-
...baseOptions,
|
|
4165
|
-
...typeof optionsOrFn === "function" ? optionsOrFn(context) : optionsOrFn
|
|
4166
|
-
}], newTarget) }));
|
|
4167
|
-
}
|
|
4168
|
-
|
|
4169
|
-
//#endregion
|
|
4170
|
-
//#region src/lib/decorators/Enumerable.ts
|
|
4079
|
+
//#region src/lib/errors/ArgumentError.ts
|
|
4171
4080
|
/**
|
|
4172
|
-
*
|
|
4081
|
+
* Errors thrown while resolving the options (arguments) of an interaction.
|
|
4173
4082
|
*
|
|
4174
|
-
* @
|
|
4175
|
-
*
|
|
4176
|
-
* class fields. Mark the field as `declare` so no field definition is emitted, and assign it in the constructor.
|
|
4177
|
-
* @param value Whether the property should be enumerable or not.
|
|
4178
|
-
* @returns A property decorator.
|
|
4083
|
+
* @property name This will be `'ArgumentError'` and can be used to distinguish the type of error when any error gets thrown.
|
|
4084
|
+
* @since 3.2.0
|
|
4179
4085
|
* @example
|
|
4180
4086
|
* ```typescript
|
|
4181
|
-
*
|
|
4182
|
-
*
|
|
4183
|
-
*
|
|
4184
|
-
*
|
|
4185
|
-
*
|
|
4186
|
-
*
|
|
4187
|
-
*
|
|
4188
|
-
* super(context, options);
|
|
4189
|
-
* this.cache = new Map();
|
|
4190
|
-
* }
|
|
4191
|
-
* }
|
|
4087
|
+
* throw new ArgumentError({
|
|
4088
|
+
* argument: 'amount',
|
|
4089
|
+
* parameter: interaction.options.getInteger('amount'),
|
|
4090
|
+
* identifier: Identifiers.ArgumentIntegerTooSmall,
|
|
4091
|
+
* message: 'The amount must be at least 1.',
|
|
4092
|
+
* context: { minimum: 1 }
|
|
4093
|
+
* });
|
|
4192
4094
|
* ```
|
|
4193
4095
|
*/
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
Reflect.defineProperty(this, key, {
|
|
4200
|
-
configurable: true,
|
|
4201
|
-
enumerable: value,
|
|
4202
|
-
value: val,
|
|
4203
|
-
writable: true
|
|
4204
|
-
});
|
|
4205
|
-
}
|
|
4096
|
+
var ArgumentError = class extends UserError {
|
|
4097
|
+
constructor(options) {
|
|
4098
|
+
super({
|
|
4099
|
+
...options,
|
|
4100
|
+
identifier: options.identifier ?? options.argument
|
|
4206
4101
|
});
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
* export class UserCommand extends Command {
|
|
4219
|
-
* (at)EnumerableMethod(true)
|
|
4220
|
-
* public getCacheKey(id: string) {
|
|
4221
|
-
* return `user:${id}`;
|
|
4222
|
-
* }
|
|
4223
|
-
* }
|
|
4224
|
-
* ```
|
|
4225
|
-
*/
|
|
4226
|
-
function EnumerableMethod(value) {
|
|
4227
|
-
return (_target, _key, descriptor) => {
|
|
4228
|
-
descriptor.enumerable = value;
|
|
4229
|
-
};
|
|
4230
|
-
}
|
|
4231
|
-
|
|
4232
|
-
//#endregion
|
|
4233
|
-
//#region src/lib/decorators/RequiresContext.ts
|
|
4234
|
-
/**
|
|
4235
|
-
* Decorator that only runs the decorated method when the interaction was received from a guild.
|
|
4236
|
-
*
|
|
4237
|
-
* @param fallback The fallback to run when the interaction did not come from a guild. Defaults to a no-op, which
|
|
4238
|
-
* silently skips the method.
|
|
4239
|
-
* @returns A method decorator.
|
|
4240
|
-
* @example
|
|
4241
|
-
* ```typescript
|
|
4242
|
-
* import { Command, RegisterCommand, RequiresGuildContext } from '@wolfstar/http-framework';
|
|
4243
|
-
*
|
|
4244
|
-
* (at)RegisterCommand({ name: 'kick', description: 'Kicks a member' })
|
|
4245
|
-
* export class UserCommand extends Command {
|
|
4246
|
-
* (at)RequiresGuildContext((interaction: Command.ChatInputInteraction) =>
|
|
4247
|
-
* interaction.reply({ content: 'This command can only be used in a server.' })
|
|
4248
|
-
* )
|
|
4249
|
-
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
4250
|
-
* return interaction.reply({ content: `Hello from ${interaction.guildId}!` });
|
|
4251
|
-
* }
|
|
4252
|
-
* }
|
|
4253
|
-
* ```
|
|
4254
|
-
*/
|
|
4255
|
-
function RequiresGuildContext(fallback = () => void 0) {
|
|
4256
|
-
return createFunctionPrecondition((interaction) => interaction.inGuild(), fallback);
|
|
4257
|
-
}
|
|
4258
|
-
/**
|
|
4259
|
-
* Decorator that only runs the decorated method when the interaction was **not** received from a guild, that is, from a
|
|
4260
|
-
* DM or from a user-installed app context.
|
|
4261
|
-
*
|
|
4262
|
-
* @param fallback The fallback to run when the interaction came from a guild. Defaults to a no-op, which silently skips
|
|
4263
|
-
* the method.
|
|
4264
|
-
* @returns A method decorator.
|
|
4265
|
-
* @example
|
|
4266
|
-
* ```typescript
|
|
4267
|
-
* import { Command, RegisterCommand, RequiresDMContext } from '@wolfstar/http-framework';
|
|
4268
|
-
*
|
|
4269
|
-
* (at)RegisterCommand({ name: 'private', description: 'Only usable outside of servers' })
|
|
4270
|
-
* export class UserCommand extends Command {
|
|
4271
|
-
* (at)RequiresDMContext((interaction: Command.ChatInputInteraction) =>
|
|
4272
|
-
* interaction.reply({ content: 'This command cannot be used in a server.' })
|
|
4273
|
-
* )
|
|
4274
|
-
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
4275
|
-
* return interaction.reply({ content: 'Hello!' });
|
|
4276
|
-
* }
|
|
4277
|
-
* }
|
|
4278
|
-
* ```
|
|
4279
|
-
*/
|
|
4280
|
-
function RequiresDMContext(fallback = () => void 0) {
|
|
4281
|
-
return createFunctionPrecondition((interaction) => !interaction.inGuild(), fallback);
|
|
4282
|
-
}
|
|
4102
|
+
_defineProperty(this, "argument", void 0);
|
|
4103
|
+
_defineProperty(this, "type", void 0);
|
|
4104
|
+
_defineProperty(this, "parameter", void 0);
|
|
4105
|
+
this.argument = options.argument;
|
|
4106
|
+
this.type = options.type ?? null;
|
|
4107
|
+
this.parameter = options.parameter;
|
|
4108
|
+
}
|
|
4109
|
+
get name() {
|
|
4110
|
+
return "ArgumentError";
|
|
4111
|
+
}
|
|
4112
|
+
};
|
|
4283
4113
|
|
|
4284
4114
|
//#endregion
|
|
4285
4115
|
//#region src/lib/errors/PreconditionError.ts
|
|
@@ -4314,6 +4144,21 @@ var PreconditionError = class extends UserError {
|
|
|
4314
4144
|
}
|
|
4315
4145
|
};
|
|
4316
4146
|
|
|
4147
|
+
//#endregion
|
|
4148
|
+
//#region src/lib/plugins/Plugin.ts
|
|
4149
|
+
/**
|
|
4150
|
+
* The base class for all plugins. Plugins hook into the {@link Client}'s lifecycle by defining static
|
|
4151
|
+
* methods keyed by the plugin symbols. Use {@link PluginManager.use} (via `Client.use`) to register a plugin.
|
|
4152
|
+
*
|
|
4153
|
+
* @since 2.4.0
|
|
4154
|
+
*/
|
|
4155
|
+
var Plugin = class {};
|
|
4156
|
+
_defineProperty(Plugin, preGenericsInitialization, void 0);
|
|
4157
|
+
_defineProperty(Plugin, preInitialization, void 0);
|
|
4158
|
+
_defineProperty(Plugin, postInitialization, void 0);
|
|
4159
|
+
_defineProperty(Plugin, preLoad, void 0);
|
|
4160
|
+
_defineProperty(Plugin, postListen, void 0);
|
|
4161
|
+
|
|
4317
4162
|
//#endregion
|
|
4318
4163
|
//#region src/lib/utils/permissions.ts
|
|
4319
4164
|
/**
|
|
@@ -4365,154 +4210,5 @@ function toPermissionNames(bits) {
|
|
|
4365
4210
|
}
|
|
4366
4211
|
|
|
4367
4212
|
//#endregion
|
|
4368
|
-
|
|
4369
|
-
/**
|
|
4370
|
-
* Reads the permissions the invoking user has in the channel the interaction was sent from.
|
|
4371
|
-
*
|
|
4372
|
-
* @param interaction The interaction to read from.
|
|
4373
|
-
* @returns The bitfield of the user's permissions, or `null` when the interaction did not come from a guild and there
|
|
4374
|
-
* are therefore no guild permissions to check.
|
|
4375
|
-
*/
|
|
4376
|
-
function getUserPermissions(interaction) {
|
|
4377
|
-
const permissions = interaction.member?.permissions;
|
|
4378
|
-
return permissions === void 0 ? null : BigInt(permissions);
|
|
4379
|
-
}
|
|
4380
|
-
/**
|
|
4381
|
-
* Decorator that only runs the decorated method when the application has all of the given permissions in the channel
|
|
4382
|
-
* the interaction was sent from, as reported by the interaction's `app_permissions` field.
|
|
4383
|
-
*
|
|
4384
|
-
* @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by
|
|
4385
|
-
* {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `commandError` (or
|
|
4386
|
-
* `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.
|
|
4387
|
-
* @param permissions The permissions the application must have.
|
|
4388
|
-
* @returns A method decorator.
|
|
4389
|
-
* @example
|
|
4390
|
-
* ```typescript
|
|
4391
|
-
* import { Command, RegisterCommand, RequiresClientPermissions } from '@wolfstar/http-framework';
|
|
4392
|
-
*
|
|
4393
|
-
* (at)RegisterCommand({ name: 'purge', description: 'Deletes messages' })
|
|
4394
|
-
* export class UserCommand extends Command {
|
|
4395
|
-
* (at)RequiresClientPermissions('ManageMessages')
|
|
4396
|
-
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
4397
|
-
* return interaction.reply({ content: 'Purging!' });
|
|
4398
|
-
* }
|
|
4399
|
-
* }
|
|
4400
|
-
* ```
|
|
4401
|
-
*/
|
|
4402
|
-
function RequiresClientPermissions(...permissions) {
|
|
4403
|
-
const required = resolvePermissions(permissions);
|
|
4404
|
-
return createFunctionPrecondition((interaction) => {
|
|
4405
|
-
const granted = interaction.applicationPermissions;
|
|
4406
|
-
return granted === void 0 || getMissingPermissions(granted, required) === 0n;
|
|
4407
|
-
}, (interaction) => {
|
|
4408
|
-
const missing = getMissingPermissions(interaction.applicationPermissions ?? 0n, required);
|
|
4409
|
-
const missingNames = toPermissionNames(missing);
|
|
4410
|
-
throw new PreconditionError({
|
|
4411
|
-
precondition: "ClientPermissions",
|
|
4412
|
-
identifier: "preconditionClientPermissions",
|
|
4413
|
-
message: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingNames.join(", ")}`,
|
|
4414
|
-
context: {
|
|
4415
|
-
missing,
|
|
4416
|
-
missingNames
|
|
4417
|
-
}
|
|
4418
|
-
});
|
|
4419
|
-
});
|
|
4420
|
-
}
|
|
4421
|
-
/**
|
|
4422
|
-
* Decorator that only runs the decorated method when the invoking user has all of the given permissions in the channel
|
|
4423
|
-
* the interaction was sent from.
|
|
4424
|
-
*
|
|
4425
|
-
* @remarks Interactions received outside of a guild carry no member permissions, so the check passes for them. Pair
|
|
4426
|
-
* this decorator with {@linkcode RequiresGuildContext} when the method must also be guild-only.
|
|
4427
|
-
* @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by
|
|
4428
|
-
* {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `commandError` (or
|
|
4429
|
-
* `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.
|
|
4430
|
-
* @param permissions The permissions the invoking user must have.
|
|
4431
|
-
* @returns A method decorator.
|
|
4432
|
-
* @example
|
|
4433
|
-
* ```typescript
|
|
4434
|
-
* import { Command, RegisterCommand, RequiresUserPermissions } from '@wolfstar/http-framework';
|
|
4435
|
-
*
|
|
4436
|
-
* (at)RegisterCommand({ name: 'ban', description: 'Bans a member' })
|
|
4437
|
-
* export class UserCommand extends Command {
|
|
4438
|
-
* (at)RequiresUserPermissions('BanMembers')
|
|
4439
|
-
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
4440
|
-
* return interaction.reply({ content: 'Banned!' });
|
|
4441
|
-
* }
|
|
4442
|
-
* }
|
|
4443
|
-
* ```
|
|
4444
|
-
*/
|
|
4445
|
-
function RequiresUserPermissions(...permissions) {
|
|
4446
|
-
const required = resolvePermissions(permissions);
|
|
4447
|
-
return createFunctionPrecondition((interaction) => {
|
|
4448
|
-
const granted = getUserPermissions(interaction);
|
|
4449
|
-
return granted === null || getMissingPermissions(granted, required) === 0n;
|
|
4450
|
-
}, (interaction) => {
|
|
4451
|
-
const missing = getMissingPermissions(getUserPermissions(interaction) ?? 0n, required);
|
|
4452
|
-
const missingNames = toPermissionNames(missing);
|
|
4453
|
-
throw new PreconditionError({
|
|
4454
|
-
precondition: "UserPermissions",
|
|
4455
|
-
identifier: "preconditionUserPermissions",
|
|
4456
|
-
message: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingNames.join(", ")}`,
|
|
4457
|
-
context: {
|
|
4458
|
-
missing,
|
|
4459
|
-
missingNames
|
|
4460
|
-
}
|
|
4461
|
-
});
|
|
4462
|
-
});
|
|
4463
|
-
}
|
|
4464
|
-
|
|
4465
|
-
//#endregion
|
|
4466
|
-
//#region src/lib/errors/ArgumentError.ts
|
|
4467
|
-
/**
|
|
4468
|
-
* Errors thrown while resolving the options (arguments) of an interaction.
|
|
4469
|
-
*
|
|
4470
|
-
* @property name This will be `'ArgumentError'` and can be used to distinguish the type of error when any error gets thrown.
|
|
4471
|
-
* @since 3.2.0
|
|
4472
|
-
* @example
|
|
4473
|
-
* ```typescript
|
|
4474
|
-
* throw new ArgumentError({
|
|
4475
|
-
* argument: 'amount',
|
|
4476
|
-
* parameter: interaction.options.getInteger('amount'),
|
|
4477
|
-
* identifier: Identifiers.ArgumentIntegerTooSmall,
|
|
4478
|
-
* message: 'The amount must be at least 1.',
|
|
4479
|
-
* context: { minimum: 1 }
|
|
4480
|
-
* });
|
|
4481
|
-
* ```
|
|
4482
|
-
*/
|
|
4483
|
-
var ArgumentError = class extends UserError {
|
|
4484
|
-
constructor(options) {
|
|
4485
|
-
super({
|
|
4486
|
-
...options,
|
|
4487
|
-
identifier: options.identifier ?? options.argument
|
|
4488
|
-
});
|
|
4489
|
-
_defineProperty(this, "argument", void 0);
|
|
4490
|
-
_defineProperty(this, "type", void 0);
|
|
4491
|
-
_defineProperty(this, "parameter", void 0);
|
|
4492
|
-
this.argument = options.argument;
|
|
4493
|
-
this.type = options.type ?? null;
|
|
4494
|
-
this.parameter = options.parameter;
|
|
4495
|
-
}
|
|
4496
|
-
get name() {
|
|
4497
|
-
return "ArgumentError";
|
|
4498
|
-
}
|
|
4499
|
-
};
|
|
4500
|
-
|
|
4501
|
-
//#endregion
|
|
4502
|
-
//#region src/lib/plugins/Plugin.ts
|
|
4503
|
-
/**
|
|
4504
|
-
* The base class for all plugins. Plugins hook into the {@link Client}'s lifecycle by defining static
|
|
4505
|
-
* methods keyed by the plugin symbols. Use {@link PluginManager.use} (via `Client.use`) to register a plugin.
|
|
4506
|
-
*
|
|
4507
|
-
* @since 2.4.0
|
|
4508
|
-
*/
|
|
4509
|
-
var Plugin = class {};
|
|
4510
|
-
_defineProperty(Plugin, preGenericsInitialization, void 0);
|
|
4511
|
-
_defineProperty(Plugin, preInitialization, void 0);
|
|
4512
|
-
_defineProperty(Plugin, postInitialization, void 0);
|
|
4513
|
-
_defineProperty(Plugin, preLoad, void 0);
|
|
4514
|
-
_defineProperty(Plugin, postListen, void 0);
|
|
4515
|
-
|
|
4516
|
-
//#endregion
|
|
4517
|
-
export { AliasPiece, AliasStore, ApplicationCommandRegistry, ApplicationCommandRegistryEntry, ApplyOptions, ArgumentError, AutocompleteInteraction, BaseInteraction, ChatInputCommandInteraction, ChatInputRouterError, ChatInputRouterErrors, Client, Command, CommandInteraction, CommandLoaderStrategy, CommandRegistry, CommandRouter, CommandStore, CommandStoreRouter, Enumerable, EnumerableMethod, Events, HotModuleReloader, HttpCodes, Identifiers, InteractionHandler, InteractionHandlerStore, Listener, ListenerLoaderStrategy, ListenerStore, LoaderError, LogLevel, Logger, Message, MessageComponentButtonInteraction, MessageComponentChannelSelectInteraction, MessageComponentInteraction, MessageComponentMentionableSelectInteraction, MessageComponentRoleSelectInteraction, MessageComponentStringSelectInteraction as MessageComponentSelectMenuInteraction, MessageComponentStringSelectInteraction, MessageComponentUserSelectInteraction, MessageContextMenuCommandInteraction, MissingExportsError, ModalSubmitInteraction, PartialMessage, Piece, Plugin, PluginHook, PluginManager, PreconditionError, RegisterCommand, RegisterMessageCommand, RegisterSubcommand, RegisterSubcommandGroup, RegisterUserCommand, RequiresClientPermissions, RequiresDMContext, RequiresGuildContext, RequiresUserPermissions, RestrictGuildIds, Store, StoreRegistry, StringIdParser, UserContextMenuCommandInteraction, UserError, applicationCommandRegistry, container, createClassDecorator, createFunctionPrecondition, createMethodDecorator, createProxy, extractTopLevelOptions, getMissingPermissions, makeInteraction, postInitialization, postListen, preGenericsInitialization, preInitialization, preLoad, resolvePermissions, restrictedGuildIdRegistry, toPermissionNames, transformAutocompleteInteraction, transformInteraction, transformMessageInteraction, transformUserInteraction };
|
|
4213
|
+
export { AliasPiece, AliasStore, ApplicationCommandRegistry, ApplicationCommandRegistryEntry, ArgumentError, AutocompleteInteraction, BaseInteraction, ChatInputCommandInteraction, ChatInputRouterError, ChatInputRouterErrors, Client, Command, CommandInteraction, CommandLoaderStrategy, CommandRegistry, CommandRouter, CommandStore, CommandStoreRouter, Events, HotModuleReloader, HttpCodes, Identifiers, InteractionHandler, InteractionHandlerStore, Listener, ListenerLoaderStrategy, ListenerStore, LoaderError, LogLevel, Logger, Message, MessageComponentButtonInteraction, MessageComponentChannelSelectInteraction, MessageComponentInteraction, MessageComponentMentionableSelectInteraction, MessageComponentRoleSelectInteraction, MessageComponentStringSelectInteraction as MessageComponentSelectMenuInteraction, MessageComponentStringSelectInteraction, MessageComponentUserSelectInteraction, MessageContextMenuCommandInteraction, MissingExportsError, ModalSubmitInteraction, PartialMessage, Piece, Plugin, PluginHook, PluginManager, PreconditionError, RegisterCommand, RegisterMessageCommand, RegisterSubcommand, RegisterSubcommandGroup, RegisterUserCommand, RestrictGuildIds, Store, StoreRegistry, StringIdParser, UserContextMenuCommandInteraction, UserError, applicationCommandRegistry, container, extractTopLevelOptions, getMissingPermissions, makeInteraction, postInitialization, postListen, preGenericsInitialization, preInitialization, preLoad, resolvePermissions, restrictedGuildIdRegistry, toPermissionNames, transformAutocompleteInteraction, transformInteraction, transformMessageInteraction, transformUserInteraction };
|
|
4518
4214
|
//# sourceMappingURL=index.js.map
|