cardboardbox/events/message.js
2019-12-23 22:40:11 -05:00

43 lines
1.8 KiB
JavaScript

module.exports = async (client, message) => {
if (message.author.bot) return;
const settings = message.settings = client.getSettings(message.guild);
const prefixMention = new RegExp(`^<@!?${client.user.id}>( |)$`);
if (message.content.match(prefixMention)) {
return message.reply(`my prefix for this guild is \`${settings.prefix}\``);
}
if (message.content.indexOf(settings.prefix) !== 0) return;
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (message.guild && !message.member) await message.guild.fetchMember(message.author);
const level = client.permlevel(message);
const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command));
if (!cmd) return;
if (cmd && !message.guild && cmd.conf.guildOnly)
return message.channel.send("This command is unavailable via private message. Please run this command in a guild.");
if (level < client.levelCache[cmd.conf.permLevel]) {
if (settings.systemNotice === "true") {
message.delete();
return message.channel.send(`${message.author}, you do not have the right permissions to use this command.\nYour current permission level is **${level}** (${client.config.permLevels.find(l => l.level === level).name}), and this command requires permission level **${client.levelCache[cmd.conf.permLevel]}** (${cmd.conf.permLevel})`);
} else {
return;
}
}
message.author.permLevel = level;
message.flags = [];
while (args[0] && args[0][0] === "-") {
message.flags.push(args.shift().slice(1));
}
client.logger.cmd(`[CMD] ${client.config.permLevels.find(l => l.level === level).name} ${message.author.username} (${message.author.id}) ran command ${cmd.help.name}`);
cmd.run(client, message, args, level);
};