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;
|
||||
}
|
23
util/deleteCustomCommand.js
Normal file
23
util/deleteCustomCommand.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const fs = require('fs')
|
||||
module.exports = function(customName, author){
|
||||
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){
|
||||
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;
|
||||
}
|
13
util/getAllCustomCommands.js
Normal file
13
util/getAllCustomCommands.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(){
|
||||
const customPath = './data/customCommands.json';
|
||||
let list = "";
|
||||
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
customCommands.forEach(function (customCommand) {
|
||||
list = list + customCommand.customName+"\n";
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
15
util/getOwnerOfCustomCommand.js
Normal file
15
util/getOwnerOfCustomCommand.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(customName){
|
||||
let author = false;
|
||||
const customPath = './data/customCommands.json';
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
author = customCommand.author;
|
||||
}
|
||||
});
|
||||
|
||||
return author;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue