@sapphire/decorators 4.3.9-next.f731c3c.0 β†’ 5.0.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ # [@sapphire/decorators@5.0.0](https://github.com/sapphiredev/utilities/compare/@sapphire/decorators@4.3.8...@sapphire/decorators@5.0.0) - (2022-08-20)
6
+
7
+ ## πŸ› Bug Fixes
8
+
9
+ - Manually set version to 5.0.0 to cover @sapphire/framework@3.0.0 ([48e083f](https://github.com/sapphiredev/utilities/commit/48e083f9d4cbdb7e6c204ce75a6d2d387662dfae))
10
+ - **deps:** Update all non-major dependencies ([2308bd7](https://github.com/sapphiredev/utilities/commit/2308bd74356b6b2e0c12995b25f4d8ade4803fe9))
11
+
12
+ ## πŸ“ Documentation
13
+
14
+ - Add @muchnameless as a contributor ([a1221fe](https://github.com/sapphiredev/utilities/commit/a1221fea68506e99591d5d00ec552a07c26833f9))
15
+ - Add @enxg as a contributor ([d2382f0](https://github.com/sapphiredev/utilities/commit/d2382f04e3909cb4ad11798a0a10e683f6cf5383))
16
+ - Add @EvolutionX-10 as a contributor ([efc3a32](https://github.com/sapphiredev/utilities/commit/efc3a320a72ae258996dd62866d206c33f8d4961))
17
+
5
18
  # [@sapphire/decorators@4.3.7](https://github.com/sapphiredev/utilities/compare/@sapphire/decorators@4.3.6...@sapphire/decorators@4.3.7) - (2022-07-13)
6
19
 
7
20
  ## 🏠 Refactor
package/README.md CHANGED
@@ -102,6 +102,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
102
102
  </tr>
103
103
  <tr>
104
104
  <td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">πŸ“–</a></td>
105
+ <td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">πŸ’»</a></td>
106
+ <td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes GenΓ§</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">πŸ’»</a></td>
107
+ <td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">πŸ’»</a></td>
105
108
  </tr>
106
109
  </table>
107
110
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,240 @@
1
- export * from './base-decorators';
2
- export * from './djs-decorators';
3
- export * from './piece-decorators';
4
- export * from './utils';
5
- //# sourceMappingURL=index.d.ts.map
1
+ import { PermissionResolvable } from 'discord.js';
2
+ import { Piece } from '@sapphire/framework';
3
+ import { Container } from '@sapphire/pieces';
4
+
5
+ /**
6
+ * Decorator that sets the enumerable property of a class field to the desired value.
7
+ * @param value Whether the property should be enumerable or not
8
+ */
9
+ declare function Enumerable(value: boolean): (target: unknown, key: string) => void;
10
+ /**
11
+ * Decorator that sets the enumerable property of a class method to the desired value.
12
+ * @param value Whether the method should be enumerable or not
13
+ */
14
+ declare function EnumerableMethod(value: boolean): MethodDecorator;
15
+
16
+ /**
17
+ * The function precondition interface.
18
+ */
19
+ interface FunctionPrecondition {
20
+ /**
21
+ * The arguments passed to the function or class' method.
22
+ */
23
+ (...args: any[]): boolean | Promise<boolean>;
24
+ }
25
+ /**
26
+ * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.
27
+ */
28
+ interface FunctionFallback {
29
+ /**
30
+ * The arguments passed to the function or class' method.
31
+ */
32
+ (...args: any[]): unknown;
33
+ }
34
+ /**
35
+ * Utility to make a method decorator with lighter syntax and inferred types.
36
+ *
37
+ * ```typescript
38
+ * // Enumerable function
39
+ * function enumerableMethod(value: boolean) {
40
+ * return createMethodDecorator((_target, _propertyKey, descriptor) => {
41
+ * descriptor.enumerable = value;
42
+ * });
43
+ * }
44
+ * ```
45
+ * @param fn The method to decorate
46
+ */
47
+ declare function createMethodDecorator(fn: MethodDecorator): MethodDecorator;
48
+ /**
49
+ * Utility to make a class decorator with lighter syntax and inferred types.
50
+ * @param fn The class to decorate
51
+ * @see {@link ApplyOptions}
52
+ */
53
+ declare function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator;
54
+ /**
55
+ * Utility to make function preconditions.
56
+ *
57
+ * ```typescript
58
+ * // No fallback (returns undefined)
59
+ * function requireGuild(value: number) {
60
+ * return createFunctionPrecondition((message: Message) =>
61
+ * message.guild !== null
62
+ * );
63
+ * }
64
+ *
65
+ * // With fallback
66
+ * function requireGuild(
67
+ * value: number,
68
+ * fallback: () => unknown = () => undefined
69
+ * ) {
70
+ * return createFunctionPrecondition(
71
+ * (message: Message) => message.guild !== null,
72
+ * fallback
73
+ * );
74
+ * }
75
+ * ```
76
+ * @since 1.0.0
77
+ * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback
78
+ * @param fallback The fallback value that defines what the method should return in case the precondition fails
79
+ */
80
+ declare function createFunctionPrecondition(precondition: FunctionPrecondition, fallback?: FunctionFallback): MethodDecorator;
81
+ /**
82
+ * Creates a new proxy to efficiently add properties to class without creating subclasses
83
+ * @param target The constructor of the class to modify
84
+ * @param handler The handler function to modify the constructor behavior for the target
85
+ * @hidden
86
+ */
87
+ declare function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T;
88
+
89
+ declare enum DecoratorIdentifiers {
90
+ RequiresClientPermissionsGuildOnly = "requiresClientPermissionsGuildOnly",
91
+ RequiresClientPermissionsMissingPermissions = "requiresClientPermissionsMissingPermissions",
92
+ RequiresUserPermissionsGuildOnly = "requiresUserPermissionsGuildOnly",
93
+ RequiresUserPermissionsMissingPermissions = "requiresUserPermissionsMissingPermissions"
94
+ }
95
+ /**
96
+ * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
97
+ * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}
98
+ * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
99
+ * @param permissionsResolvable Permissions that the method should have.
100
+ * @example
101
+ * ```typescript
102
+ * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';
103
+ * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
104
+ * import type { Message } from 'discord.js';
105
+ *
106
+ * (at)ApplyOptions<SubCommandPluginCommandOptions>({
107
+ * aliases: ['cws'],
108
+ * description: 'A basic command with some subcommands',
109
+ * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
110
+ * })
111
+ * export default class extends SubCommandPluginCommand {
112
+ * // Anyone should be able to view the result, but not modify
113
+ * public async show(message: Message) {
114
+ * return message.channel.send('Showing!');
115
+ * }
116
+ *
117
+ * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
118
+ * public async add(message: Message) {
119
+ * return message.channel.send('Adding!');
120
+ * }
121
+ *
122
+ * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
123
+ * public async remove(message: Message) {
124
+ * return message.channel.send('Removing!');
125
+ * }
126
+ *
127
+ * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
128
+ * public async reset(message: Message) {
129
+ * return message.channel.send('Resetting!');
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ declare const RequiresClientPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
135
+ /**
136
+ * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
137
+ * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}
138
+ * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
139
+ * @param permissionsResolvable Permissions that the method should have.
140
+ * @example
141
+ * ```typescript
142
+ * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';
143
+ * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
144
+ * import type { Message } from 'discord.js';
145
+ *
146
+ * (at)ApplyOptions<SubCommandPluginCommandOptions>({
147
+ * aliases: ['cws'],
148
+ * description: 'A basic command with some subcommands',
149
+ * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
150
+ * })
151
+ * export default class extends SubCommandPluginCommand {
152
+ * // Anyone should be able to view the result, but not modify
153
+ * public async show(message: Message) {
154
+ * return message.channel.send('Showing!');
155
+ * }
156
+ *
157
+ * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
158
+ * public async add(message: Message) {
159
+ * return message.channel.send('Adding!');
160
+ * }
161
+ *
162
+ * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
163
+ * public async remove(message: Message) {
164
+ * return message.channel.send('Removing!');
165
+ * }
166
+ *
167
+ * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
168
+ * public async reset(message: Message) {
169
+ * return message.channel.send('Resetting!');
170
+ * }
171
+ * }
172
+ * ```
173
+ */
174
+ declare const RequiresUserPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
175
+ /**
176
+ * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance
177
+ * @since 1.0.0
178
+ * @param fallback The fallback value passed to `createFunctionInhibitor`
179
+ */
180
+ declare function RequiresGuildContext(fallback?: FunctionFallback): MethodDecorator;
181
+ /**
182
+ * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance
183
+ * @since 1.0.0
184
+ * @param fallback The fallback value passed to `createFunctionInhibitor`
185
+ */
186
+ declare function RequiresDMContext(fallback?: FunctionFallback): MethodDecorator;
187
+
188
+ /**
189
+ * Decorator function that applies given options to any Sapphire piece
190
+ * @param options The options to pass to the piece constructor
191
+ * @example
192
+ * ```typescript
193
+ * import { ApplyOptions } from '@sapphire/decorators';
194
+ * import { Command } from '@sapphire/framework';
195
+ * import type { Message } from 'discord.js';
196
+ *
197
+ * @ApplyOptions<Command.Options>({
198
+ * description: 'ping pong',
199
+ * enabled: true
200
+ * })
201
+ * export class UserCommand extends Command {
202
+ * public override async messageRun(message: Message) {
203
+ * const msg = await message.channel.send('Ping?');
204
+ *
205
+ * return msg.edit(
206
+ * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`
207
+ * );
208
+ * }
209
+ * }
210
+ * ```
211
+ * @example
212
+ * ```typescript
213
+ * import { ApplyOptions } from '@sapphire/decorators';
214
+ * import { Listener } from '@sapphire/framework';
215
+ * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';
216
+ *
217
+ * @ApplyOptions<Listener.Options>(({ container }) => ({
218
+ * description: 'Handle Raw Message Delete events',
219
+ * emitter: container.client.ws,
220
+ * event: GatewayDispatchEvents.MessageDelete
221
+ * }))
222
+ * export class UserListener extends Listener {
223
+ * public override run(data: GatewayMessageDeleteDispatch['d']): void {
224
+ * if (!data.guild_id) return;
225
+ *
226
+ * const guild = this.container.client.guilds.cache.get(data.guild_id);
227
+ * if (!guild || !guild.channels.cache.has(data.channel_id)) return;
228
+ *
229
+ * // Do something with the data
230
+ * }
231
+ * }
232
+ * ```
233
+ */
234
+ declare function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator;
235
+ interface ApplyOptionsCallbackParameters {
236
+ container: Container;
237
+ context: Piece.Context;
238
+ }
239
+
240
+ export { ApplyOptions, ApplyOptionsCallbackParameters, DecoratorIdentifiers, Enumerable, EnumerableMethod, FunctionFallback, FunctionPrecondition, RequiresClientPermissions, RequiresDMContext, RequiresGuildContext, RequiresUserPermissions, createClassDecorator, createFunctionPrecondition, createMethodDecorator, createProxy };
package/dist/index.js CHANGED
@@ -106,26 +106,30 @@ var DecoratorIdentifiers = /* @__PURE__ */ ((DecoratorIdentifiers2) => {
106
106
  DecoratorIdentifiers2["RequiresUserPermissionsMissingPermissions"] = "requiresUserPermissionsMissingPermissions";
107
107
  return DecoratorIdentifiers2;
108
108
  })(DecoratorIdentifiers || {});
109
- var DMAvailablePermissions = new import_discord2.Permissions(~new import_discord2.Permissions([
110
- "ADD_REACTIONS",
111
- "ATTACH_FILES",
112
- "EMBED_LINKS",
113
- "READ_MESSAGE_HISTORY",
114
- "SEND_MESSAGES",
115
- "USE_EXTERNAL_EMOJIS",
116
- "VIEW_CHANNEL"
117
- ]).bitfield & import_discord2.Permissions.ALL);
118
- var DMAvailableUserPermissions = new import_discord2.Permissions(~new import_discord2.Permissions([
119
- "ADD_REACTIONS",
120
- "ATTACH_FILES",
121
- "EMBED_LINKS",
122
- "READ_MESSAGE_HISTORY",
123
- "SEND_MESSAGES",
124
- "USE_EXTERNAL_EMOJIS",
125
- "VIEW_CHANNEL",
126
- "USE_EXTERNAL_STICKERS",
127
- "MENTION_EVERYONE"
128
- ]).bitfield & import_discord2.Permissions.ALL);
109
+ var DMAvailablePermissions = new import_discord2.Permissions(
110
+ ~new import_discord2.Permissions([
111
+ "ADD_REACTIONS",
112
+ "ATTACH_FILES",
113
+ "EMBED_LINKS",
114
+ "READ_MESSAGE_HISTORY",
115
+ "SEND_MESSAGES",
116
+ "USE_EXTERNAL_EMOJIS",
117
+ "VIEW_CHANNEL"
118
+ ]).bitfield & import_discord2.Permissions.ALL
119
+ );
120
+ var DMAvailableUserPermissions = new import_discord2.Permissions(
121
+ ~new import_discord2.Permissions([
122
+ "ADD_REACTIONS",
123
+ "ATTACH_FILES",
124
+ "EMBED_LINKS",
125
+ "READ_MESSAGE_HISTORY",
126
+ "SEND_MESSAGES",
127
+ "USE_EXTERNAL_EMOJIS",
128
+ "VIEW_CHANNEL",
129
+ "USE_EXTERNAL_STICKERS",
130
+ "MENTION_EVERYONE"
131
+ ]).bitfield & import_discord2.Permissions.ALL
132
+ );
129
133
  var RequiresClientPermissions = /* @__PURE__ */ __name((...permissionsResolvable) => {
130
134
  const resolved = new import_discord2.Permissions(permissionsResolvable);
131
135
  const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);
@@ -188,12 +192,14 @@ __name(RequiresDMContext, "RequiresDMContext");
188
192
  // src/piece-decorators.ts
189
193
  var import_framework2 = require("@sapphire/framework");
190
194
  function ApplyOptions(optionsOrFn) {
191
- return createClassDecorator((target) => createProxy(target, {
192
- construct: (ctor, [context, baseOptions = {}]) => new ctor(context, {
193
- ...baseOptions,
194
- ...typeof optionsOrFn === "function" ? optionsOrFn({ container: import_framework2.container, context }) : optionsOrFn
195
+ return createClassDecorator(
196
+ (target) => createProxy(target, {
197
+ construct: (ctor, [context, baseOptions = {}]) => new ctor(context, {
198
+ ...baseOptions,
199
+ ...typeof optionsOrFn === "function" ? optionsOrFn({ container: import_framework2.container, context }) : optionsOrFn
200
+ })
195
201
  })
196
- }));
202
+ );
197
203
  }
198
204
  __name(ApplyOptions, "ApplyOptions");
199
205
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/base-decorators.ts","../src/djs-decorators.ts","../src/piece-decorators.ts"],"sourcesContent":["export * from './base-decorators';\nexport * from './djs-decorators';\nexport * from './piece-decorators';\nexport * from './utils';\n","/**\n * The function precondition interface.\n */\nexport interface FunctionPrecondition {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): boolean | Promise<boolean>;\n}\n\n/**\n * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.\n */\nexport interface FunctionFallback {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): unknown;\n}\n\n/**\n * Utility to make a method decorator with lighter syntax and inferred types.\n *\n * ```typescript\n * // Enumerable function\n *\tfunction enumerableMethod(value: boolean) {\n *\t\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n *\t\t\tdescriptor.enumerable = value;\n *\t\t});\n *\t}\n * ```\n * @param fn The method to decorate\n */\nexport function createMethodDecorator(fn: MethodDecorator): MethodDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make a class decorator with lighter syntax and inferred types.\n * @param fn The class to decorate\n * @see {@link ApplyOptions}\n */\nexport function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make function preconditions.\n *\n * ```typescript\n * // No fallback (returns undefined)\n * function requireGuild(value: number) {\n * return createFunctionPrecondition((message: Message) =>\n * message.guild !== null\n * );\n * }\n *\n * // With fallback\n * function requireGuild(\n * value: number,\n * fallback: () => unknown = () => undefined\n * ) {\n * return createFunctionPrecondition(\n * (message: Message) => message.guild !== null,\n * fallback\n * );\n * }\n * ```\n * @since 1.0.0\n * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback\n * @param fallback The fallback value that defines what the method should return in case the precondition fails\n */\nexport function createFunctionPrecondition(precondition: FunctionPrecondition, fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tconst method = descriptor.value;\n\t\tif (!method) throw new Error('Function preconditions require a [[value]].');\n\t\tif (typeof method !== 'function') throw new Error('Function preconditions can only be applied to functions.');\n\n\t\tdescriptor.value = async function descriptorValue(this: (...args: any[]) => any, ...args: any[]) {\n\t\t\tconst canRun = await precondition(...args);\n\t\t\treturn canRun ? method.call(this, ...args) : fallback.call(this, ...args);\n\t\t} as unknown as undefined;\n\t});\n}\n\n/**\n * Creates a new proxy to efficiently add properties to class without creating subclasses\n * @param target The constructor of the class to modify\n * @param handler The handler function to modify the constructor behavior for the target\n * @hidden\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {\n\treturn new Proxy(target, {\n\t\t...handler,\n\t\tget: (target, property) => {\n\t\t\tconst value = Reflect.get(target, property);\n\t\t\treturn typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(target, args) : value;\n\t\t}\n\t});\n}\n","import type { NonNullObject } from '@sapphire/utilities';\nimport { createMethodDecorator } from './utils';\n\n/**\n * Decorator that sets the enumerable property of a class field to the desired value.\n * @param value Whether the property should be enumerable or not\n */\nexport function Enumerable(value: boolean) {\n\treturn (target: unknown, key: string) => {\n\t\tReflect.defineProperty(target as NonNullObject, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as NonNullObject, key, {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: value,\n\t\t\t\t\tvalue: val,\n\t\t\t\t\twritable: true\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t};\n}\n\n/**\n * Decorator that sets the enumerable property of a class method to the desired value.\n * @param value Whether the method should be enumerable or not\n */\nexport function EnumerableMethod(value: boolean) {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tdescriptor.enumerable = value;\n\t});\n}\n","import { isDMChannel, isGuildBasedChannel } from '@sapphire/discord.js-utilities';\nimport { UserError } from '@sapphire/framework';\nimport { Message, PermissionResolvable, Permissions } from 'discord.js';\nimport { createFunctionPrecondition, FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new Permissions(\n\t~new Permissions([\n\t\t//\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL'\n\t]).bitfield & Permissions.ALL\n);\n\nconst DMAvailableUserPermissions = new Permissions(\n\t~new Permissions([\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL',\n\t\t'USE_EXTERNAL_STICKERS',\n\t\t'MENTION_EVERYONE'\n\t]).bitfield & Permissions.ALL\n);\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresClientPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.guild!.me!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresUserPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.member!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresGuildContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild !== null, fallback);\n}\n\n/**\n * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresDMContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild === null, fallback);\n}\n","import { container, type Piece } from '@sapphire/framework';\nimport type { Container } from '@sapphire/pieces';\nimport type { Ctor } from '@sapphire/utilities';\nimport { createClassDecorator, createProxy } from './utils';\n\n/**\n * Decorator function that applies given options to any Sapphire piece\n * @param options The options to pass to the piece constructor\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import type { Message } from 'discord.js';\n *\n * @ApplyOptions<Command.Options>({\n * description: 'ping pong',\n * enabled: true\n * })\n * export class UserCommand extends Command {\n * public override async messageRun(message: Message) {\n * const msg = await message.channel.send('Ping?');\n *\n * return msg.edit(\n * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`\n * );\n * }\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Listener } from '@sapphire/framework';\n * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';\n *\n * @ApplyOptions<Listener.Options>(({ container }) => ({\n * description: 'Handle Raw Message Delete events',\n * emitter: container.client.ws,\n * event: GatewayDispatchEvents.MessageDelete\n * }))\n * export class UserListener extends Listener {\n * public override run(data: GatewayMessageDeleteDispatch['d']): void {\n * if (!data.guild_id) return;\n *\n * const guild = this.container.client.guilds.cache.get(data.guild_id);\n * if (!guild || !guild.channels.cache.has(data.channel_id)) return;\n *\n * // Do something with the data\n * }\n * }\n * ```\n */\nexport function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator {\n\treturn createClassDecorator((target: Ctor<ConstructorParameters<typeof Piece>, Piece>) =>\n\t\tcreateProxy(target, {\n\t\t\tconstruct: (ctor, [context, baseOptions = {}]: [Piece.Context, Piece.Options]) =>\n\t\t\t\tnew ctor(context, {\n\t\t\t\t\t...baseOptions,\n\t\t\t\t\t...(typeof optionsOrFn === 'function' ? optionsOrFn({ container, context }) : optionsOrFn)\n\t\t\t\t})\n\t\t})\n\t);\n}\n\nexport interface ApplyOptionsCallbackParameters {\n\tcontainer: Container;\n\tcontext: Piece.Context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiCO,+BAA+B,IAAsC;AAC3E,SAAO;AACR;AAFgB;AAST,8BAA0E,IAA+B;AAC/G,SAAO;AACR;AAFgB;AA8BT,oCAAoC,cAAoC,WAA6B,MAAY,QAA4B;AACnJ,SAAO,sBAAsB,CAAC,SAAS,cAAc,eAAe;AACnE,UAAM,SAAS,WAAW;AAC1B,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM,6CAA6C;AAC1E,QAAI,OAAO,WAAW;AAAY,YAAM,IAAI,MAAM,0DAA0D;AAE5G,eAAW,QAAQ,yDAAiE,MAAa;AAChG,YAAM,SAAS,MAAM,aAAa,GAAG,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IAAI,2BAAU;AAAA,UACnB,YAAY;AAAA,UACZ,SAAS,+EAA+E;AAAA,UACxF,SAAS;AAAA,YACR,SAAS;AAAA,UACV;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,EACR,CAAC;AACF,GA5BuC;AAmChC,8BAA8B,WAA6B,MAAY,QAA4B;AACzG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;AAST,2BAA2B,WAA6B,MAAY,QAA4B;AACtG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;;;AC/LhB,wBAAsC;AAmD/B,sBAA+C,aAAsF;AAC3I,SAAO,qBAAqB,CAAC,WAC5B,YAAY,QAAQ;AAAA,IACnB,WAAW,CAAC,MAAM,CAAC,SAAS,cAAc,CAAC,OAC1C,IAAI,KAAK,SAAS;AAAA,MACjB,GAAG;AAAA,MACH,GAAI,OAAO,gBAAgB,aAAa,YAAY,EAAE,wCAAW,QAAQ,CAAC,IAAI;AAAA,IAC/E,CAAC;AAAA,EACH,CAAC,CACF;AACD;AAVgB;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/base-decorators.ts","../src/djs-decorators.ts","../src/piece-decorators.ts"],"sourcesContent":["export * from './base-decorators';\nexport * from './djs-decorators';\nexport * from './piece-decorators';\nexport * from './utils';\n","/**\n * The function precondition interface.\n */\nexport interface FunctionPrecondition {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): boolean | Promise<boolean>;\n}\n\n/**\n * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.\n */\nexport interface FunctionFallback {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): unknown;\n}\n\n/**\n * Utility to make a method decorator with lighter syntax and inferred types.\n *\n * ```typescript\n * // Enumerable function\n *\tfunction enumerableMethod(value: boolean) {\n *\t\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n *\t\t\tdescriptor.enumerable = value;\n *\t\t});\n *\t}\n * ```\n * @param fn The method to decorate\n */\nexport function createMethodDecorator(fn: MethodDecorator): MethodDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make a class decorator with lighter syntax and inferred types.\n * @param fn The class to decorate\n * @see {@link ApplyOptions}\n */\nexport function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make function preconditions.\n *\n * ```typescript\n * // No fallback (returns undefined)\n * function requireGuild(value: number) {\n * return createFunctionPrecondition((message: Message) =>\n * message.guild !== null\n * );\n * }\n *\n * // With fallback\n * function requireGuild(\n * value: number,\n * fallback: () => unknown = () => undefined\n * ) {\n * return createFunctionPrecondition(\n * (message: Message) => message.guild !== null,\n * fallback\n * );\n * }\n * ```\n * @since 1.0.0\n * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback\n * @param fallback The fallback value that defines what the method should return in case the precondition fails\n */\nexport function createFunctionPrecondition(precondition: FunctionPrecondition, fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tconst method = descriptor.value;\n\t\tif (!method) throw new Error('Function preconditions require a [[value]].');\n\t\tif (typeof method !== 'function') throw new Error('Function preconditions can only be applied to functions.');\n\n\t\tdescriptor.value = async function descriptorValue(this: (...args: any[]) => any, ...args: any[]) {\n\t\t\tconst canRun = await precondition(...args);\n\t\t\treturn canRun ? method.call(this, ...args) : fallback.call(this, ...args);\n\t\t} as unknown as undefined;\n\t});\n}\n\n/**\n * Creates a new proxy to efficiently add properties to class without creating subclasses\n * @param target The constructor of the class to modify\n * @param handler The handler function to modify the constructor behavior for the target\n * @hidden\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {\n\treturn new Proxy(target, {\n\t\t...handler,\n\t\tget: (target, property) => {\n\t\t\tconst value = Reflect.get(target, property);\n\t\t\treturn typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(target, args) : value;\n\t\t}\n\t});\n}\n","import type { NonNullObject } from '@sapphire/utilities';\nimport { createMethodDecorator } from './utils';\n\n/**\n * Decorator that sets the enumerable property of a class field to the desired value.\n * @param value Whether the property should be enumerable or not\n */\nexport function Enumerable(value: boolean) {\n\treturn (target: unknown, key: string) => {\n\t\tReflect.defineProperty(target as NonNullObject, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as NonNullObject, key, {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: value,\n\t\t\t\t\tvalue: val,\n\t\t\t\t\twritable: true\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t};\n}\n\n/**\n * Decorator that sets the enumerable property of a class method to the desired value.\n * @param value Whether the method should be enumerable or not\n */\nexport function EnumerableMethod(value: boolean) {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tdescriptor.enumerable = value;\n\t});\n}\n","import { isDMChannel, isGuildBasedChannel } from '@sapphire/discord.js-utilities';\nimport { UserError } from '@sapphire/framework';\nimport { Message, PermissionResolvable, Permissions } from 'discord.js';\nimport { createFunctionPrecondition, FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new Permissions(\n\t~new Permissions([\n\t\t//\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL'\n\t]).bitfield & Permissions.ALL\n);\n\nconst DMAvailableUserPermissions = new Permissions(\n\t~new Permissions([\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL',\n\t\t'USE_EXTERNAL_STICKERS',\n\t\t'MENTION_EVERYONE'\n\t]).bitfield & Permissions.ALL\n);\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresClientPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.guild!.me!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresUserPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.member!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresGuildContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild !== null, fallback);\n}\n\n/**\n * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresDMContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild === null, fallback);\n}\n","import { container, type Piece } from '@sapphire/framework';\nimport type { Container } from '@sapphire/pieces';\nimport type { Ctor } from '@sapphire/utilities';\nimport { createClassDecorator, createProxy } from './utils';\n\n/**\n * Decorator function that applies given options to any Sapphire piece\n * @param options The options to pass to the piece constructor\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import type { Message } from 'discord.js';\n *\n * @ApplyOptions<Command.Options>({\n * description: 'ping pong',\n * enabled: true\n * })\n * export class UserCommand extends Command {\n * public override async messageRun(message: Message) {\n * const msg = await message.channel.send('Ping?');\n *\n * return msg.edit(\n * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`\n * );\n * }\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Listener } from '@sapphire/framework';\n * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';\n *\n * @ApplyOptions<Listener.Options>(({ container }) => ({\n * description: 'Handle Raw Message Delete events',\n * emitter: container.client.ws,\n * event: GatewayDispatchEvents.MessageDelete\n * }))\n * export class UserListener extends Listener {\n * public override run(data: GatewayMessageDeleteDispatch['d']): void {\n * if (!data.guild_id) return;\n *\n * const guild = this.container.client.guilds.cache.get(data.guild_id);\n * if (!guild || !guild.channels.cache.has(data.channel_id)) return;\n *\n * // Do something with the data\n * }\n * }\n * ```\n */\nexport function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator {\n\treturn createClassDecorator((target: Ctor<ConstructorParameters<typeof Piece>, Piece>) =>\n\t\tcreateProxy(target, {\n\t\t\tconstruct: (ctor, [context, baseOptions = {}]: [Piece.Context, Piece.Options]) =>\n\t\t\t\tnew ctor(context, {\n\t\t\t\t\t...baseOptions,\n\t\t\t\t\t...(typeof optionsOrFn === 'function' ? optionsOrFn({ container, context }) : optionsOrFn)\n\t\t\t\t})\n\t\t})\n\t);\n}\n\nexport interface ApplyOptionsCallbackParameters {\n\tcontainer: Container;\n\tcontext: Piece.Context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiCO,SAAS,sBAAsB,IAAsC;AAC3E,SAAO;AACR;AAFgB;AAST,SAAS,qBAAiE,IAA+B;AAC/G,SAAO;AACR;AAFgB;AA8BT,SAAS,2BAA2B,cAAoC,WAA6B,MAAY,QAA4B;AACnJ,SAAO,sBAAsB,CAAC,SAAS,cAAc,eAAe;AACnE,UAAM,SAAS,WAAW;AAC1B,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM,6CAA6C;AAC1E,QAAI,OAAO,WAAW;AAAY,YAAM,IAAI,MAAM,0DAA0D;AAE5G,eAAW,QAAQ,sCAAe,mBAAkD,MAAa;AAChG,YAAM,SAAS,MAAM,aAAa,GAAG,IAAI;AACzC,aAAO,SAAS,OAAO,KAAK,MAAM,GAAG,IAAI,IAAI,SAAS,KAAK,MAAM,GAAG,IAAI;AAAA,IACzE,GAHmB;AAAA,EAIpB,CAAC;AACF;AAXgB;AAoBT,SAAS,YAA8B,QAAW,SAA0C;AAClG,SAAO,IAAI,MAAM,QAAQ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SAAS;AAAA,UACV;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,EACR,CAAC;AACF,GA5BuC;AAmChC,SAAS,qBAAqB,WAA6B,MAAY,QAA4B;AACzG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;AAST,SAAS,kBAAkB,WAA6B,MAAY,QAA4B;AACtG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;;;AC/LhB,IAAAC,oBAAsC;AAmD/B,SAAS,aAAsC,aAAsF;AAC3I,SAAO;AAAA,IAAqB,CAAC,WAC5B,YAAY,QAAQ;AAAA,MACnB,WAAW,CAAC,MAAM,CAAC,SAAS,cAAc,CAAC,CAAC,MAC3C,IAAI,KAAK,SAAS;AAAA,QACjB,GAAG;AAAA,QACH,GAAI,OAAO,gBAAgB,aAAa,YAAY,EAAE,wCAAW,QAAQ,CAAC,IAAI;AAAA,MAC/E,CAAC;AAAA,IACH,CAAC;AAAA,EACF;AACD;AAVgB;","names":["target","import_discord","DecoratorIdentifiers","import_framework"]}
package/dist/index.mjs CHANGED
@@ -70,26 +70,30 @@ var DecoratorIdentifiers = /* @__PURE__ */ ((DecoratorIdentifiers2) => {
70
70
  DecoratorIdentifiers2["RequiresUserPermissionsMissingPermissions"] = "requiresUserPermissionsMissingPermissions";
71
71
  return DecoratorIdentifiers2;
72
72
  })(DecoratorIdentifiers || {});
73
- var DMAvailablePermissions = new Permissions(~new Permissions([
74
- "ADD_REACTIONS",
75
- "ATTACH_FILES",
76
- "EMBED_LINKS",
77
- "READ_MESSAGE_HISTORY",
78
- "SEND_MESSAGES",
79
- "USE_EXTERNAL_EMOJIS",
80
- "VIEW_CHANNEL"
81
- ]).bitfield & Permissions.ALL);
82
- var DMAvailableUserPermissions = new Permissions(~new Permissions([
83
- "ADD_REACTIONS",
84
- "ATTACH_FILES",
85
- "EMBED_LINKS",
86
- "READ_MESSAGE_HISTORY",
87
- "SEND_MESSAGES",
88
- "USE_EXTERNAL_EMOJIS",
89
- "VIEW_CHANNEL",
90
- "USE_EXTERNAL_STICKERS",
91
- "MENTION_EVERYONE"
92
- ]).bitfield & Permissions.ALL);
73
+ var DMAvailablePermissions = new Permissions(
74
+ ~new Permissions([
75
+ "ADD_REACTIONS",
76
+ "ATTACH_FILES",
77
+ "EMBED_LINKS",
78
+ "READ_MESSAGE_HISTORY",
79
+ "SEND_MESSAGES",
80
+ "USE_EXTERNAL_EMOJIS",
81
+ "VIEW_CHANNEL"
82
+ ]).bitfield & Permissions.ALL
83
+ );
84
+ var DMAvailableUserPermissions = new Permissions(
85
+ ~new Permissions([
86
+ "ADD_REACTIONS",
87
+ "ATTACH_FILES",
88
+ "EMBED_LINKS",
89
+ "READ_MESSAGE_HISTORY",
90
+ "SEND_MESSAGES",
91
+ "USE_EXTERNAL_EMOJIS",
92
+ "VIEW_CHANNEL",
93
+ "USE_EXTERNAL_STICKERS",
94
+ "MENTION_EVERYONE"
95
+ ]).bitfield & Permissions.ALL
96
+ );
93
97
  var RequiresClientPermissions = /* @__PURE__ */ __name((...permissionsResolvable) => {
94
98
  const resolved = new Permissions(permissionsResolvable);
95
99
  const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);
@@ -152,12 +156,14 @@ __name(RequiresDMContext, "RequiresDMContext");
152
156
  // src/piece-decorators.ts
153
157
  import { container } from "@sapphire/framework";
154
158
  function ApplyOptions(optionsOrFn) {
155
- return createClassDecorator((target) => createProxy(target, {
156
- construct: (ctor, [context, baseOptions = {}]) => new ctor(context, {
157
- ...baseOptions,
158
- ...typeof optionsOrFn === "function" ? optionsOrFn({ container, context }) : optionsOrFn
159
+ return createClassDecorator(
160
+ (target) => createProxy(target, {
161
+ construct: (ctor, [context, baseOptions = {}]) => new ctor(context, {
162
+ ...baseOptions,
163
+ ...typeof optionsOrFn === "function" ? optionsOrFn({ container, context }) : optionsOrFn
164
+ })
159
165
  })
160
- }));
166
+ );
161
167
  }
162
168
  __name(ApplyOptions, "ApplyOptions");
163
169
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/base-decorators.ts","../src/djs-decorators.ts","../src/piece-decorators.ts"],"sourcesContent":["/**\n * The function precondition interface.\n */\nexport interface FunctionPrecondition {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): boolean | Promise<boolean>;\n}\n\n/**\n * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.\n */\nexport interface FunctionFallback {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): unknown;\n}\n\n/**\n * Utility to make a method decorator with lighter syntax and inferred types.\n *\n * ```typescript\n * // Enumerable function\n *\tfunction enumerableMethod(value: boolean) {\n *\t\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n *\t\t\tdescriptor.enumerable = value;\n *\t\t});\n *\t}\n * ```\n * @param fn The method to decorate\n */\nexport function createMethodDecorator(fn: MethodDecorator): MethodDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make a class decorator with lighter syntax and inferred types.\n * @param fn The class to decorate\n * @see {@link ApplyOptions}\n */\nexport function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make function preconditions.\n *\n * ```typescript\n * // No fallback (returns undefined)\n * function requireGuild(value: number) {\n * return createFunctionPrecondition((message: Message) =>\n * message.guild !== null\n * );\n * }\n *\n * // With fallback\n * function requireGuild(\n * value: number,\n * fallback: () => unknown = () => undefined\n * ) {\n * return createFunctionPrecondition(\n * (message: Message) => message.guild !== null,\n * fallback\n * );\n * }\n * ```\n * @since 1.0.0\n * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback\n * @param fallback The fallback value that defines what the method should return in case the precondition fails\n */\nexport function createFunctionPrecondition(precondition: FunctionPrecondition, fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tconst method = descriptor.value;\n\t\tif (!method) throw new Error('Function preconditions require a [[value]].');\n\t\tif (typeof method !== 'function') throw new Error('Function preconditions can only be applied to functions.');\n\n\t\tdescriptor.value = async function descriptorValue(this: (...args: any[]) => any, ...args: any[]) {\n\t\t\tconst canRun = await precondition(...args);\n\t\t\treturn canRun ? method.call(this, ...args) : fallback.call(this, ...args);\n\t\t} as unknown as undefined;\n\t});\n}\n\n/**\n * Creates a new proxy to efficiently add properties to class without creating subclasses\n * @param target The constructor of the class to modify\n * @param handler The handler function to modify the constructor behavior for the target\n * @hidden\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {\n\treturn new Proxy(target, {\n\t\t...handler,\n\t\tget: (target, property) => {\n\t\t\tconst value = Reflect.get(target, property);\n\t\t\treturn typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(target, args) : value;\n\t\t}\n\t});\n}\n","import type { NonNullObject } from '@sapphire/utilities';\nimport { createMethodDecorator } from './utils';\n\n/**\n * Decorator that sets the enumerable property of a class field to the desired value.\n * @param value Whether the property should be enumerable or not\n */\nexport function Enumerable(value: boolean) {\n\treturn (target: unknown, key: string) => {\n\t\tReflect.defineProperty(target as NonNullObject, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as NonNullObject, key, {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: value,\n\t\t\t\t\tvalue: val,\n\t\t\t\t\twritable: true\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t};\n}\n\n/**\n * Decorator that sets the enumerable property of a class method to the desired value.\n * @param value Whether the method should be enumerable or not\n */\nexport function EnumerableMethod(value: boolean) {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tdescriptor.enumerable = value;\n\t});\n}\n","import { isDMChannel, isGuildBasedChannel } from '@sapphire/discord.js-utilities';\nimport { UserError } from '@sapphire/framework';\nimport { Message, PermissionResolvable, Permissions } from 'discord.js';\nimport { createFunctionPrecondition, FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new Permissions(\n\t~new Permissions([\n\t\t//\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL'\n\t]).bitfield & Permissions.ALL\n);\n\nconst DMAvailableUserPermissions = new Permissions(\n\t~new Permissions([\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL',\n\t\t'USE_EXTERNAL_STICKERS',\n\t\t'MENTION_EVERYONE'\n\t]).bitfield & Permissions.ALL\n);\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresClientPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.guild!.me!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresUserPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.member!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresGuildContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild !== null, fallback);\n}\n\n/**\n * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresDMContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild === null, fallback);\n}\n","import { container, type Piece } from '@sapphire/framework';\nimport type { Container } from '@sapphire/pieces';\nimport type { Ctor } from '@sapphire/utilities';\nimport { createClassDecorator, createProxy } from './utils';\n\n/**\n * Decorator function that applies given options to any Sapphire piece\n * @param options The options to pass to the piece constructor\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import type { Message } from 'discord.js';\n *\n * @ApplyOptions<Command.Options>({\n * description: 'ping pong',\n * enabled: true\n * })\n * export class UserCommand extends Command {\n * public override async messageRun(message: Message) {\n * const msg = await message.channel.send('Ping?');\n *\n * return msg.edit(\n * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`\n * );\n * }\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Listener } from '@sapphire/framework';\n * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';\n *\n * @ApplyOptions<Listener.Options>(({ container }) => ({\n * description: 'Handle Raw Message Delete events',\n * emitter: container.client.ws,\n * event: GatewayDispatchEvents.MessageDelete\n * }))\n * export class UserListener extends Listener {\n * public override run(data: GatewayMessageDeleteDispatch['d']): void {\n * if (!data.guild_id) return;\n *\n * const guild = this.container.client.guilds.cache.get(data.guild_id);\n * if (!guild || !guild.channels.cache.has(data.channel_id)) return;\n *\n * // Do something with the data\n * }\n * }\n * ```\n */\nexport function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator {\n\treturn createClassDecorator((target: Ctor<ConstructorParameters<typeof Piece>, Piece>) =>\n\t\tcreateProxy(target, {\n\t\t\tconstruct: (ctor, [context, baseOptions = {}]: [Piece.Context, Piece.Options]) =>\n\t\t\t\tnew ctor(context, {\n\t\t\t\t\t...baseOptions,\n\t\t\t\t\t...(typeof optionsOrFn === 'function' ? optionsOrFn({ container, context }) : optionsOrFn)\n\t\t\t\t})\n\t\t})\n\t);\n}\n\nexport interface ApplyOptionsCallbackParameters {\n\tcontainer: Container;\n\tcontext: Piece.Context;\n}\n"],"mappings":";;;;AAiCO,+BAA+B,IAAsC;AAC3E,SAAO;AACR;AAFgB;AAST,8BAA0E,IAA+B;AAC/G,SAAO;AACR;AAFgB;AA8BT,oCAAoC,cAAoC,WAA6B,MAAY,QAA4B;AACnJ,SAAO,sBAAsB,CAAC,SAAS,cAAc,eAAe;AACnE,UAAM,SAAS,WAAW;AAC1B,QAA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O,GAAG;AACzC,YAAM,qBAAqB,QAAQ,QAAQ,eAAe,QAAQ,MAAO,EAAE,QAAQ,QAAQ;AAE3F,UAAI,mBAAmB,QAAQ;AAC9B,cAAM,IAAI,UAAU;AAAA,UACnB,YAAY;AAAA,UACZ,SAAS,+EAA+E;AAAA,UACxF,SAAS;AAAA,YACR,SAAS;AAAA,UACV;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,EACR,CAAC;AACF,GA5BuC;AAmChC,8BAA8B,WAA6B,MAAY,QAA4B;AACzG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;AAST,2BAA2B,WAA6B,MAAY,QAA4B;AACtG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;;;AC/LhB;AAmDO,sBAA+C,aAAsF;AAC3I,SAAO,qBAAqB,CAAC,WAC5B,YAAY,QAAQ;AAAA,IACnB,WAAW,CAAC,MAAM,CAAC,SAAS,cAAc,CAAC,OAC1C,IAAI,KAAK,SAAS;AAAA,MACjB,GAAG;AAAA,MACH,GAAI,OAAO,gBAAgB,aAAa,YAAY,EAAE,WAAW,QAAQ,CAAC,IAAI;AAAA,IAC/E,CAAC;AAAA,EACH,CAAC,CACF;AACD;AAVgB;","names":[]}
1
+ {"version":3,"sources":["../src/utils.ts","../src/base-decorators.ts","../src/djs-decorators.ts","../src/piece-decorators.ts"],"sourcesContent":["/**\n * The function precondition interface.\n */\nexport interface FunctionPrecondition {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): boolean | Promise<boolean>;\n}\n\n/**\n * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.\n */\nexport interface FunctionFallback {\n\t/**\n\t * The arguments passed to the function or class' method.\n\t */\n\t(...args: any[]): unknown;\n}\n\n/**\n * Utility to make a method decorator with lighter syntax and inferred types.\n *\n * ```typescript\n * // Enumerable function\n *\tfunction enumerableMethod(value: boolean) {\n *\t\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n *\t\t\tdescriptor.enumerable = value;\n *\t\t});\n *\t}\n * ```\n * @param fn The method to decorate\n */\nexport function createMethodDecorator(fn: MethodDecorator): MethodDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make a class decorator with lighter syntax and inferred types.\n * @param fn The class to decorate\n * @see {@link ApplyOptions}\n */\nexport function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator {\n\treturn fn;\n}\n\n/**\n * Utility to make function preconditions.\n *\n * ```typescript\n * // No fallback (returns undefined)\n * function requireGuild(value: number) {\n * return createFunctionPrecondition((message: Message) =>\n * message.guild !== null\n * );\n * }\n *\n * // With fallback\n * function requireGuild(\n * value: number,\n * fallback: () => unknown = () => undefined\n * ) {\n * return createFunctionPrecondition(\n * (message: Message) => message.guild !== null,\n * fallback\n * );\n * }\n * ```\n * @since 1.0.0\n * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback\n * @param fallback The fallback value that defines what the method should return in case the precondition fails\n */\nexport function createFunctionPrecondition(precondition: FunctionPrecondition, fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tconst method = descriptor.value;\n\t\tif (!method) throw new Error('Function preconditions require a [[value]].');\n\t\tif (typeof method !== 'function') throw new Error('Function preconditions can only be applied to functions.');\n\n\t\tdescriptor.value = async function descriptorValue(this: (...args: any[]) => any, ...args: any[]) {\n\t\t\tconst canRun = await precondition(...args);\n\t\t\treturn canRun ? method.call(this, ...args) : fallback.call(this, ...args);\n\t\t} as unknown as undefined;\n\t});\n}\n\n/**\n * Creates a new proxy to efficiently add properties to class without creating subclasses\n * @param target The constructor of the class to modify\n * @param handler The handler function to modify the constructor behavior for the target\n * @hidden\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {\n\treturn new Proxy(target, {\n\t\t...handler,\n\t\tget: (target, property) => {\n\t\t\tconst value = Reflect.get(target, property);\n\t\t\treturn typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(target, args) : value;\n\t\t}\n\t});\n}\n","import type { NonNullObject } from '@sapphire/utilities';\nimport { createMethodDecorator } from './utils';\n\n/**\n * Decorator that sets the enumerable property of a class field to the desired value.\n * @param value Whether the property should be enumerable or not\n */\nexport function Enumerable(value: boolean) {\n\treturn (target: unknown, key: string) => {\n\t\tReflect.defineProperty(target as NonNullObject, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as NonNullObject, key, {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: value,\n\t\t\t\t\tvalue: val,\n\t\t\t\t\twritable: true\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t};\n}\n\n/**\n * Decorator that sets the enumerable property of a class method to the desired value.\n * @param value Whether the method should be enumerable or not\n */\nexport function EnumerableMethod(value: boolean) {\n\treturn createMethodDecorator((_target, _propertyKey, descriptor) => {\n\t\tdescriptor.enumerable = value;\n\t});\n}\n","import { isDMChannel, isGuildBasedChannel } from '@sapphire/discord.js-utilities';\nimport { UserError } from '@sapphire/framework';\nimport { Message, PermissionResolvable, Permissions } from 'discord.js';\nimport { createFunctionPrecondition, FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new Permissions(\n\t~new Permissions([\n\t\t//\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL'\n\t]).bitfield & Permissions.ALL\n);\n\nconst DMAvailableUserPermissions = new Permissions(\n\t~new Permissions([\n\t\t'ADD_REACTIONS',\n\t\t'ATTACH_FILES',\n\t\t'EMBED_LINKS',\n\t\t'READ_MESSAGE_HISTORY',\n\t\t'SEND_MESSAGES',\n\t\t'USE_EXTERNAL_EMOJIS',\n\t\t'VIEW_CHANNEL',\n\t\t'USE_EXTERNAL_STICKERS',\n\t\t'MENTION_EVERYONE'\n\t]).bitfield & Permissions.ALL\n);\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresClientPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.guild!.me!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresClientPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.\n * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}\n * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.\n * @param permissionsResolvable Permissions that the method should have.\n * @example\n * ```typescript\n * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';\n * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<SubCommandPluginCommandOptions>({\n * \taliases: ['cws'],\n * \tdescription: 'A basic command with some subcommands',\n * \tsubCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]\n * })\n * export default class extends SubCommandPluginCommand {\n * // Anyone should be able to view the result, but not modify\n * \tpublic async show(message: Message) {\n * \t\treturn message.channel.send('Showing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async add(message: Message) {\n * \t\treturn message.channel.send('Adding!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async remove(message: Message) {\n * \t\treturn message.channel.send('Removing!');\n * \t}\n *\n * \t(at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.\n * \tpublic async reset(message: Message) {\n * \t\treturn message.channel.send('Resetting!');\n * \t}\n * }\n * ```\n */\nexport const RequiresUserPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {\n\tconst resolved = new Permissions(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);\n\n\treturn createFunctionPrecondition((message: Message) => {\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {\n\t\t\tthrow new UserError({\n\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsGuildOnly,\n\t\t\t\tmessage: 'Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs'\n\t\t\t});\n\t\t}\n\n\t\tif (isGuildBasedChannel(message.channel)) {\n\t\t\tconst missingPermissions = message.channel.permissionsFor(message.member!).missing(resolved);\n\n\t\t\tif (missingPermissions.length) {\n\t\t\t\tthrow new UserError({\n\t\t\t\t\tidentifier: DecoratorIdentifiers.RequiresUserPermissionsMissingPermissions,\n\t\t\t\t\tmessage: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tmissing: missingPermissions\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\n/**\n * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresGuildContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild !== null, fallback);\n}\n\n/**\n * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance\n * @since 1.0.0\n * @param fallback The fallback value passed to `createFunctionInhibitor`\n */\nexport function RequiresDMContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((message: Message) => message.guild === null, fallback);\n}\n","import { container, type Piece } from '@sapphire/framework';\nimport type { Container } from '@sapphire/pieces';\nimport type { Ctor } from '@sapphire/utilities';\nimport { createClassDecorator, createProxy } from './utils';\n\n/**\n * Decorator function that applies given options to any Sapphire piece\n * @param options The options to pass to the piece constructor\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import type { Message } from 'discord.js';\n *\n * @ApplyOptions<Command.Options>({\n * description: 'ping pong',\n * enabled: true\n * })\n * export class UserCommand extends Command {\n * public override async messageRun(message: Message) {\n * const msg = await message.channel.send('Ping?');\n *\n * return msg.edit(\n * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`\n * );\n * }\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions } from '@sapphire/decorators';\n * import { Listener } from '@sapphire/framework';\n * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';\n *\n * @ApplyOptions<Listener.Options>(({ container }) => ({\n * description: 'Handle Raw Message Delete events',\n * emitter: container.client.ws,\n * event: GatewayDispatchEvents.MessageDelete\n * }))\n * export class UserListener extends Listener {\n * public override run(data: GatewayMessageDeleteDispatch['d']): void {\n * if (!data.guild_id) return;\n *\n * const guild = this.container.client.guilds.cache.get(data.guild_id);\n * if (!guild || !guild.channels.cache.has(data.channel_id)) return;\n *\n * // Do something with the data\n * }\n * }\n * ```\n */\nexport function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator {\n\treturn createClassDecorator((target: Ctor<ConstructorParameters<typeof Piece>, Piece>) =>\n\t\tcreateProxy(target, {\n\t\t\tconstruct: (ctor, [context, baseOptions = {}]: [Piece.Context, Piece.Options]) =>\n\t\t\t\tnew ctor(context, {\n\t\t\t\t\t...baseOptions,\n\t\t\t\t\t...(typeof optionsOrFn === 'function' ? optionsOrFn({ container, context }) : optionsOrFn)\n\t\t\t\t})\n\t\t})\n\t);\n}\n\nexport interface ApplyOptionsCallbackParameters {\n\tcontainer: Container;\n\tcontext: Piece.Context;\n}\n"],"mappings":";;;;AAiCO,SAAS,sBAAsB,IAAsC;AAC3E,SAAO;AACR;AAFgB;AAST,SAAS,qBAAiE,IAA+B;AAC/G,SAAO;AACR;AAFgB;AA8BT,SAAS,2BAA2B,cAAoC,WAA6B,MAAY,QAA4B;AACnJ,SAAO,sBAAsB,CAAC,SAAS,cAAc,eAAe;AACnE,UAAM,SAAS,WAAW;AAC1B,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM,6CAA6C;AAC1E,QAAI,OAAO,WAAW;AAAY,YAAM,IAAI,MAAM,0DAA0D;AAE5G,eAAW,QAAQ,sCAAe,mBAAkD,MAAa;AAChG,YAAM,SAAS,MAAM,aAAa,GAAG,IAAI;AACzC,aAAO,SAAS,OAAO,KAAK,MAAM,GAAG,IAAI,IAAI,SAAS,KAAK,MAAM,GAAG,IAAI;AAAA,IACzE,GAHmB;AAAA,EAIpB,CAAC;AACF;AAXgB;AAoBT,SAAS,YAA8B,QAAW,SAA0C;AAClG,SAAO,IAAI,MAAM,QAAQ;AAAA,IACxB,GAAG;AAAA,IACH,KAAK,CAACA,SAAQ,aAAa;AAC1B,YAAM,QAAQ,QA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ACR,CAAC;AACF,GA5BuC;AAmChC,SAAS,qBAAqB,WAA6B,MAAY,QAA4B;AACzG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;AAST,SAAS,kBAAkB,WAA6B,MAAY,QAA4B;AACtG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM,QAAQ;AACzF;AAFgB;;;AC/LhB,SAAS,iBAA6B;AAmD/B,SAAS,aAAsC,aAAsF;AAC3I,SAAO;AAAA,IAAqB,CAAC,WAC5B,YAAY,QAAQ;AAAA,MACnB,WAAW,CAAC,MAAM,CAAC,SAAS,cAAc,CAAC,CAAC,MAC3C,IAAI,KAAK,SAAS;AAAA,QACjB,GAAG;AAAA,QACH,GAAI,OAAO,gBAAgB,aAAa,YAAY,EAAE,WAAW,QAAQ,CAAC,IAAI;AAAA,MAC/E,CAAC;AAAA,IACH,CAAC;AAAA,EACF;AACD;AAVgB;","names":["target","DecoratorIdentifiers"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/decorators",
3
- "version": "4.3.9-next.f731c3c.0",
3
+ "version": "5.0.0",
4
4
  "description": "Useful TypeScript decorators for Sapphire Framework Discord bots",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "test": "vitest run",
18
18
  "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
19
- "build": "tsup && tsc -b src",
19
+ "build": "tsup",
20
20
  "prepack": "yarn build",
21
21
  "bump": "cliff-jumper",
22
22
  "check-update": "cliff-jumper --dry-run"
@@ -25,14 +25,16 @@
25
25
  "tslib": "^2.4.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@favware/cliff-jumper": "^1.8.5",
29
- "@sapphire/discord-utilities": "^2.11.4",
30
- "@sapphire/discord.js-utilities": "^4.11.3",
28
+ "@favware/cliff-jumper": "^1.8.7",
29
+ "@sapphire/discord-utilities": "^2.11.6",
30
+ "@sapphire/discord.js-utilities": "^5.0.0",
31
31
  "@sapphire/ratelimits": "^2.4.4",
32
- "@sapphire/result": "^2.0.1",
33
- "@sapphire/utilities": "^3.7.0",
34
- "tsup": "^6.1.3",
35
- "typescript": "^4.7.4"
32
+ "@sapphire/result": "^2.4.0",
33
+ "@sapphire/utilities": "^3.9.2",
34
+ "@vitest/coverage-c8": "^0.22.1",
35
+ "tsup": "^6.2.2",
36
+ "typescript": "^4.7.4",
37
+ "vitest": "^0.22.1"
36
38
  },
37
39
  "repository": {
38
40
  "type": "git",
@@ -1,11 +0,0 @@
1
- /**
2
- * Decorator that sets the enumerable property of a class field to the desired value.
3
- * @param value Whether the property should be enumerable or not
4
- */
5
- export declare function Enumerable(value: boolean): (target: unknown, key: string) => void;
6
- /**
7
- * Decorator that sets the enumerable property of a class method to the desired value.
8
- * @param value Whether the method should be enumerable or not
9
- */
10
- export declare function EnumerableMethod(value: boolean): MethodDecorator;
11
- //# sourceMappingURL=base-decorators.d.ts.map
@@ -1,101 +0,0 @@
1
- import { PermissionResolvable } from 'discord.js';
2
- import { FunctionFallback } from './utils';
3
- export declare enum DecoratorIdentifiers {
4
- RequiresClientPermissionsGuildOnly = "requiresClientPermissionsGuildOnly",
5
- RequiresClientPermissionsMissingPermissions = "requiresClientPermissionsMissingPermissions",
6
- RequiresUserPermissionsGuildOnly = "requiresUserPermissionsGuildOnly",
7
- RequiresUserPermissionsMissingPermissions = "requiresUserPermissionsMissingPermissions"
8
- }
9
- /**
10
- * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
11
- * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}
12
- * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
13
- * @param permissionsResolvable Permissions that the method should have.
14
- * @example
15
- * ```typescript
16
- * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';
17
- * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
18
- * import type { Message } from 'discord.js';
19
- *
20
- * (at)ApplyOptions<SubCommandPluginCommandOptions>({
21
- * aliases: ['cws'],
22
- * description: 'A basic command with some subcommands',
23
- * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
24
- * })
25
- * export default class extends SubCommandPluginCommand {
26
- * // Anyone should be able to view the result, but not modify
27
- * public async show(message: Message) {
28
- * return message.channel.send('Showing!');
29
- * }
30
- *
31
- * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
32
- * public async add(message: Message) {
33
- * return message.channel.send('Adding!');
34
- * }
35
- *
36
- * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
37
- * public async remove(message: Message) {
38
- * return message.channel.send('Removing!');
39
- * }
40
- *
41
- * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
42
- * public async reset(message: Message) {
43
- * return message.channel.send('Resetting!');
44
- * }
45
- * }
46
- * ```
47
- */
48
- export declare const RequiresClientPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
49
- /**
50
- * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
51
- * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}
52
- * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
53
- * @param permissionsResolvable Permissions that the method should have.
54
- * @example
55
- * ```typescript
56
- * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';
57
- * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
58
- * import type { Message } from 'discord.js';
59
- *
60
- * (at)ApplyOptions<SubCommandPluginCommandOptions>({
61
- * aliases: ['cws'],
62
- * description: 'A basic command with some subcommands',
63
- * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
64
- * })
65
- * export default class extends SubCommandPluginCommand {
66
- * // Anyone should be able to view the result, but not modify
67
- * public async show(message: Message) {
68
- * return message.channel.send('Showing!');
69
- * }
70
- *
71
- * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
72
- * public async add(message: Message) {
73
- * return message.channel.send('Adding!');
74
- * }
75
- *
76
- * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
77
- * public async remove(message: Message) {
78
- * return message.channel.send('Removing!');
79
- * }
80
- *
81
- * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
82
- * public async reset(message: Message) {
83
- * return message.channel.send('Resetting!');
84
- * }
85
- * }
86
- * ```
87
- */
88
- export declare const RequiresUserPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
89
- /**
90
- * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance
91
- * @since 1.0.0
92
- * @param fallback The fallback value passed to `createFunctionInhibitor`
93
- */
94
- export declare function RequiresGuildContext(fallback?: FunctionFallback): MethodDecorator;
95
- /**
96
- * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance
97
- * @since 1.0.0
98
- * @param fallback The fallback value passed to `createFunctionInhibitor`
99
- */
100
- export declare function RequiresDMContext(fallback?: FunctionFallback): MethodDecorator;
101
- //# sourceMappingURL=djs-decorators.d.ts.map
@@ -1,54 +0,0 @@
1
- import { type Piece } from '@sapphire/framework';
2
- import type { Container } from '@sapphire/pieces';
3
- /**
4
- * Decorator function that applies given options to any Sapphire piece
5
- * @param options The options to pass to the piece constructor
6
- * @example
7
- * ```typescript
8
- * import { ApplyOptions } from '@sapphire/decorators';
9
- * import { Command } from '@sapphire/framework';
10
- * import type { Message } from 'discord.js';
11
- *
12
- * @ApplyOptions<Command.Options>({
13
- * description: 'ping pong',
14
- * enabled: true
15
- * })
16
- * export class UserCommand extends Command {
17
- * public override async messageRun(message: Message) {
18
- * const msg = await message.channel.send('Ping?');
19
- *
20
- * return msg.edit(
21
- * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`
22
- * );
23
- * }
24
- * }
25
- * ```
26
- * @example
27
- * ```typescript
28
- * import { ApplyOptions } from '@sapphire/decorators';
29
- * import { Listener } from '@sapphire/framework';
30
- * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';
31
- *
32
- * @ApplyOptions<Listener.Options>(({ container }) => ({
33
- * description: 'Handle Raw Message Delete events',
34
- * emitter: container.client.ws,
35
- * event: GatewayDispatchEvents.MessageDelete
36
- * }))
37
- * export class UserListener extends Listener {
38
- * public override run(data: GatewayMessageDeleteDispatch['d']): void {
39
- * if (!data.guild_id) return;
40
- *
41
- * const guild = this.container.client.guilds.cache.get(data.guild_id);
42
- * if (!guild || !guild.channels.cache.has(data.channel_id)) return;
43
- *
44
- * // Do something with the data
45
- * }
46
- * }
47
- * ```
48
- */
49
- export declare function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator;
50
- export interface ApplyOptionsCallbackParameters {
51
- container: Container;
52
- context: Piece.Context;
53
- }
54
- //# sourceMappingURL=piece-decorators.d.ts.map
package/dist/utils.d.ts DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * The function precondition interface.
3
- */
4
- export interface FunctionPrecondition {
5
- /**
6
- * The arguments passed to the function or class' method.
7
- */
8
- (...args: any[]): boolean | Promise<boolean>;
9
- }
10
- /**
11
- * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.
12
- */
13
- export interface FunctionFallback {
14
- /**
15
- * The arguments passed to the function or class' method.
16
- */
17
- (...args: any[]): unknown;
18
- }
19
- /**
20
- * Utility to make a method decorator with lighter syntax and inferred types.
21
- *
22
- * ```typescript
23
- * // Enumerable function
24
- * function enumerableMethod(value: boolean) {
25
- * return createMethodDecorator((_target, _propertyKey, descriptor) => {
26
- * descriptor.enumerable = value;
27
- * });
28
- * }
29
- * ```
30
- * @param fn The method to decorate
31
- */
32
- export declare function createMethodDecorator(fn: MethodDecorator): MethodDecorator;
33
- /**
34
- * Utility to make a class decorator with lighter syntax and inferred types.
35
- * @param fn The class to decorate
36
- * @see {@link ApplyOptions}
37
- */
38
- export declare function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator;
39
- /**
40
- * Utility to make function preconditions.
41
- *
42
- * ```typescript
43
- * // No fallback (returns undefined)
44
- * function requireGuild(value: number) {
45
- * return createFunctionPrecondition((message: Message) =>
46
- * message.guild !== null
47
- * );
48
- * }
49
- *
50
- * // With fallback
51
- * function requireGuild(
52
- * value: number,
53
- * fallback: () => unknown = () => undefined
54
- * ) {
55
- * return createFunctionPrecondition(
56
- * (message: Message) => message.guild !== null,
57
- * fallback
58
- * );
59
- * }
60
- * ```
61
- * @since 1.0.0
62
- * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback
63
- * @param fallback The fallback value that defines what the method should return in case the precondition fails
64
- */
65
- export declare function createFunctionPrecondition(precondition: FunctionPrecondition, fallback?: FunctionFallback): MethodDecorator;
66
- /**
67
- * Creates a new proxy to efficiently add properties to class without creating subclasses
68
- * @param target The constructor of the class to modify
69
- * @param handler The handler function to modify the constructor behavior for the target
70
- * @hidden
71
- */
72
- export declare function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T;
73
- //# sourceMappingURL=utils.d.ts.map