Move custom command files into own directory
This commit is contained in:
parent
e6bf4045ed
commit
4e41a035ed
9 changed files with 8 additions and 8 deletions
23
util/custom_commands/deleteCustomCommand.js
Normal file
23
util/custom_commands/deleteCustomCommand.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const fs = require('fs')
|
||||
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');
|
||||
let customCommands = JSON.parse(json)
|
||||
let index = 0;
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
if(customCommand.author === author || owners.indexOf(author) != -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."
|
||||
}
|
||||
}
|
||||
index++
|
||||
});
|
||||
|
||||
|
||||
return sendText;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue