@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
56 lines (53 loc) • 2.58 kB
JavaScript
'use strict';
var pieces = require('@sapphire/pieces');
var Identifiers_cjs = require('../lib/errors/Identifiers.cjs');
var Command_cjs = require('../lib/structures/Command.cjs');
var Precondition_cjs = require('../lib/structures/Precondition.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var _CorePrecondition = class _CorePrecondition extends Precondition_cjs.AllFlowsPrecondition {
messageRun(message, _, context) {
const commandType = "message";
if (!context.types) return this.ok();
const channelType = message.channel.type;
if (Command_cjs.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_cjs.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_cjs.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_cjs.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 pieces.container.stores.loadPiece({
name: "RunIn",
piece: CorePrecondition,
store: "preconditions"
});
exports.CorePrecondition = CorePrecondition;
//# sourceMappingURL=RunIn.cjs.map
//# sourceMappingURL=RunIn.cjs.map