Add custom commands
This commit is contained in:
parent
ea65547701
commit
49a3c50980
6 changed files with 152 additions and 0 deletions
28
util/addCustomCommand.js
Normal file
28
util/addCustomCommand.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(customName, customMessage, author){
|
||||
let sendText;
|
||||
const customPath = './data/customCommands.json';
|
||||
if(!fs.existsSync(customPath)){
|
||||
fs.writeFileSync(customPath,"[]")
|
||||
}
|
||||
|
||||
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 has been added."
|
||||
}
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
return sendText;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue