UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

77 lines (74 loc) 3.93 kB
'use strict'; var pieces = require('@sapphire/pieces'); var result = require('@sapphire/result'); var Identifiers_cjs = require('../../errors/Identifiers.cjs'); var UserError_cjs = require('../../errors/UserError.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var _PreconditionContainerSingle = class _PreconditionContainerSingle { constructor(data) { if (typeof data === "string") { this.context = {}; this.name = data; } else { this.context = Reflect.get(data, "context") ?? {}; this.name = data.name; } } /** * Runs the container. * @since 1.0.0 * @param message The message that ran this precondition. * @param command The command the message invoked. * @param context The context for the message precondition. */ messageRun(message, command, context = {}) { const precondition = pieces.container.stores.get("preconditions").get(this.name); if (precondition) { return precondition.messageRun ? precondition.messageRun(message, command, { ...context, ...this.context }) : precondition.error({ identifier: Identifiers_cjs.Identifiers.PreconditionMissingMessageHandler, message: `The precondition "${precondition.name}" is missing a "messageRun" handler, but it was requested for the "${command.name}" command.` }); } return result.err(new UserError_cjs.UserError({ identifier: Identifiers_cjs.Identifiers.PreconditionUnavailable, message: `The precondition "${this.name}" is not available.` })); } /** * Runs the container. * @since 3.0.0 * @param interaction The interaction that ran this precondition. * @param command The command the interaction invoked. * @param context The context for the chat input command precondition. */ chatInputRun(interaction, command, context = {}) { const precondition = pieces.container.stores.get("preconditions").get(this.name); if (precondition) { return precondition.chatInputRun ? precondition.chatInputRun(interaction, command, { ...context, ...this.context }) : precondition.error({ identifier: Identifiers_cjs.Identifiers.PreconditionMissingChatInputHandler, message: `The precondition "${precondition.name}" is missing a "chatInputRun" handler, but it was requested for the "${command.name}" command.` }); } return result.err(new UserError_cjs.UserError({ identifier: Identifiers_cjs.Identifiers.PreconditionUnavailable, message: `The precondition "${this.name}" is not available.` })); } /** * Runs the container. * @since 3.0.0 * @param interaction The interaction that ran this precondition. * @param command The command the interaction invoked. * @param context The context for the context menu command precondition. */ contextMenuRun(interaction, command, context = {}) { const precondition = pieces.container.stores.get("preconditions").get(this.name); if (precondition) { return precondition.contextMenuRun ? precondition.contextMenuRun(interaction, command, { ...context, ...this.context }) : precondition.error({ identifier: Identifiers_cjs.Identifiers.PreconditionMissingContextMenuHandler, message: `The precondition "${precondition.name}" is missing a "contextMenuRun" handler, but it was requested for the "${command.name}" command.` }); } return result.err(new UserError_cjs.UserError({ identifier: Identifiers_cjs.Identifiers.PreconditionUnavailable, message: `The precondition "${this.name}" is not available.` })); } }; __name(_PreconditionContainerSingle, "PreconditionContainerSingle"); var PreconditionContainerSingle = _PreconditionContainerSingle; exports.PreconditionContainerSingle = PreconditionContainerSingle; //# sourceMappingURL=PreconditionContainerSingle.cjs.map //# sourceMappingURL=PreconditionContainerSingle.cjs.map