All checks were successful
CI / CI (push) Successful in 1m24s
* Use a primary autoincrementing primary key because primary keys need to be unique * Cache whitelist on bot startup / only read from database once * "Externalize" whitelist checking to the messageCreate function.
39 lines
No EOL
1.6 KiB
JavaScript
39 lines
No EOL
1.6 KiB
JavaScript
module.exports = function(client, owners, message, globalPrefix){
|
|
let prefix = globalPrefix;
|
|
let serverPrefix = client.serverPrefixes.get(message.guild.id);
|
|
if (serverPrefix) {
|
|
prefix = serverPrefix;
|
|
}
|
|
|
|
|
|
if(message.content.startsWith(`<@${client.user.id}>`)){
|
|
let regex = new RegExp("(<@" + client.user.id + ">) *")
|
|
message.content = message.content.replace(regex, prefix);
|
|
}
|
|
if (!message.guild || message.author.bot || !message.content.startsWith(prefix)) return;
|
|
let args = message.content.slice(prefix.length).split(" ")
|
|
if(args[0] !== "fm" && args[0].startsWith("fm")){
|
|
let firstElement = args[0];
|
|
args.splice(0, 1, firstElement.substring(0, 2), firstElement.substring(2));
|
|
}
|
|
|
|
const commandName = args.shift().toLowerCase();
|
|
const command = client.commands.get(commandName);
|
|
if(command.needsWhitelist){
|
|
let isWhitelisted = client.whitelist.get(message.guild.id)?.includes(command.name);
|
|
if(!isWhitelisted){
|
|
message.channel.send(`\`${command.name}\` is not whitelisted in this server. The bot admin needs to whitelist the command in this server for it to work`)
|
|
return;
|
|
}
|
|
}
|
|
if (command.admin && owners.indexOf(message.author.id.toString()) == -1) return;
|
|
try {
|
|
command.execute({ message: message, args: args, client: client, prefix: prefix, owners: owners, globalPrefix: globalPrefix})
|
|
console.log(`${message.author.username}(id: ${message.author.id}) executed ${command.name} with '${args}' as arguments`)
|
|
} catch (error) {
|
|
let divider = "------------------------"
|
|
console.log(divider)
|
|
console.error(error)
|
|
console.log(divider)
|
|
}
|
|
} |