@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
46 lines (44 loc) • 2.43 kB
JavaScript
"use strict";
const require_lib_errors_Identifiers = require('../lib/errors/Identifiers.cjs');
const require_lib_structures_Precondition = require('../lib/structures/Precondition.cjs');
const require_lib_structures_Command = require('../lib/structures/Command.cjs');
let __sapphire_pieces = require("@sapphire/pieces");
//#region src/preconditions/RunIn.ts
var CorePrecondition = class extends require_lib_structures_Precondition.AllFlowsPrecondition {
messageRun(message, _, context) {
const commandType = "message";
if (!context.types) return this.ok();
const channelType = message.channel.type;
if (require_lib_structures_Command.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 (require_lib_structures_Command.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 (require_lib_structures_Command.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: require_lib_errors_Identifiers.Identifiers.PreconditionRunIn,
message: `You cannot run this ${commandType} command in this type of channel.`,
context: { types: context.types }
});
}
};
__sapphire_pieces.container.stores.loadPiece({
name: "RunIn",
piece: CorePrecondition,
store: "preconditions"
});
//#endregion
exports.CorePrecondition = CorePrecondition;
//# sourceMappingURL=RunIn.cjs.map