UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

45 lines (43 loc) 2.15 kB
import { Identifiers } from "../lib/errors/Identifiers.mjs"; import { AllFlowsPrecondition } from "../lib/structures/Precondition.mjs"; import { Command } from "../lib/structures/Command.mjs"; import { container } from "@sapphire/pieces"; //#region src/preconditions/RunIn.ts var CorePrecondition = class 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 } }); } }; container.stores.loadPiece({ name: "RunIn", piece: CorePrecondition, store: "preconditions" }); //#endregion export { CorePrecondition }; //# sourceMappingURL=RunIn.mjs.map