From b872e88f85408613e6ac55a59432d72e3ecfd274 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Fri, 9 Jul 2021 20:22:38 +0200 Subject: [PATCH] Allow bot owner to delete custom commands --- commands/custom.js | 4 ++-- util/deleteCustomCommand.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/commands/custom.js b/commands/custom.js index 0d55eae..e54d693 100644 --- a/commands/custom.js +++ b/commands/custom.js @@ -17,7 +17,7 @@ module.exports = { "custom list - list all custom commands", "custom variables - list all variables you can use" ], - execute({message, args, client, prefix}) { + execute({message, args, client, prefix, owners}) { const customPath = './data/customCommands.json'; if(!fs.existsSync(customPath)){ fs.writeFileSync(customPath,"[]") @@ -36,7 +36,7 @@ module.exports = { break; case "remove": case "delete": - sendText = deleteCustomCommand(customName, message.author.id); + sendText = deleteCustomCommand(customName, message.author.id, owners); break; case "owner": let author = getOwnerOfCustomCommand(customName); diff --git a/util/deleteCustomCommand.js b/util/deleteCustomCommand.js index 89a3368..f646391 100644 --- a/util/deleteCustomCommand.js +++ b/util/deleteCustomCommand.js @@ -1,5 +1,5 @@ const fs = require('fs') -module.exports = function(customName, author){ +module.exports = function(customName, author, owners){ const customPath = './data/customCommands.json'; let sendText = "This custom command does not exist."; let json = fs.readFileSync(customPath, 'utf8'); @@ -7,10 +7,10 @@ module.exports = function(customName, author){ let index = 0; customCommands.forEach(function (customCommand) { if (customCommand.customName === customName) { - if(customCommand.author === author){ - customCommands.splice(index, 1) - sendText = `The custom command "${customName}" has been deleted.` - fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4)) + if(customCommand.author === author || owners.indexOf(author.toString()) != -1 ){ + customCommands.splice(index, 1) + sendText = `The custom command "${customName}" has been deleted.` + fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4)) }else { sendText = "You do not own this custom command.\nOnly the one who created the custom command can delete it." }