* 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:
parent
c9d7a54e25
commit
ba88243dea
5 changed files with 56 additions and 46 deletions
|
@ -2,15 +2,22 @@ const sqlite3 = require('sqlite3').verbose();
|
|||
|
||||
module.exports = {
|
||||
name: 'whitelist',
|
||||
description: 'Whitelist different commands that need whitelisting.',
|
||||
description: 'Whitelist a command in a specific server.',
|
||||
admin: true,
|
||||
async execute({message, args, prefix}) {
|
||||
async execute({message, args, prefix, client}) {
|
||||
if(args < 2){
|
||||
message.channel.send(`You need to supply the command and channel that you want to whitelist\n\`${prefix}whitelist <command> <server_id>\``);
|
||||
return;
|
||||
}
|
||||
let command = args[0];
|
||||
let guild = args[1];
|
||||
if(guild === "this") guild = message.guild.id;
|
||||
// TODO: Add ability to remove server from whitelist.
|
||||
const whitelistedCommands = client.whitelist.get("guild");
|
||||
if(whitelistedCommands && whitelistedCommands.includes(command)){
|
||||
message.channel.send("Command is already whitelisted in that server.")
|
||||
return;
|
||||
}
|
||||
// TODO: First check if the bot has access to that guild before whitelisting.
|
||||
const databasePath = 'data/database.db'
|
||||
const db = new sqlite3.Database(databasePath)
|
||||
|
@ -35,8 +42,15 @@ module.exports = {
|
|||
}
|
||||
});
|
||||
})
|
||||
if(!err)
|
||||
if(!err){
|
||||
if(whitelistedCommands){
|
||||
whitelistedCommands.push(command);
|
||||
client.whitelist.set(guild, whitelistedCommands);
|
||||
}else {
|
||||
client.whitelist.set(guild, command);
|
||||
}
|
||||
message.channel.send("Command has been whitelisted in this server.")
|
||||
else message.channel.send("Could not whitelist the server with that command. Check the logs.")
|
||||
|
||||
} else message.channel.send("Could not whitelist the server with that command. Check the logs.")
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue