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
25
util/custom_commands/addCustomCommand.js
Normal file
25
util/custom_commands/addCustomCommand.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(customName, customMessage, author){
|
||||
let sendText;
|
||||
const customPath = './data/customCommands.json';
|
||||
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
|
||||
let isExists = false;
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
sendText = "This custom command already exists";
|
||||
isExists = true;
|
||||
}
|
||||
});
|
||||
if (!isExists) {
|
||||
let newCustomCommand = {
|
||||
"customName": customName, "customMessage": customMessage, "author": author
|
||||
}
|
||||
customCommands.push(newCustomCommand)
|
||||
sendText = `New custom command with the name "${customName}" added`
|
||||
}
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
return sendText;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue