UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

53 lines (51 loc) 2.39 kB
import { __name } from '../chunk-PAWJFY3S.mjs'; import { container } from '@sapphire/pieces'; import { Identifiers } from '../lib/errors/Identifiers.mjs'; import { Command } from '../lib/structures/Command.mjs'; import { AllFlowsPrecondition } from '../lib/structures/Precondition.mjs'; var _CorePrecondition = class _CorePrecondition extends AllFlowsPrecondition { messageRun(message, _, context) { const commandType = "message"; if (!context.types) return this.ok(); const channelType = message.channel.type; if (Command.runInTypeIsSpecificsObject(context.types)) { return context.types.messageRun.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType); } return context.types.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType); } async chatInputRun(interaction, _, context) { const commandType = "chat input"; if (!context.types) return this.ok(); const channelType = (await this.fetchChannelFromInteraction(interaction)).type; if (Command.runInTypeIsSpecificsObject(context.types)) { return context.types.chatInputRun.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType); } return context.types.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType); } async contextMenuRun(interaction, _, context) { const commandType = "context menu"; if (!context.types) return this.ok(); const channelType = (await this.fetchChannelFromInteraction(interaction)).type; if (Command.runInTypeIsSpecificsObject(context.types)) { return context.types.contextMenuRun.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType); } return context.types.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType); } makeSharedError(context, commandType) { return this.error({ identifier: Identifiers.PreconditionRunIn, message: `You cannot run this ${commandType} command in this type of channel.`, context: { types: context.types } }); } }; __name(_CorePrecondition, "CorePrecondition"); var CorePrecondition = _CorePrecondition; void container.stores.loadPiece({ name: "RunIn", piece: CorePrecondition, store: "preconditions" }); export { CorePrecondition }; //# sourceMappingURL=RunIn.mjs.map //# sourceMappingURL=RunIn.mjs.map