@sapphire/decorators 7.0.0-pr-589.aa473f9.0 → 7.0.0-pr-935.7da5c8bb
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 +55 -0
- package/README.md +0 -1
- package/dist/{index.js → cjs/index.cjs} +91 -20
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +503 -0
- package/dist/esm/index.d.mts +503 -0
- package/dist/{index.mjs → esm/index.mjs} +89 -21
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +31 -24
- package/dist/index.d.ts +0 -240
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts","../../src/base-decorators.ts","../../src/djs-decorators.ts","../../src/piece-decorators.ts"],"names":["target","DecoratorIdentifiers"],"mappings":";;;;;;;;;AAiCO,SAAS,sBAAsB,EAAA,EAAsC;AAC3E,EAAA,OAAO,EAAA;AACR;AAFgB,MAAA,CAAA,qBAAA,EAAA,uBAAA,CAAA;AAST,SAAS,qBAAiE,EAAA,EAA+B;AAC/G,EAAA,OAAO,EAAA;AACR;AAFgB,MAAA,CAAA,oBAAA,EAAA,sBAAA,CAAA;AA8BT,SAAS,0BAAA,CAA2B,YAAA,EAAoC,QAAA,GAA6B,MAAY,MAAA,EAA4B;AACnJ,EAAA,OAAO,qBAAA,CAAsB,CAAC,OAAA,EAAS,YAAA,EAAc,UAAA,KAAe;AACnE,IAAA,MAAM,SAAS,UAAA,CAAW,KAAA;AAC1B,IAAA,IAAI,CAAC,MAAA,EAAQ,MAAM,IAAI,MAAM,6CAA6C,CAAA;AAC1E,IAAA,IAAI,OAAO,MAAA,KAAW,UAAA,EAAY,MAAM,IAAI,MAAM,0DAA0D,CAAA;AAE5G,IAAA,UAAA,CAAW,KAAA,mBAAQ,MAAA,CAAA,eAAe,eAAA,CAAA,GAAkD,IAAA,EAAa;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AA,CAAS,wBAAA,CAAyB,CAAC,OAAA,KAAY,IAAA,CAAK,UAAU,OAAA,EAAS,OAAO,CAAA,EAAG,IAAA,CAAK,eAAe,CAAA;AACrG,cAAA;AAAA,YACD;AAAA,YAEA,KAAK,mCAAA,EAAqC;AACzC,cAAA,QAAA,CAAS,0BAAA;AAAA,gBACR,CAAC,YAAY,IAAA,CAAK,SAAA,CAAU,SAAS,OAAO,CAAA,CAAE,OAAA,CAAQ,sBAAA,CAAuB,OAAO,CAAA;AAAA,gBACpF,IAAA,CAAK;AAAA,eACN;AACA,cAAA;AAAA,YACD;AAAA,YAEA,KAAK,gCAAA,EAAkC;AACtC,cAAA,QAAA,CAAS,0BAAA;AAAA,gBACR,CAAC,YAAY,IAAA,CAAK,SAAA,CAAU,SAAS,OAAO,CAAA,CAAE,OAAA,CAAQ,sBAAA,CAAuB,IAAI,CAAA;AAAA,gBACjF,IAAA,CAAK;AAAA,eACN;AACA,cAAA;AAAA,YACD;AAAA;AACD,QACD;AAEA,QAAA,IAAI,gBAAA,EAAkB,OAAO,gBAAA,CAAiB,IAAA,CAAK,MAAM,QAAQ,CAAA;AAAA,MAClE,CAAA,EA3BsC,6BAAA,CAAA;AA6BtC,MAAA,OAAO,OAAA;AAAA,IACR;AAAA,GACA,CAAA;AAED,EAAA,iCAAA,CAAkC,GAAA,CAAI,SAAS,QAAQ,CAAA;AACvD,EAAA,iCAAA,CAAkC,GAAA,CAAI,UAAU,OAAO,CAAA;AAEvD,EAAA,OAAO,OAAA;AACR;AApDS,MAAA,CAAA,mCAAA,EAAA,qCAAA,CAAA","file":"index.mjs","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 */\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 { 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: object, key: string) => {\n\t\tReflect.defineProperty(target, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as object, 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 { isNullish } from '@sapphire/utilities';\nimport { PermissionFlagsBits, PermissionsBitField, type BaseInteraction, type Message, type PermissionResolvable } from 'discord.js';\nimport { createFunctionPrecondition, type FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new PermissionsBitField(\n\t~new PermissionsBitField([\n\t\t//\n\t\tPermissionFlagsBits.AddReactions,\n\t\tPermissionFlagsBits.AttachFiles,\n\t\tPermissionFlagsBits.EmbedLinks,\n\t\tPermissionFlagsBits.ReadMessageHistory,\n\t\tPermissionFlagsBits.SendMessages,\n\t\tPermissionFlagsBits.UseExternalEmojis,\n\t\tPermissionFlagsBits.ViewChannel\n\t]).bitfield & PermissionsBitField.All\n);\n\nconst DMAvailableUserPermissions = new PermissionsBitField(\n\t~new PermissionsBitField([\n\t\tPermissionFlagsBits.AddReactions,\n\t\tPermissionFlagsBits.AttachFiles,\n\t\tPermissionFlagsBits.EmbedLinks,\n\t\tPermissionFlagsBits.ReadMessageHistory,\n\t\tPermissionFlagsBits.SendMessages,\n\t\tPermissionFlagsBits.UseExternalEmojis,\n\t\tPermissionFlagsBits.ViewChannel,\n\t\tPermissionFlagsBits.UseExternalStickers,\n\t\tPermissionFlagsBits.MentionEveryone\n\t]).bitfield & PermissionsBitField.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 { Subcommand } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Subcommand.Options>({\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 Subcommand {\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 PermissionsBitField(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);\n\n\treturn createFunctionPrecondition((context: Message | BaseInteraction) => {\n\t\tconst { channel } = context;\n\t\tconst member = context.guild?.members.me;\n\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(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(channel) && !isNullish(member)) {\n\t\t\tconst missingPermissions = channel.permissionsFor(member).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 { Subcommand } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Subcommand.Options>({\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 Subcommand {\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 PermissionsBitField(permissionsResolvable);\n\tconst resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailableUserPermissions.bitfield);\n\n\treturn createFunctionPrecondition((context: Message | BaseInteraction) => {\n\t\tconst { channel } = context;\n\t\tconst member = context.guild?.members.me;\n\n\t\tif (resolvedIncludesServerPermissions && isDMChannel(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(channel) && !isNullish(member)) {\n\t\t\tconst missingPermissions = channel.permissionsFor(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 {@link Message} or {@link BaseInteraction} instance which includes all interaction types\n * @since 1.0.0\n * @param fallback The fallback value passed to {@link createFunctionPrecondition}\n */\nexport function RequiresGuildContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((context: Message | BaseInteraction) => context.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 {@link Message} or {@link BaseInteraction} instance which includes all interaction types\n * @since 1.0.0\n * @param fallback The fallback value passed to {@link createFunctionPrecondition}\n */\nexport function RequiresDMContext(fallback: FunctionFallback = (): void => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((context: Message | BaseInteraction) => context.guild === null, fallback);\n}\n","import { container, type ApplicationCommandRegistryRegisterOptions, type Command, type Piece } from '@sapphire/framework';\nimport type { Container } from '@sapphire/pieces';\nimport type { Ctor } from '@sapphire/utilities';\nimport {\n\tApplicationCommandType,\n\ttype ContextMenuCommandBuilder,\n\ttype SlashCommandBuilder,\n\ttype SlashCommandOptionsOnlyBuilder,\n\ttype SlashCommandSubcommandsOnlyBuilder\n} from 'discord.js';\nimport { createClassDecorator, createProxy } from './utils';\n\nconst applicationDecoratorsMap = new WeakMap<CommandTarget<any>, DecoratorMap<any>[]>();\nconst proxyApplicationCommandToOriginal = new WeakMap<CommandTarget<any>, CommandTarget<any>>();\nconst originalApplicationCommandToProxy = new WeakMap<CommandTarget<any>, CommandTarget<any>>();\n\n/**\n * Decorator function that applies given options to any Sapphire piece\n * @param optionsOrFn The options or function that returns 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.js';\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.LoaderContext, 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\n/**\n * Decorator for registering chat input command.\n * @param optionsFn The function that returns options to pass to the registry.\n * @example\n * ```typescript\n * import { RegisterChatInputCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n *\n * (at)RegisterChatInputCommand((builder, command) => builder\n * .setName(command.name)\n * .setDescription(command.description)\n * )\n * export class UserCommand extends Command {\n * \t public override chatInputRun(interaction: Command.ChatInputCommandInteraction) {\n * \t \treturn interaction.reply({ content: 'HI!' });\n * \t }\n * }\n * ```\n * @example\n * ```typescript\n * import { RegisterChatInputCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n *\n * (at)RegisterChatInputCommand((builder, command) => builder\n *\t\t.setName(command.name)\n *\t\t.setDescription(command.description),\n *\t{\n *\t\tidHints: ['737141877803057244'],\n *\t\tguildIds: ['737141877803057244']\n *\t}\n * )\n * export class UserCommand extends Command {\n * \t public override chatInputRun(interaction: Command.ChatInputCommandInteraction) {\n * \t \treturn interaction.reply({ content: 'HI!' });\n * \t }\n * }\n * ```\n * @example\n * ```typescript\n * import { RegisterChatInputCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n *\n * (at)RegisterChatInputCommand((builder) => builder\n * .setName('hi')\n * .setDescription('Sends a hi message')\n * )\n * export class UserCommand extends Command {\n * \t public override chatInputRun(interaction: Command.ChatInputCommandInteraction) {\n * \t \treturn interaction.reply({ content: 'HI!' });\n * \t }\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions, RegisterChatInputCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Command.Options>({\n * description: 'ping pong',\n * enabled: true\n * })\n * (at)RegisterChatInputCommand((builder, command) => builder\n * .setName(command.name)\n * .setDescription(command.description)\n * )\n * export class UserCommand extends Command { *\n * \t public override chatInputRun(interaction: Command.ChatInputCommandInteraction) {\n * \t \treturn interaction.reply({ content: 'HI!' });\n * \t }\n * }\n * ```\n */\nexport function RegisterChatInputCommand<CMD extends Command = Command>(\n\toptionsFn: ChatInputCommandDecoratorsMap<CMD>['optionsFn'],\n\tregistryOptions?: ApplicationCommandRegistryRegisterOptions\n): ClassDecorator {\n\treturn createClassDecorator((target: CommandTarget<CMD>) =>\n\t\tcollectApplicationCommandDecorators(target, { type: 'RegisterChatInputCommand', optionsFn, registryOptions })\n\t);\n}\n\n/**\n * Decorator for registering message context menu command.\n * @param optionsFn The function that returns options to pass to the registry.\n * @example\n * ```typescript\n * import { RegisterMessageContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type MessageContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterMessageContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * import { RegisterMessageContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type MessageContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterMessageContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall),\n *\t{\n *\t\tidHints: ['737141877803057244'],\n *\t\tguildIds: ['737141877803057244']\n *\t}\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * import { RegisterMessageContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type MessageContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterMessageContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * import { RegisterMessageContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type MessageContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterMessageContextMenuCommand((builder) => builder\n * \t .setName('Send HI')\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions, RegisterMessageContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type MessageContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)ApplyOptions<Command.Options>({\n * enabled: true\n * })\n * (at)RegisterMessageContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n */\nexport function RegisterMessageContextMenuCommand<CMD extends Command = Command>(\n\toptionsFn: ContextMenuCommandDecoratorsMap<CMD>['optionsFn'],\n\tregistryOptions?: ApplicationCommandRegistryRegisterOptions\n): ClassDecorator {\n\treturn createClassDecorator((target: CommandTarget<CMD>) =>\n\t\tcollectApplicationCommandDecorators(target, { type: 'RegisterMessageContextMenuCommand', optionsFn, registryOptions })\n\t);\n}\n\n/**\n * Decorator for registering user context menu command.\n * @param optionsFn The function that returns options to pass to the registry.\n * @example\n * ```typescript\n * import { RegisterUserContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type UserContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterUserContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: UserContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n * ```\n * @example\n * ```typescript\n * import { RegisterUserContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type MessageContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterUserContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall),\n *\t{\n *\t\tidHints: ['737141877803057244'],\n *\t\tguildIds: ['737141877803057244']\n *\t}\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * import { RegisterUserContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type UserContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)RegisterUserContextMenuCommand((builder, command) => builder\n * \t .setName('Send HI')\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: UserContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: `HI ${interaction.targetUser}!` })\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * import { ApplyOptions, RegisterUserContextMenuCommand } from '@sapphire/decorators';\n * import { Command } from '@sapphire/framework';\n * import { ApplicationIntegrationType, InteractionContextType, type UserContextMenuCommandInteraction } from 'discord.js';\n *\n * (at)ApplyOptions<Command.Options>({\n * enabled: true\n * })\n * (at)RegisterUserContextMenuCommand((builder, command) => builder\n * \t .setName(command.name)\n * \t .setContexts(InteractionContextType.Guild)\n * \t .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)\n * )\n * export class UserCommand extends Command {\n * \tpublic override contextMenuRun(interaction: MessageContextMenuCommandInteraction) {\n * \t\treturn interaction.reply({ content: 'HI!' })\n * \t}\n * }\n * ```\n */\nexport function RegisterUserContextMenuCommand<CMD extends Command = Command>(\n\toptionsFn: ContextMenuCommandDecoratorsMap<CMD>['optionsFn'],\n\tregistryOptions?: ApplicationCommandRegistryRegisterOptions\n): ClassDecorator {\n\treturn createClassDecorator((target: CommandTarget<CMD>) =>\n\t\tcollectApplicationCommandDecorators(target, { type: 'RegisterUserContextMenuCommand', optionsFn, registryOptions })\n\t);\n}\n\nfunction collectApplicationCommandDecorators<CMD extends Command>(target: CommandTarget<CMD>, decorator: DecoratorMap<CMD>): CommandTarget<CMD> {\n\tconst original = proxyApplicationCommandToOriginal.get(target) ?? target;\n\n\tconst exisiting = applicationDecoratorsMap.get(original) ?? [];\n\texisiting.push(decorator);\n\tapplicationDecoratorsMap.set(original, exisiting);\n\n\tif (originalApplicationCommandToProxy.has(original)) return originalApplicationCommandToProxy.get(original)!;\n\n\tconst proxied = createProxy(target, {\n\t\tconstruct(originalTarget, argArray) {\n\t\t\tconst command: CMD = Reflect.construct(originalTarget, argArray);\n\t\t\tconst decorators = applicationDecoratorsMap.get(original) as DecoratorMap<CMD>[];\n\n\t\t\tconst originalRegister = command.registerApplicationCommands?.bind(command);\n\t\t\tcommand.registerApplicationCommands = function registerApplicationCommands(registry: Command.Registry) {\n\t\t\t\tfor (const deco of decorators) {\n\t\t\t\t\tswitch (deco.type) {\n\t\t\t\t\t\tcase 'RegisterChatInputCommand': {\n\t\t\t\t\t\t\tregistry.registerChatInputCommand((builder) => deco.optionsFn(builder, command), deco.registryOptions);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcase 'RegisterMessageContextMenuCommand': {\n\t\t\t\t\t\t\tregistry.registerContextMenuCommand(\n\t\t\t\t\t\t\t\t(builder) => deco.optionsFn(builder, command).setType(ApplicationCommandType.Message),\n\t\t\t\t\t\t\t\tdeco.registryOptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcase 'RegisterUserContextMenuCommand': {\n\t\t\t\t\t\t\tregistry.registerContextMenuCommand(\n\t\t\t\t\t\t\t\t(builder) => deco.optionsFn(builder, command).setType(ApplicationCommandType.User),\n\t\t\t\t\t\t\t\tdeco.registryOptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (originalRegister) return originalRegister.call(this, registry);\n\t\t\t};\n\n\t\t\treturn command;\n\t\t}\n\t});\n\n\tproxyApplicationCommandToOriginal.set(proxied, original);\n\toriginalApplicationCommandToProxy.set(original, proxied);\n\n\treturn proxied;\n}\n\nexport interface ApplyOptionsCallbackParameters {\n\tcontainer: Container;\n\tcontext: Piece.LoaderContext;\n}\n\ninterface ChatInputCommandDecoratorsMap<CMD extends Command> {\n\ttype: 'RegisterChatInputCommand';\n\toptionsFn: (\n\t\tbuilder: SlashCommandBuilder,\n\t\tcommand: ThisType<CMD> & CMD\n\t) => SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | SlashCommandOptionsOnlyBuilder;\n\tregistryOptions?: ApplicationCommandRegistryRegisterOptions;\n}\n\ninterface ContextMenuCommandDecoratorsMap<CMD extends Command> {\n\ttype: 'RegisterMessageContextMenuCommand' | 'RegisterUserContextMenuCommand';\n\toptionsFn: (\n\t\tbuilder: ContextMenuCommandBuilder, //\n\t\tcommand: ThisType<CMD> & CMD\n\t) => ContextMenuCommandBuilder;\n\tregistryOptions?: ApplicationCommandRegistryRegisterOptions;\n}\n\ntype CommandTarget<CMD extends Command> = Ctor<ConstructorParameters<typeof Command>, CMD>;\ntype DecoratorMap<CMD extends Command> = ChatInputCommandDecoratorsMap<CMD> | ContextMenuCommandDecoratorsMap<CMD>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,43 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/decorators",
|
|
3
|
-
"version": "7.0.0-pr-
|
|
3
|
+
"version": "7.0.0-pr-935.7da5c8bb",
|
|
4
4
|
"description": "Useful TypeScript decorators for Sapphire Framework Discord bots",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/index.
|
|
8
|
-
"
|
|
7
|
+
"main": "dist/cjs/index.cjs",
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
|
+
"types": "dist/cjs/index.d.cts",
|
|
9
10
|
"exports": {
|
|
10
|
-
"import":
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/esm/index.d.mts",
|
|
13
|
+
"default": "./dist/esm/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/cjs/index.d.cts",
|
|
17
|
+
"default": "./dist/cjs/index.cjs"
|
|
18
|
+
}
|
|
13
19
|
},
|
|
14
20
|
"sideEffects": false,
|
|
15
21
|
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/decorators",
|
|
16
22
|
"scripts": {
|
|
17
23
|
"test": "vitest run",
|
|
18
24
|
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
|
19
|
-
"build": "tsup",
|
|
25
|
+
"build": "yarn gen-index && tsup && yarn build:rename-cjs-index",
|
|
26
|
+
"build:rename-cjs-index": "tsx ../../scripts/rename-cjs-index.cts",
|
|
20
27
|
"docs": "typedoc-json-parser",
|
|
21
28
|
"prepack": "yarn build",
|
|
22
29
|
"bump": "cliff-jumper",
|
|
23
|
-
"check-update": "cliff-jumper --dry-run"
|
|
30
|
+
"check-update": "cliff-jumper --dry-run",
|
|
31
|
+
"gen-index": "tsx ../../scripts/gen-index.cts decorators --write"
|
|
24
32
|
},
|
|
25
33
|
"dependencies": {
|
|
26
|
-
"tslib": "^2.
|
|
34
|
+
"tslib": "^2.8.1"
|
|
27
35
|
},
|
|
28
36
|
"devDependencies": {
|
|
29
|
-
"@favware/cliff-jumper": "^
|
|
30
|
-
"@sapphire/discord-utilities": "^3.0
|
|
31
|
-
"@sapphire/discord.js-utilities": "^
|
|
32
|
-
"@sapphire/ratelimits": "^2.4.
|
|
33
|
-
"@sapphire/result": "^2.
|
|
34
|
-
"@sapphire/utilities": "^3.
|
|
35
|
-
"@vitest/coverage-
|
|
36
|
-
"tsup": "^
|
|
37
|
-
"
|
|
38
|
-
"typedoc
|
|
39
|
-
"
|
|
40
|
-
"
|
|
37
|
+
"@favware/cliff-jumper": "^6.0.0",
|
|
38
|
+
"@sapphire/discord-utilities": "^3.5.0",
|
|
39
|
+
"@sapphire/discord.js-utilities": "^7.3.3",
|
|
40
|
+
"@sapphire/ratelimits": "^2.4.11",
|
|
41
|
+
"@sapphire/result": "^2.7.3",
|
|
42
|
+
"@sapphire/utilities": "^3.18.2",
|
|
43
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
|
+
"tsx": "^4.20.6",
|
|
46
|
+
"typedoc": "^0.26.11",
|
|
47
|
+
"typedoc-json-parser": "^10.2.0",
|
|
48
|
+
"typescript": "~5.4.5",
|
|
49
|
+
"vitest": "^3.2.4"
|
|
41
50
|
},
|
|
42
51
|
"repository": {
|
|
43
52
|
"type": "git",
|
|
@@ -45,9 +54,7 @@
|
|
|
45
54
|
"directory": "packages/decorators"
|
|
46
55
|
},
|
|
47
56
|
"files": [
|
|
48
|
-
"dist
|
|
49
|
-
"dist/**/*.mjs*",
|
|
50
|
-
"dist/**/*.d*"
|
|
57
|
+
"dist/"
|
|
51
58
|
],
|
|
52
59
|
"engines": {
|
|
53
60
|
"node": ">=v14.0.0",
|
package/dist/index.d.ts
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
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 { Subcommand } from '@sapphire/plugin-subcommands';
|
|
104
|
-
* import type { Message } from 'discord.js';
|
|
105
|
-
*
|
|
106
|
-
* (at)ApplyOptions<Subcommand.Options>({
|
|
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 Subcommand {
|
|
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 { Subcommand } from '@sapphire/plugin-subcommands';
|
|
144
|
-
* import type { Message } from 'discord.js';
|
|
145
|
-
*
|
|
146
|
-
* (at)ApplyOptions<Subcommand.Options>({
|
|
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 Subcommand {
|
|
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.js';
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/base-decorators.ts","../src/djs-decorators.ts","../src/piece-decorators.ts"],"names":["target","DecoratorIdentifiers"],"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;AAmBT,SAAS,YAA8B,QAAW,SAA0C;AAClG,SAAO,IAAI,MAAM,QAAQ;AAAA,IACxB,GAAG;AAAA,IACH,KAAK,CAACA,SAAQ,aAAa;AAC1B,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,QAAQ;AAC1C,aAAO,OAAO,UAAU,aAAa,IAAI,SAA6B,MAAM,MAAMA,SAAQ,IAAI,IAAI;AAAA,IACnG;AAAA,EACD,CAAC;AACF;AARgB;;;ACpFT,SAAS,WAAW,OAAgB;AAC1C,SAAO,CAAC,QAAiB,QAAgB;AAC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uC;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","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 */\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, PermissionFlagsBits, PermissionsBitField, type PermissionResolvable } from 'discord.js';\nimport { createFunctionPrecondition, type FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new PermissionsBitField(\n\t~new PermissionsBitField([\n\t\t//\n\t\tPermissionFlagsBits.AddReactions,\n\t\tPermissionFlagsBits.AttachFiles,\n\t\tPermissionFlagsBits.EmbedLinks,\n\t\tPermissionFlagsBits.ReadMessageHistory,\n\t\tPermissionFlagsBits.SendMessages,\n\t\tPermissionFlagsBits.UseExternalEmojis,\n\t\tPermissionFlagsBits.ViewChannel\n\t]).bitfield & PermissionsBitField.All\n);\n\nconst DMAvailableUserPermissions = new PermissionsBitField(\n\t~new PermissionsBitField([\n\t\tPermissionFlagsBits.AddReactions,\n\t\tPermissionFlagsBits.AttachFiles,\n\t\tPermissionFlagsBits.EmbedLinks,\n\t\tPermissionFlagsBits.ReadMessageHistory,\n\t\tPermissionFlagsBits.SendMessages,\n\t\tPermissionFlagsBits.UseExternalEmojis,\n\t\tPermissionFlagsBits.ViewChannel,\n\t\tPermissionFlagsBits.UseExternalStickers,\n\t\tPermissionFlagsBits.MentionEveryone\n\t]).bitfield & PermissionsBitField.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 { Subcommand } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Subcommand.Options>({\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 Subcommand {\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 PermissionsBitField(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!.members.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 { Subcommand } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Subcommand.Options>({\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 Subcommand {\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 PermissionsBitField(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.js';\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"]}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/base-decorators.ts","../src/djs-decorators.ts","../src/piece-decorators.ts"],"names":["target","DecoratorIdentifiers"],"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;AAmBT,SAAS,YAA8B,QAAW,SAA0C;AAClG,SAAO,IAAI,MAAM,QAAQ;AAAA,IACxB,GAAG;AAAA,IACH,KAAK,CAACA,SAAQ,aAAa;AAC1B,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,QAAQ;AAC1C,aAAO,OAAO,UAAU,aAAa,IAAI,SAA6B,MAAM,MAAMA,SAAQ,IAAI,IAAI;AAAA,IACnG;AAAA,EACD,CAAC;AACF;AARgB;;;ACpFT,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,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,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","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 */\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, PermissionFlagsBits, PermissionsBitField, type PermissionResolvable } from 'discord.js';\nimport { createFunctionPrecondition, type FunctionFallback } from './utils';\n\nexport enum DecoratorIdentifiers {\n\tRequiresClientPermissionsGuildOnly = 'requiresClientPermissionsGuildOnly',\n\tRequiresClientPermissionsMissingPermissions = 'requiresClientPermissionsMissingPermissions',\n\tRequiresUserPermissionsGuildOnly = 'requiresUserPermissionsGuildOnly',\n\tRequiresUserPermissionsMissingPermissions = 'requiresUserPermissionsMissingPermissions'\n}\n\nconst DMAvailablePermissions = new PermissionsBitField(\n\t~new PermissionsBitField([\n\t\t//\n\t\tPermissionFlagsBits.AddReactions,\n\t\tPermissionFlagsBits.AttachFiles,\n\t\tPermissionFlagsBits.EmbedLinks,\n\t\tPermissionFlagsBits.ReadMessageHistory,\n\t\tPermissionFlagsBits.SendMessages,\n\t\tPermissionFlagsBits.UseExternalEmojis,\n\t\tPermissionFlagsBits.ViewChannel\n\t]).bitfield & PermissionsBitField.All\n);\n\nconst DMAvailableUserPermissions = new PermissionsBitField(\n\t~new PermissionsBitField([\n\t\tPermissionFlagsBits.AddReactions,\n\t\tPermissionFlagsBits.AttachFiles,\n\t\tPermissionFlagsBits.EmbedLinks,\n\t\tPermissionFlagsBits.ReadMessageHistory,\n\t\tPermissionFlagsBits.SendMessages,\n\t\tPermissionFlagsBits.UseExternalEmojis,\n\t\tPermissionFlagsBits.ViewChannel,\n\t\tPermissionFlagsBits.UseExternalStickers,\n\t\tPermissionFlagsBits.MentionEveryone\n\t]).bitfield & PermissionsBitField.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 { Subcommand } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Subcommand.Options>({\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 Subcommand {\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 PermissionsBitField(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!.members.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 { Subcommand } from '@sapphire/plugin-subcommands';\n * import type { Message } from 'discord.js';\n *\n * (at)ApplyOptions<Subcommand.Options>({\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 Subcommand {\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 PermissionsBitField(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.js';\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"]}
|