@sapphire/decorators 4.0.2 → 4.1.0-next.365a53a.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/README.md +4 -0
- package/dist/index.js +216 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -15
- package/dist/index.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/base-decorators.js +0 -35
- package/dist/base-decorators.js.map +0 -1
- package/dist/djs-decorators.js +0 -184
- package/dist/djs-decorators.js.map +0 -1
- package/dist/piece-decorators.js +0 -61
- package/dist/piece-decorators.js.map +0 -1
- package/dist/utils.js +0 -87
- package/dist/utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -86,6 +86,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
86
86
|
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">💻</a></td>
|
|
87
87
|
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">🚧</a></td>
|
|
88
88
|
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
|
|
89
|
+
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">💻</a></td>
|
|
90
|
+
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jérémy de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">💻</a></td>
|
|
91
|
+
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">💻</a></td>
|
|
92
|
+
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">💻</a></td>
|
|
89
93
|
</tr>
|
|
90
94
|
</table>
|
|
91
95
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,218 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
(
|
|
7
|
-
(
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
21
|
+
return (module2, temp) => {
|
|
22
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
23
|
+
};
|
|
24
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
ApplyOptions: () => ApplyOptions,
|
|
30
|
+
DecoratorIdentifiers: () => DecoratorIdentifiers,
|
|
31
|
+
Enumerable: () => Enumerable,
|
|
32
|
+
EnumerableMethod: () => EnumerableMethod,
|
|
33
|
+
RequiresClientPermissions: () => RequiresClientPermissions,
|
|
34
|
+
RequiresDMContext: () => RequiresDMContext,
|
|
35
|
+
RequiresGuildContext: () => RequiresGuildContext,
|
|
36
|
+
RequiresUserPermissions: () => RequiresUserPermissions,
|
|
37
|
+
createClassDecorator: () => createClassDecorator,
|
|
38
|
+
createFunctionPrecondition: () => createFunctionPrecondition,
|
|
39
|
+
createMethodDecorator: () => createMethodDecorator,
|
|
40
|
+
createProxy: () => createProxy
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// src/utils.ts
|
|
44
|
+
function createMethodDecorator(fn) {
|
|
45
|
+
return fn;
|
|
46
|
+
}
|
|
47
|
+
__name(createMethodDecorator, "createMethodDecorator");
|
|
48
|
+
function createClassDecorator(fn) {
|
|
49
|
+
return fn;
|
|
50
|
+
}
|
|
51
|
+
__name(createClassDecorator, "createClassDecorator");
|
|
52
|
+
function createFunctionPrecondition(precondition, fallback = () => void 0) {
|
|
53
|
+
return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
54
|
+
const method = descriptor.value;
|
|
55
|
+
if (!method)
|
|
56
|
+
throw new Error("Function preconditions require a [[value]].");
|
|
57
|
+
if (typeof method !== "function")
|
|
58
|
+
throw new Error("Function preconditions can only be applied to functions.");
|
|
59
|
+
descriptor.value = /* @__PURE__ */ __name(async function descriptorValue(...args) {
|
|
60
|
+
const canRun = await precondition(...args);
|
|
61
|
+
return canRun ? method.call(this, ...args) : fallback.call(this, ...args);
|
|
62
|
+
}, "descriptorValue");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
__name(createFunctionPrecondition, "createFunctionPrecondition");
|
|
66
|
+
function createProxy(target, handler) {
|
|
67
|
+
return new Proxy(target, {
|
|
68
|
+
...handler,
|
|
69
|
+
get: (target2, property) => {
|
|
70
|
+
const value = Reflect.get(target2, property);
|
|
71
|
+
return typeof value === "function" ? (...args) => value.apply(target2, args) : value;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
__name(createProxy, "createProxy");
|
|
76
|
+
|
|
77
|
+
// src/base-decorators.ts
|
|
78
|
+
function Enumerable(value) {
|
|
79
|
+
return (target, key) => {
|
|
80
|
+
Reflect.defineProperty(target, key, {
|
|
81
|
+
enumerable: value,
|
|
82
|
+
set(val) {
|
|
83
|
+
Reflect.defineProperty(this, key, {
|
|
84
|
+
configurable: true,
|
|
85
|
+
enumerable: value,
|
|
86
|
+
value: val,
|
|
87
|
+
writable: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
__name(Enumerable, "Enumerable");
|
|
94
|
+
function EnumerableMethod(value) {
|
|
95
|
+
return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
96
|
+
descriptor.enumerable = value;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
__name(EnumerableMethod, "EnumerableMethod");
|
|
100
|
+
|
|
101
|
+
// src/djs-decorators.ts
|
|
102
|
+
var import_discord = require("@sapphire/discord.js-utilities");
|
|
103
|
+
var import_framework = require("@sapphire/framework");
|
|
104
|
+
var import_discord2 = require("discord.js");
|
|
105
|
+
var DecoratorIdentifiers = /* @__PURE__ */ ((DecoratorIdentifiers2) => {
|
|
106
|
+
DecoratorIdentifiers2["RequiresClientPermissionsGuildOnly"] = "requiresClientPermissionsGuildOnly";
|
|
107
|
+
DecoratorIdentifiers2["RequiresClientPermissionsMissingPermissions"] = "requiresClientPermissionsMissingPermissions";
|
|
108
|
+
DecoratorIdentifiers2["RequiresUserPermissionsGuildOnly"] = "requiresUserPermissionsGuildOnly";
|
|
109
|
+
DecoratorIdentifiers2["RequiresUserPermissionsMissingPermissions"] = "requiresUserPermissionsMissingPermissions";
|
|
110
|
+
return DecoratorIdentifiers2;
|
|
111
|
+
})(DecoratorIdentifiers || {});
|
|
112
|
+
var DMAvailablePermissions = new import_discord2.Permissions(~new import_discord2.Permissions([
|
|
113
|
+
"ADD_REACTIONS",
|
|
114
|
+
"ATTACH_FILES",
|
|
115
|
+
"EMBED_LINKS",
|
|
116
|
+
"READ_MESSAGE_HISTORY",
|
|
117
|
+
"SEND_MESSAGES",
|
|
118
|
+
"USE_EXTERNAL_EMOJIS",
|
|
119
|
+
"VIEW_CHANNEL"
|
|
120
|
+
]).bitfield & import_discord2.Permissions.ALL);
|
|
121
|
+
var DMAvailableUserPermissions = new import_discord2.Permissions(~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
|
+
var RequiresClientPermissions = /* @__PURE__ */ __name((...permissionsResolvable) => {
|
|
133
|
+
const resolved = new import_discord2.Permissions(permissionsResolvable);
|
|
134
|
+
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);
|
|
135
|
+
return createFunctionPrecondition((message) => {
|
|
136
|
+
if (resolvedIncludesServerPermissions && (0, import_discord.isDMChannel)(message.channel)) {
|
|
137
|
+
throw new import_framework.UserError({
|
|
138
|
+
identifier: "requiresClientPermissionsGuildOnly" /* RequiresClientPermissionsGuildOnly */,
|
|
139
|
+
message: "Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if ((0, import_discord.isGuildBasedChannel)(message.channel)) {
|
|
143
|
+
const missingPermissions = message.channel.permissionsFor(message.guild.me).missing(resolved);
|
|
144
|
+
if (missingPermissions.length) {
|
|
145
|
+
throw new import_framework.UserError({
|
|
146
|
+
identifier: "requiresClientPermissionsMissingPermissions" /* RequiresClientPermissionsMissingPermissions */,
|
|
147
|
+
message: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,
|
|
148
|
+
context: {
|
|
149
|
+
missing: missingPermissions
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
});
|
|
156
|
+
}, "RequiresClientPermissions");
|
|
157
|
+
var RequiresUserPermissions = /* @__PURE__ */ __name((...permissionsResolvable) => {
|
|
158
|
+
const resolved = new import_discord2.Permissions(permissionsResolvable);
|
|
159
|
+
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);
|
|
160
|
+
return createFunctionPrecondition((message) => {
|
|
161
|
+
if (resolvedIncludesServerPermissions && (0, import_discord.isDMChannel)(message.channel)) {
|
|
162
|
+
throw new import_framework.UserError({
|
|
163
|
+
identifier: "requiresUserPermissionsGuildOnly" /* RequiresUserPermissionsGuildOnly */,
|
|
164
|
+
message: "Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if ((0, import_discord.isGuildBasedChannel)(message.channel)) {
|
|
168
|
+
const missingPermissions = message.channel.permissionsFor(message.member).missing(resolved);
|
|
169
|
+
if (missingPermissions.length) {
|
|
170
|
+
throw new import_framework.UserError({
|
|
171
|
+
identifier: "requiresUserPermissionsMissingPermissions" /* RequiresUserPermissionsMissingPermissions */,
|
|
172
|
+
message: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,
|
|
173
|
+
context: {
|
|
174
|
+
missing: missingPermissions
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
});
|
|
181
|
+
}, "RequiresUserPermissions");
|
|
182
|
+
function RequiresGuildContext(fallback = () => void 0) {
|
|
183
|
+
return createFunctionPrecondition((message) => message.guild !== null, fallback);
|
|
184
|
+
}
|
|
185
|
+
__name(RequiresGuildContext, "RequiresGuildContext");
|
|
186
|
+
function RequiresDMContext(fallback = () => void 0) {
|
|
187
|
+
return createFunctionPrecondition((message) => message.guild === null, fallback);
|
|
188
|
+
}
|
|
189
|
+
__name(RequiresDMContext, "RequiresDMContext");
|
|
190
|
+
|
|
191
|
+
// src/piece-decorators.ts
|
|
192
|
+
var import_framework2 = require("@sapphire/framework");
|
|
193
|
+
function ApplyOptions(optionsOrFn) {
|
|
194
|
+
return createClassDecorator((target) => createProxy(target, {
|
|
195
|
+
construct: (ctor, [context, baseOptions = {}]) => new ctor(context, {
|
|
196
|
+
...baseOptions,
|
|
197
|
+
...typeof optionsOrFn === "function" ? optionsOrFn({ container: import_framework2.container, context }) : optionsOrFn
|
|
198
|
+
})
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
__name(ApplyOptions, "ApplyOptions");
|
|
202
|
+
module.exports = __toCommonJS(src_exports);
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
ApplyOptions,
|
|
206
|
+
DecoratorIdentifiers,
|
|
207
|
+
Enumerable,
|
|
208
|
+
EnumerableMethod,
|
|
209
|
+
RequiresClientPermissions,
|
|
210
|
+
RequiresDMContext,
|
|
211
|
+
RequiresGuildContext,
|
|
212
|
+
RequiresUserPermissions,
|
|
213
|
+
createClassDecorator,
|
|
214
|
+
createFunctionPrecondition,
|
|
215
|
+
createMethodDecorator,
|
|
216
|
+
createProxy
|
|
217
|
+
});
|
|
8
218
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iEAAkC;AAClC,gEAAiC;AACjC,kEAAmC;AACnC,uDAAwB"}
|
|
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 const 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;;;ACiCO,+BAA+B,IAAsC;AAC3E,SAAO;AAAA;AADQ;AAST,8BAA0E,IAA+B;AAC/G,SAAO;AAAA;AADQ;AA8BT,oCAAoC,cAAoC,WAA6B,MAAY,QAA4B;AACnJ,SAAO,sBAAsB,CAAC,SAAS,cAAc,eAAe;AACnE,UAAM,SAAS,WAAW;AAC1B,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM;AAC7B,QAAI,OAAO,WAAW;AAAY,YAAM,IAAI,MAAM;AAElD,eAAW,QAAQ,yDAAiE,MAAa;AAChG,YAAM,SAAS,MAAM,aAAa,GAAG;AACrC,aAAO,SAAS,OAAO,KAAK,MAAM,GAAG,QAAQ,SAAS,KAAK,MAAM,GAAG;AAAA,OAFlD;AAAA;AAAA;AANL;AAoBT,qBAAuC,QAAW,SAA0C;AAClG,SAAO,IAAI,MAAM,QAAQ;AAAA,OACrB;AAAA,IACH,KAAK,CAAC,SAAQ,aAAa;AAC1B,YAAM,QAAQ,QAAQ,IAAI,SAAQ;AAClC,aAAO,OAAO,UAAU,aAAa,IAAI,SAA6B,MAAM,MAAM,SAAQ,QAAQ;AAAA;AAAA;AAAA;AALrF;;;ACrFT,oBAAoB,OAAgB;AAC1C,SAAO,CAAC,QAAiB,QAAgB;AACxC,YAAQ,eAAe,QAAyB,KAAK;AAAA,MACpD,YAAY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-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/utils.ts
|
|
5
|
+
function createMethodDecorator(fn) {
|
|
6
|
+
return fn;
|
|
7
|
+
}
|
|
8
|
+
__name(createMethodDecorator, "createMethodDecorator");
|
|
9
|
+
function createClassDecorator(fn) {
|
|
10
|
+
return fn;
|
|
11
|
+
}
|
|
12
|
+
__name(createClassDecorator, "createClassDecorator");
|
|
13
|
+
function createFunctionPrecondition(precondition, fallback = () => void 0) {
|
|
14
|
+
return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
15
|
+
const method = descriptor.value;
|
|
16
|
+
if (!method)
|
|
17
|
+
throw new Error("Function preconditions require a [[value]].");
|
|
18
|
+
if (typeof method !== "function")
|
|
19
|
+
throw new Error("Function preconditions can only be applied to functions.");
|
|
20
|
+
descriptor.value = /* @__PURE__ */ __name(async function descriptorValue(...args) {
|
|
21
|
+
const canRun = await precondition(...args);
|
|
22
|
+
return canRun ? method.call(this, ...args) : fallback.call(this, ...args);
|
|
23
|
+
}, "descriptorValue");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
__name(createFunctionPrecondition, "createFunctionPrecondition");
|
|
27
|
+
function createProxy(target, handler) {
|
|
28
|
+
return new Proxy(target, {
|
|
29
|
+
...handler,
|
|
30
|
+
get: (target2, property) => {
|
|
31
|
+
const value = Reflect.get(target2, property);
|
|
32
|
+
return typeof value === "function" ? (...args) => value.apply(target2, args) : value;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
__name(createProxy, "createProxy");
|
|
37
|
+
|
|
38
|
+
// src/base-decorators.ts
|
|
39
|
+
function Enumerable(value) {
|
|
40
|
+
return (target, key) => {
|
|
41
|
+
Reflect.defineProperty(target, key, {
|
|
42
|
+
enumerable: value,
|
|
43
|
+
set(val) {
|
|
44
|
+
Reflect.defineProperty(this, key, {
|
|
45
|
+
configurable: true,
|
|
46
|
+
enumerable: value,
|
|
47
|
+
value: val,
|
|
48
|
+
writable: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
__name(Enumerable, "Enumerable");
|
|
55
|
+
function EnumerableMethod(value) {
|
|
56
|
+
return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
57
|
+
descriptor.enumerable = value;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
__name(EnumerableMethod, "EnumerableMethod");
|
|
61
|
+
|
|
62
|
+
// src/djs-decorators.ts
|
|
63
|
+
import { isDMChannel, isGuildBasedChannel } from "@sapphire/discord.js-utilities";
|
|
64
|
+
import { UserError } from "@sapphire/framework";
|
|
65
|
+
import { Permissions } from "discord.js";
|
|
66
|
+
var DecoratorIdentifiers = /* @__PURE__ */ ((DecoratorIdentifiers2) => {
|
|
67
|
+
DecoratorIdentifiers2["RequiresClientPermissionsGuildOnly"] = "requiresClientPermissionsGuildOnly";
|
|
68
|
+
DecoratorIdentifiers2["RequiresClientPermissionsMissingPermissions"] = "requiresClientPermissionsMissingPermissions";
|
|
69
|
+
DecoratorIdentifiers2["RequiresUserPermissionsGuildOnly"] = "requiresUserPermissionsGuildOnly";
|
|
70
|
+
DecoratorIdentifiers2["RequiresUserPermissionsMissingPermissions"] = "requiresUserPermissionsMissingPermissions";
|
|
71
|
+
return DecoratorIdentifiers2;
|
|
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);
|
|
93
|
+
var RequiresClientPermissions = /* @__PURE__ */ __name((...permissionsResolvable) => {
|
|
94
|
+
const resolved = new Permissions(permissionsResolvable);
|
|
95
|
+
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);
|
|
96
|
+
return createFunctionPrecondition((message) => {
|
|
97
|
+
if (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {
|
|
98
|
+
throw new UserError({
|
|
99
|
+
identifier: "requiresClientPermissionsGuildOnly" /* RequiresClientPermissionsGuildOnly */,
|
|
100
|
+
message: "Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs"
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (isGuildBasedChannel(message.channel)) {
|
|
104
|
+
const missingPermissions = message.channel.permissionsFor(message.guild.me).missing(resolved);
|
|
105
|
+
if (missingPermissions.length) {
|
|
106
|
+
throw new UserError({
|
|
107
|
+
identifier: "requiresClientPermissionsMissingPermissions" /* RequiresClientPermissionsMissingPermissions */,
|
|
108
|
+
message: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,
|
|
109
|
+
context: {
|
|
110
|
+
missing: missingPermissions
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
});
|
|
117
|
+
}, "RequiresClientPermissions");
|
|
118
|
+
var RequiresUserPermissions = /* @__PURE__ */ __name((...permissionsResolvable) => {
|
|
119
|
+
const resolved = new Permissions(permissionsResolvable);
|
|
120
|
+
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);
|
|
121
|
+
return createFunctionPrecondition((message) => {
|
|
122
|
+
if (resolvedIncludesServerPermissions && isDMChannel(message.channel)) {
|
|
123
|
+
throw new UserError({
|
|
124
|
+
identifier: "requiresUserPermissionsGuildOnly" /* RequiresUserPermissionsGuildOnly */,
|
|
125
|
+
message: "Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (isGuildBasedChannel(message.channel)) {
|
|
129
|
+
const missingPermissions = message.channel.permissionsFor(message.member).missing(resolved);
|
|
130
|
+
if (missingPermissions.length) {
|
|
131
|
+
throw new UserError({
|
|
132
|
+
identifier: "requiresUserPermissionsMissingPermissions" /* RequiresUserPermissionsMissingPermissions */,
|
|
133
|
+
message: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,
|
|
134
|
+
context: {
|
|
135
|
+
missing: missingPermissions
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
});
|
|
142
|
+
}, "RequiresUserPermissions");
|
|
143
|
+
function RequiresGuildContext(fallback = () => void 0) {
|
|
144
|
+
return createFunctionPrecondition((message) => message.guild !== null, fallback);
|
|
145
|
+
}
|
|
146
|
+
__name(RequiresGuildContext, "RequiresGuildContext");
|
|
147
|
+
function RequiresDMContext(fallback = () => void 0) {
|
|
148
|
+
return createFunctionPrecondition((message) => message.guild === null, fallback);
|
|
149
|
+
}
|
|
150
|
+
__name(RequiresDMContext, "RequiresDMContext");
|
|
151
|
+
|
|
152
|
+
// src/piece-decorators.ts
|
|
153
|
+
import { container } from "@sapphire/framework";
|
|
154
|
+
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
|
+
})
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
__name(ApplyOptions, "ApplyOptions");
|
|
163
|
+
export {
|
|
164
|
+
ApplyOptions,
|
|
165
|
+
DecoratorIdentifiers,
|
|
166
|
+
Enumerable,
|
|
167
|
+
EnumerableMethod,
|
|
168
|
+
RequiresClientPermissions,
|
|
169
|
+
RequiresDMContext,
|
|
170
|
+
RequiresGuildContext,
|
|
171
|
+
RequiresUserPermissions,
|
|
172
|
+
createClassDecorator,
|
|
173
|
+
createFunctionPrecondition,
|
|
174
|
+
createMethodDecorator,
|
|
175
|
+
createProxy
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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 const 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;AAAA;AADQ;AAST,8BAA0E,IAA+B;AAC/G,SAAO;AAAA;AADQ;AA8BT,oCAAoC,cAAoC,WAA6B,MAAY,QAA4B;AACnJ,SAAO,sBAAsB,CAAC,SAAS,cAAc,eAAe;AACnE,UAAM,SAAS,WAAW;AAC1B,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM;AAC7B,QAAI,OAAO,WAAW;AAAY,YAAM,IAAI,MAAM;AAElD,eAAW,QAAQ,yDAAiE,MAAa;AAChG,YAAM,SAAS,MAAM,aAAa,GAAG;AACrC,aAAO,SAAS,OAAO,KAAK,MAAM,GAAG,QAAQ,SAAS,KAAK,MAAM,GAAG;AAAA,OAFlD;AAAA;AAAA;AANL;AAoBT,qBAAuC,QAAW,SAA0C;AAClG,SAAO,IAAI,MAAM,QAAQ;AAAA,OACrB;AAAA,IACH,KAAK,CAAC,SAAQ,aAAa;AAC1B,YAAM,QAAQ,QAAQ,IAAI,SAAQ;AAClC,aAAO,OAAO,UAAU,aAAa,IAAI,SAA6B,MAAM,MAAM,SAAQ,QAAQ;AAAA;AAAA;AAAA;AALrF;;;ACrFT,oBAAoB,OAAgB;AAC1C,SAAO,CAAC,QAAiB,QAAgB;AACxC,YAAQ,eAAe,QAAyB,KAAK;AAAA,MACpD,YAAY;AAAA,MACZ,IAAmB,KAAc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AAA;AAAA,GA1BgC;AAqElC,IAAM,0BAA0B,2BAAI,0BAAmE;AAC7G,QAAM,WAAW,IAAI,YAAY;AACjC,QAAM,oCAAoC,QAAQ,SAAS,WAAW,2BAA2B;AAEjG,SAAO,2BAA2B,CAAC,YAAqB;AACvD,QAAI,qCAAqC,YAAY,QAAQ,UAAU;AACtE,YAAM,IAAI,UAAU;AAAA,QACnB,YAAY;AAAA,QACZ,SAAS;AAAA;AAAA;AAIX,QAAI,oBAAoB,QAAQ,UAAU;AACzC,YAAM,qBAAqB,QAAQ,QAAQ,eAAe,QAAQ,QAAS,QAAQ;AAEnF,UAAI,mBAAmB,QAAQ;AAC9B,cAAM,IAAI,UAAU;AAAA,UACnB,YAAY;AAAA,UACZ,SAAS,+EAA+E;AAAA,UACxF,SAAS;AAAA,YACR,SAAS;AAAA;AAAA;AAAA;AAAA;AAMb,WAAO;AAAA;AAAA,GA1B8B;AAmChC,8BAA8B,WAA6B,MAAY,QAA4B;AACzG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM;AAAA;AADjE;AAST,2BAA2B,WAA6B,MAAY,QAA4B;AACtG,SAAO,2BAA2B,CAAC,YAAqB,QAAQ,UAAU,MAAM;AAAA;AADjE;;;AC/LhB;AAmDO,sBAA+C,aAAsF;AAC3I,SAAO,qBAAqB,CAAC,WAC5B,YAAY,QAAQ;AAAA,IACnB,WAAW,CAAC,MAAM,CAAC,SAAS,cAAc,QACzC,IAAI,KAAK,SAAS;AAAA,SACd;AAAA,SACC,OAAO,gBAAgB,aAAa,YAAY,EAAE,WAAW,aAAa;AAAA;AAAA;AAAA;AANnE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/decorators",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.1.0-next.365a53a.0",
|
|
4
4
|
"description": "Useful TypeScript decorators for Sapphire Framework Discord bots",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "jest",
|
|
18
18
|
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
|
19
|
-
"build": "tsc -b src
|
|
19
|
+
"build": "tsup && tsc -b src",
|
|
20
20
|
"prepublishOnly": "yarn build"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"tslib": "^2.3.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@sapphire/discord-utilities": "^2.
|
|
27
|
-
"@sapphire/discord.js-utilities": "^4.
|
|
28
|
-
"@sapphire/ratelimits": "^2.
|
|
29
|
-
"@sapphire/utilities": "^3.
|
|
26
|
+
"@sapphire/discord-utilities": "^2.7.0-next.365a53a.0",
|
|
27
|
+
"@sapphire/discord.js-utilities": "^4.5.0-next.365a53a.0",
|
|
28
|
+
"@sapphire/ratelimits": "^2.2.0-next.365a53a.0",
|
|
29
|
+
"@sapphire/utilities": "^3.3.0-next.365a53a.0"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "365a53a5517a01a0926cf28a83c96b63f32ed9f8"
|
|
61
61
|
}
|
package/dist/base-decorators.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnumerableMethod = exports.Enumerable = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
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
|
-
function Enumerable(value) {
|
|
10
|
-
return (target, key) => {
|
|
11
|
-
Reflect.defineProperty(target, key, {
|
|
12
|
-
enumerable: value,
|
|
13
|
-
set(val) {
|
|
14
|
-
Reflect.defineProperty(this, key, {
|
|
15
|
-
configurable: true,
|
|
16
|
-
enumerable: value,
|
|
17
|
-
value: val,
|
|
18
|
-
writable: true
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
exports.Enumerable = Enumerable;
|
|
25
|
-
/**
|
|
26
|
-
* Decorator that sets the enumerable property of a class method to the desired value.
|
|
27
|
-
* @param value Whether the method should be enumerable or not
|
|
28
|
-
*/
|
|
29
|
-
function EnumerableMethod(value) {
|
|
30
|
-
return (0, utils_1.createMethodDecorator)((_target, _propertyKey, descriptor) => {
|
|
31
|
-
descriptor.enumerable = value;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.EnumerableMethod = EnumerableMethod;
|
|
35
|
-
//# sourceMappingURL=base-decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-decorators.js","sourceRoot":"","sources":["../src/base-decorators.ts"],"names":[],"mappings":";;;AACA,mCAAgD;AAEhD;;;GAGG;AACH,SAAgB,UAAU,CAAC,KAAc;IACxC,OAAO,CAAC,MAAe,EAAE,GAAW,EAAE,EAAE;QACvC,OAAO,CAAC,cAAc,CAAC,MAAuB,EAAE,GAAG,EAAE;YACpD,UAAU,EAAE,KAAK;YACjB,GAAG,CAAgB,GAAY;gBAC9B,OAAO,CAAC,cAAc,CAAC,IAAqB,EAAE,GAAG,EAAE;oBAClD,YAAY,EAAE,IAAI;oBAClB,UAAU,EAAE,KAAK;oBACjB,KAAK,EAAE,GAAG;oBACV,QAAQ,EAAE,IAAI;iBACd,CAAC,CAAC;YACJ,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAdD,gCAcC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,KAAc;IAC9C,OAAO,IAAA,6BAAqB,EAAC,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE;QAClE,UAAU,CAAC,UAAU,GAAG,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;AACJ,CAAC;AAJD,4CAIC"}
|
package/dist/djs-decorators.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequiresDMContext = exports.RequiresGuildContext = exports.RequiresUserPermissions = exports.RequiresClientPermissions = exports.DecoratorIdentifiers = void 0;
|
|
4
|
-
const discord_js_utilities_1 = require("@sapphire/discord.js-utilities");
|
|
5
|
-
const framework_1 = require("@sapphire/framework");
|
|
6
|
-
const discord_js_1 = require("discord.js");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
var DecoratorIdentifiers;
|
|
9
|
-
(function (DecoratorIdentifiers) {
|
|
10
|
-
DecoratorIdentifiers["RequiresClientPermissionsGuildOnly"] = "requiresClientPermissionsGuildOnly";
|
|
11
|
-
DecoratorIdentifiers["RequiresClientPermissionsMissingPermissions"] = "requiresClientPermissionsMissingPermissions";
|
|
12
|
-
DecoratorIdentifiers["RequiresUserPermissionsGuildOnly"] = "requiresUserPermissionsGuildOnly";
|
|
13
|
-
DecoratorIdentifiers["RequiresUserPermissionsMissingPermissions"] = "requiresUserPermissionsMissingPermissions";
|
|
14
|
-
})(DecoratorIdentifiers = exports.DecoratorIdentifiers || (exports.DecoratorIdentifiers = {}));
|
|
15
|
-
const DMAvailablePermissions = new discord_js_1.Permissions(~new discord_js_1.Permissions([
|
|
16
|
-
//
|
|
17
|
-
'ADD_REACTIONS',
|
|
18
|
-
'ATTACH_FILES',
|
|
19
|
-
'EMBED_LINKS',
|
|
20
|
-
'READ_MESSAGE_HISTORY',
|
|
21
|
-
'SEND_MESSAGES',
|
|
22
|
-
'USE_EXTERNAL_EMOJIS',
|
|
23
|
-
'VIEW_CHANNEL'
|
|
24
|
-
]).bitfield & discord_js_1.Permissions.ALL);
|
|
25
|
-
const DMAvailableUserPermissions = new discord_js_1.Permissions(~new discord_js_1.Permissions([
|
|
26
|
-
'ADD_REACTIONS',
|
|
27
|
-
'ATTACH_FILES',
|
|
28
|
-
'EMBED_LINKS',
|
|
29
|
-
'READ_MESSAGE_HISTORY',
|
|
30
|
-
'SEND_MESSAGES',
|
|
31
|
-
'USE_EXTERNAL_EMOJIS',
|
|
32
|
-
'VIEW_CHANNEL',
|
|
33
|
-
'USE_EXTERNAL_STICKERS',
|
|
34
|
-
'MENTION_EVERYONE'
|
|
35
|
-
]).bitfield & discord_js_1.Permissions.ALL);
|
|
36
|
-
/**
|
|
37
|
-
* Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
|
|
38
|
-
* @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}
|
|
39
|
-
* @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
|
|
40
|
-
* @param permissionsResolvable Permissions that the method should have.
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';
|
|
44
|
-
* import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
|
|
45
|
-
* import type { Message } from 'discord.js';
|
|
46
|
-
*
|
|
47
|
-
* (at)ApplyOptions<SubCommandPluginCommandOptions>({
|
|
48
|
-
* aliases: ['cws'],
|
|
49
|
-
* description: 'A basic command with some subcommands',
|
|
50
|
-
* subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
|
|
51
|
-
* })
|
|
52
|
-
* export default class extends SubCommandPluginCommand {
|
|
53
|
-
* // Anyone should be able to view the result, but not modify
|
|
54
|
-
* public async show(message: Message) {
|
|
55
|
-
* return message.channel.send('Showing!');
|
|
56
|
-
* }
|
|
57
|
-
*
|
|
58
|
-
* (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
|
|
59
|
-
* public async add(message: Message) {
|
|
60
|
-
* return message.channel.send('Adding!');
|
|
61
|
-
* }
|
|
62
|
-
*
|
|
63
|
-
* (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
|
|
64
|
-
* public async remove(message: Message) {
|
|
65
|
-
* return message.channel.send('Removing!');
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
|
|
69
|
-
* public async reset(message: Message) {
|
|
70
|
-
* return message.channel.send('Resetting!');
|
|
71
|
-
* }
|
|
72
|
-
* }
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
const RequiresClientPermissions = (...permissionsResolvable) => {
|
|
76
|
-
const resolved = new discord_js_1.Permissions(permissionsResolvable);
|
|
77
|
-
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);
|
|
78
|
-
return (0, utils_1.createFunctionPrecondition)((message) => {
|
|
79
|
-
if (resolvedIncludesServerPermissions && (0, discord_js_utilities_1.isDMChannel)(message.channel)) {
|
|
80
|
-
throw new framework_1.UserError({
|
|
81
|
-
identifier: "requiresClientPermissionsGuildOnly" /* RequiresClientPermissionsGuildOnly */,
|
|
82
|
-
message: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
if ((0, discord_js_utilities_1.isGuildBasedChannel)(message.channel)) {
|
|
86
|
-
const missingPermissions = message.channel.permissionsFor(message.guild.me).missing(resolved);
|
|
87
|
-
if (missingPermissions.length) {
|
|
88
|
-
throw new framework_1.UserError({
|
|
89
|
-
identifier: "requiresClientPermissionsMissingPermissions" /* RequiresClientPermissionsMissingPermissions */,
|
|
90
|
-
message: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,
|
|
91
|
-
context: {
|
|
92
|
-
missing: missingPermissions
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
exports.RequiresClientPermissions = RequiresClientPermissions;
|
|
101
|
-
/**
|
|
102
|
-
* Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
|
|
103
|
-
* @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}
|
|
104
|
-
* @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
|
|
105
|
-
* @param permissionsResolvable Permissions that the method should have.
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';
|
|
109
|
-
* import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
|
|
110
|
-
* import type { Message } from 'discord.js';
|
|
111
|
-
*
|
|
112
|
-
* (at)ApplyOptions<SubCommandPluginCommandOptions>({
|
|
113
|
-
* aliases: ['cws'],
|
|
114
|
-
* description: 'A basic command with some subcommands',
|
|
115
|
-
* subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
|
|
116
|
-
* })
|
|
117
|
-
* export default class extends SubCommandPluginCommand {
|
|
118
|
-
* // Anyone should be able to view the result, but not modify
|
|
119
|
-
* public async show(message: Message) {
|
|
120
|
-
* return message.channel.send('Showing!');
|
|
121
|
-
* }
|
|
122
|
-
*
|
|
123
|
-
* (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
|
|
124
|
-
* public async add(message: Message) {
|
|
125
|
-
* return message.channel.send('Adding!');
|
|
126
|
-
* }
|
|
127
|
-
*
|
|
128
|
-
* (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
|
|
129
|
-
* public async remove(message: Message) {
|
|
130
|
-
* return message.channel.send('Removing!');
|
|
131
|
-
* }
|
|
132
|
-
*
|
|
133
|
-
* (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
|
|
134
|
-
* public async reset(message: Message) {
|
|
135
|
-
* return message.channel.send('Resetting!');
|
|
136
|
-
* }
|
|
137
|
-
* }
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
const RequiresUserPermissions = (...permissionsResolvable) => {
|
|
141
|
-
const resolved = new discord_js_1.Permissions(permissionsResolvable);
|
|
142
|
-
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);
|
|
143
|
-
return (0, utils_1.createFunctionPrecondition)((message) => {
|
|
144
|
-
if (resolvedIncludesServerPermissions && (0, discord_js_utilities_1.isDMChannel)(message.channel)) {
|
|
145
|
-
throw new framework_1.UserError({
|
|
146
|
-
identifier: "requiresUserPermissionsGuildOnly" /* RequiresUserPermissionsGuildOnly */,
|
|
147
|
-
message: 'Sorry, but that command can only be used in a server because you do not have sufficient permissions in DMs'
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
if ((0, discord_js_utilities_1.isGuildBasedChannel)(message.channel)) {
|
|
151
|
-
const missingPermissions = message.channel.permissionsFor(message.member).missing(resolved);
|
|
152
|
-
if (missingPermissions.length) {
|
|
153
|
-
throw new framework_1.UserError({
|
|
154
|
-
identifier: "requiresUserPermissionsMissingPermissions" /* RequiresUserPermissionsMissingPermissions */,
|
|
155
|
-
message: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingPermissions}`,
|
|
156
|
-
context: {
|
|
157
|
-
missing: missingPermissions
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return true;
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
exports.RequiresUserPermissions = RequiresUserPermissions;
|
|
166
|
-
/**
|
|
167
|
-
* Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance
|
|
168
|
-
* @since 1.0.0
|
|
169
|
-
* @param fallback The fallback value passed to `createFunctionInhibitor`
|
|
170
|
-
*/
|
|
171
|
-
function RequiresGuildContext(fallback = () => undefined) {
|
|
172
|
-
return (0, utils_1.createFunctionPrecondition)((message) => message.guild !== null, fallback);
|
|
173
|
-
}
|
|
174
|
-
exports.RequiresGuildContext = RequiresGuildContext;
|
|
175
|
-
/**
|
|
176
|
-
* Requires the message to be run in a dm 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
|
-
function RequiresDMContext(fallback = () => undefined) {
|
|
181
|
-
return (0, utils_1.createFunctionPrecondition)((message) => message.guild === null, fallback);
|
|
182
|
-
}
|
|
183
|
-
exports.RequiresDMContext = RequiresDMContext;
|
|
184
|
-
//# sourceMappingURL=djs-decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"djs-decorators.js","sourceRoot":"","sources":["../src/djs-decorators.ts"],"names":[],"mappings":";;;AAAA,yEAAkF;AAClF,mDAAgD;AAChD,2CAAwE;AACxE,mCAAuE;AAEvE,IAAkB,oBAKjB;AALD,WAAkB,oBAAoB;IACrC,iGAAyE,CAAA;IACzE,mHAA2F,CAAA;IAC3F,6FAAqE,CAAA;IACrE,+GAAuF,CAAA;AACxF,CAAC,EALiB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAKrC;AAED,MAAM,sBAAsB,GAAG,IAAI,wBAAW,CAC7C,CAAC,IAAI,wBAAW,CAAC;IAChB,EAAE;IACF,eAAe;IACf,cAAc;IACd,aAAa;IACb,sBAAsB;IACtB,eAAe;IACf,qBAAqB;IACrB,cAAc;CACd,CAAC,CAAC,QAAQ,GAAG,wBAAW,CAAC,GAAG,CAC7B,CAAC;AAEF,MAAM,0BAA0B,GAAG,IAAI,wBAAW,CACjD,CAAC,IAAI,wBAAW,CAAC;IAChB,eAAe;IACf,cAAc;IACd,aAAa;IACb,sBAAs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CAAC,SAAS;IACnF,OAAO,IAAA,kCAA0B,EAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC3F,CAAC;AAFD,8CAEC"}
|
package/dist/piece-decorators.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplyOptions = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
/**
|
|
7
|
-
* Decorator function that applies given options to any Sapphire piece
|
|
8
|
-
* @param options The options to pass to the piece constructor
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { ApplyOptions } from '@sapphire/decorators';
|
|
12
|
-
* import { Command } from '@sapphire/framework';
|
|
13
|
-
* import type { Message } from 'discord.js';
|
|
14
|
-
*
|
|
15
|
-
* @ApplyOptions<Command.Options>({
|
|
16
|
-
* description: 'ping pong',
|
|
17
|
-
* enabled: true
|
|
18
|
-
* })
|
|
19
|
-
* export class UserCommand extends Command {
|
|
20
|
-
* public override async messageRun(message: Message) {
|
|
21
|
-
* const msg = await message.channel.send('Ping?');
|
|
22
|
-
*
|
|
23
|
-
* return msg.edit(
|
|
24
|
-
* `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`
|
|
25
|
-
* );
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* import { ApplyOptions } from '@sapphire/decorators';
|
|
32
|
-
* import { Listener } from '@sapphire/framework';
|
|
33
|
-
* import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';
|
|
34
|
-
*
|
|
35
|
-
* @ApplyOptions<Listener.Options>(({ container }) => ({
|
|
36
|
-
* description: 'Handle Raw Message Delete events',
|
|
37
|
-
* emitter: container.client.ws,
|
|
38
|
-
* event: GatewayDispatchEvents.MessageDelete
|
|
39
|
-
* }))
|
|
40
|
-
* export class UserListener extends Listener {
|
|
41
|
-
* public override run(data: GatewayMessageDeleteDispatch['d']): void {
|
|
42
|
-
* if (!data.guild_id) return;
|
|
43
|
-
*
|
|
44
|
-
* const guild = this.container.client.guilds.cache.get(data.guild_id);
|
|
45
|
-
* if (!guild || !guild.channels.cache.has(data.channel_id)) return;
|
|
46
|
-
*
|
|
47
|
-
* // Do something with the data
|
|
48
|
-
* }
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
function ApplyOptions(optionsOrFn) {
|
|
53
|
-
return (0, utils_1.createClassDecorator)((target) => (0, utils_1.createProxy)(target, {
|
|
54
|
-
construct: (ctor, [context, baseOptions = {}]) => new ctor(context, {
|
|
55
|
-
...baseOptions,
|
|
56
|
-
...(typeof optionsOrFn === 'function' ? optionsOrFn({ container: framework_1.container, context }) : optionsOrFn)
|
|
57
|
-
})
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
exports.ApplyOptions = ApplyOptions;
|
|
61
|
-
//# sourceMappingURL=piece-decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"piece-decorators.js","sourceRoot":"","sources":["../src/piece-decorators.ts"],"names":[],"mappings":";;;AAAA,mDAA4D;AAG5D,mCAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,SAAgB,YAAY,CAA0B,WAAoE;IACzH,OAAO,IAAA,4BAAoB,EAAC,CAAC,MAAwD,EAAE,EAAE,CACxF,IAAA,mBAAW,EAAC,MAAM,EAAE;QACnB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,EAAE,CAAiC,EAAE,EAAE,CAChF,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,GAAG,WAAW;YACd,GAAG,CAAC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,SAAS,EAAT,qBAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;SAC1F,CAAC;KACH,CAAC,CACF,CAAC;AACH,CAAC;AAVD,oCAUC"}
|
package/dist/utils.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createProxy = exports.createFunctionPrecondition = exports.createClassDecorator = exports.createMethodDecorator = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Utility to make a method decorator with lighter syntax and inferred types.
|
|
6
|
-
*
|
|
7
|
-
* ```typescript
|
|
8
|
-
* // Enumerable function
|
|
9
|
-
* function enumerableMethod(value: boolean) {
|
|
10
|
-
* return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
11
|
-
* descriptor.enumerable = value;
|
|
12
|
-
* });
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
* @param fn The method to decorate
|
|
16
|
-
*/
|
|
17
|
-
function createMethodDecorator(fn) {
|
|
18
|
-
return fn;
|
|
19
|
-
}
|
|
20
|
-
exports.createMethodDecorator = createMethodDecorator;
|
|
21
|
-
/**
|
|
22
|
-
* Utility to make a class decorator with lighter syntax and inferred types.
|
|
23
|
-
* @param fn The class to decorate
|
|
24
|
-
* @see {@link ApplyOptions}
|
|
25
|
-
*/
|
|
26
|
-
function createClassDecorator(fn) {
|
|
27
|
-
return fn;
|
|
28
|
-
}
|
|
29
|
-
exports.createClassDecorator = createClassDecorator;
|
|
30
|
-
/**
|
|
31
|
-
* Utility to make function preconditions.
|
|
32
|
-
*
|
|
33
|
-
* ```typescript
|
|
34
|
-
* // No fallback (returns undefined)
|
|
35
|
-
* function requireGuild(value: number) {
|
|
36
|
-
* return createFunctionPrecondition((message: Message) =>
|
|
37
|
-
* message.guild !== null
|
|
38
|
-
* );
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* // With fallback
|
|
42
|
-
* function requireGuild(
|
|
43
|
-
* value: number,
|
|
44
|
-
* fallback: () => unknown = () => undefined
|
|
45
|
-
* ) {
|
|
46
|
-
* return createFunctionPrecondition(
|
|
47
|
-
* (message: Message) => message.guild !== null,
|
|
48
|
-
* fallback
|
|
49
|
-
* );
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
* @since 1.0.0
|
|
53
|
-
* @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback
|
|
54
|
-
* @param fallback The fallback value that defines what the method should return in case the precondition fails
|
|
55
|
-
*/
|
|
56
|
-
function createFunctionPrecondition(precondition, fallback = () => undefined) {
|
|
57
|
-
return createMethodDecorator((_target, _propertyKey, descriptor) => {
|
|
58
|
-
const method = descriptor.value;
|
|
59
|
-
if (!method)
|
|
60
|
-
throw new Error('Function preconditions require a [[value]].');
|
|
61
|
-
if (typeof method !== 'function')
|
|
62
|
-
throw new Error('Function preconditions can only be applied to functions.');
|
|
63
|
-
descriptor.value = async function descriptorValue(...args) {
|
|
64
|
-
const canRun = await precondition(...args);
|
|
65
|
-
return canRun ? method.call(this, ...args) : fallback.call(this, ...args);
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
exports.createFunctionPrecondition = createFunctionPrecondition;
|
|
70
|
-
/**
|
|
71
|
-
* Creates a new proxy to efficiently add properties to class without creating subclasses
|
|
72
|
-
* @param target The constructor of the class to modify
|
|
73
|
-
* @param handler The handler function to modify the constructor behavior for the target
|
|
74
|
-
* @hidden
|
|
75
|
-
*/
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
77
|
-
function createProxy(target, handler) {
|
|
78
|
-
return new Proxy(target, {
|
|
79
|
-
...handler,
|
|
80
|
-
get: (target, property) => {
|
|
81
|
-
const value = Reflect.get(target, property);
|
|
82
|
-
return typeof value === 'function' ? (...args) => value.apply(target, args) : value;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
exports.createProxy = createProxy;
|
|
87
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAoBA;;;;;;;;;;;;GAYG;AACH,SAAgB,qBAAqB,CAAC,EAAmB;IACxD,OAAO,EAAE,CAAC;AACX,CAAC;AAFD,sDAEC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAA6C,EAAa;IAC7F,OAAO,EAAE,CAAC;AACX,CAAC;AAFD,oDAEC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,0BAA0B,CAAC,YAAkC,EAAE,WAA6B,GAAS,EAAE,CAAC,SAAS;IAChI,OAAO,qBAAqB,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE;QAClE,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;QAChC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAC5E,IAAI,OAAO,MAAM,KAAK,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAE9G,UAAU,CAAC,KAAK,GAAG,KAAK,UAAU,eAAe,CAAgC,GAAG,IAAW;YAC9F,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;YAC3C,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QAC3E,CAAyB,CAAC;IAC3B,CAAC,CAAC,CAAC;AACJ,CAAC;AA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