Improve whitelist feature
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.
This commit is contained in:
SileNce5k 2025-04-30 15:55:53 +02:00
parent c9d7a54e25
commit a066fd0662
Signed by: SileNce
GPG key ID: B0A142BB4291B204
6 changed files with 81 additions and 71 deletions

View file

@ -1,6 +1,3 @@
const fs = require('fs');
const customReplaceWithVariables = require('../util/custom_commands/customReplaceWithVariables');
module.exports = function(client, owners, message, globalPrefix){
let prefix = globalPrefix;
let serverPrefix = client.serverPrefixes.get(message.guild.id);
@ -22,19 +19,12 @@ module.exports = function(client, owners, message, globalPrefix){
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
if (!command){
const customPath = './data/customCommands.json';
if(fs.existsSync(customPath)){
let json = fs.readFileSync(customPath, 'utf8');
let customCommands = JSON.parse(json)
customCommands.forEach(function (customCommand) {
if (customCommand.customName === commandName) {
let customMessage = customReplaceWithVariables(customCommand.customMessage, message, prefix, globalPrefix)
message.channel.send(customMessage)
}
});
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;
}
return;
}
if (command.admin && owners.indexOf(message.author.id.toString()) == -1) return;
try {