@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
74 lines (72 loc) • 3.63 kB
JavaScript
import { __name } from '../../../chunk-PAWJFY3S.mjs';
import { container } from '@sapphire/pieces';
import { err } from '@sapphire/result';
import { Identifiers } from '../../errors/Identifiers.mjs';
import { UserError } from '../../errors/UserError.mjs';
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 = container.stores.get("preconditions").get(this.name);
if (precondition) {
return precondition.messageRun ? precondition.messageRun(message, command, { ...context, ...this.context }) : precondition.error({
identifier: Identifiers.PreconditionMissingMessageHandler,
message: `The precondition "${precondition.name}" is missing a "messageRun" handler, but it was requested for the "${command.name}" command.`
});
}
return err(new UserError({ identifier: 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 = container.stores.get("preconditions").get(this.name);
if (precondition) {
return precondition.chatInputRun ? precondition.chatInputRun(interaction, command, { ...context, ...this.context }) : precondition.error({
identifier: Identifiers.PreconditionMissingChatInputHandler,
message: `The precondition "${precondition.name}" is missing a "chatInputRun" handler, but it was requested for the "${command.name}" command.`
});
}
return err(new UserError({ identifier: 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 = container.stores.get("preconditions").get(this.name);
if (precondition) {
return precondition.contextMenuRun ? precondition.contextMenuRun(interaction, command, { ...context, ...this.context }) : precondition.error({
identifier: Identifiers.PreconditionMissingContextMenuHandler,
message: `The precondition "${precondition.name}" is missing a "contextMenuRun" handler, but it was requested for the "${command.name}" command.`
});
}
return err(new UserError({ identifier: Identifiers.PreconditionUnavailable, message: `The precondition "${this.name}" is not available.` }));
}
};
__name(_PreconditionContainerSingle, "PreconditionContainerSingle");
var PreconditionContainerSingle = _PreconditionContainerSingle;
export { PreconditionContainerSingle };
//# sourceMappingURL=PreconditionContainerSingle.mjs.map
//# sourceMappingURL=PreconditionContainerSingle.mjs.map