Add editing feature to custom command
Also edit the default if argument isn't recognised.
This commit is contained in:
parent
274215f665
commit
c1bc55d456
2 changed files with 28 additions and 3 deletions
|
@ -3,18 +3,20 @@ const deleteCustomCommand = require("../util/deleteCustomCommand");
|
||||||
const getAllCustomCommands = require("../util/getAllCustomCommands");
|
const getAllCustomCommands = require("../util/getAllCustomCommands");
|
||||||
const getOwnerOfCustomCommand = require("../util/getOwnerOfCustomCommand");
|
const getOwnerOfCustomCommand = require("../util/getOwnerOfCustomCommand");
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const fs = require('fs')
|
const fs = require('fs');
|
||||||
|
const editCustomCommand = require("../util/editCustomCommand");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'custom',
|
name: 'custom',
|
||||||
description: 'Add custom commands, see <prefix>help custom for more',
|
description: 'Add custom commands, see <prefix>help custom for more',
|
||||||
moreHelp: ["<prefix>custom add - Add new custom commands",
|
moreHelp: ["<prefix>custom add - Add new custom commands",
|
||||||
|
"<prefix>custom edit - Edit an existing command that you own",
|
||||||
"<prefix>custom remove - Delete your custom commands.",
|
"<prefix>custom remove - Delete your custom commands.",
|
||||||
"<prefix>custom owner - check owner of custom command",
|
"<prefix>custom owner - check owner of custom command",
|
||||||
"<prefix>custom list - list all custom commands",
|
"<prefix>custom list - list all custom commands",
|
||||||
"<prefix>custom variables - list all variables you can use"
|
"<prefix>custom variables - list all variables you can use"
|
||||||
],
|
],
|
||||||
execute({message, args, client}) {
|
execute({message, args, client, prefix}) {
|
||||||
const customPath = './data/customCommands.json';
|
const customPath = './data/customCommands.json';
|
||||||
if(!fs.existsSync(customPath)){
|
if(!fs.existsSync(customPath)){
|
||||||
fs.writeFileSync(customPath,"[]")
|
fs.writeFileSync(customPath,"[]")
|
||||||
|
@ -58,8 +60,11 @@ module.exports = {
|
||||||
case "variables":
|
case "variables":
|
||||||
sendText = "The variables you can use are:\n<prefix>\n<globalPrefix>\n<username>\n<nickname>\n<user_id>\n<discriminator>\n<guild_name>\n<guild_id>"
|
sendText = "The variables you can use are:\n<prefix>\n<globalPrefix>\n<username>\n<nickname>\n<user_id>\n<discriminator>\n<guild_name>\n<guild_id>"
|
||||||
break;
|
break;
|
||||||
|
case "edit":
|
||||||
|
sendText = editCustomCommand(customName, message.author.id, customMessage)
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sendText = "Argument not recognized."
|
sendText = `Argument not recognized.\n"${prefix}help custom" to see all arguments you can use.`
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
util/editCustomCommand.js
Normal file
20
util/editCustomCommand.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
module.exports = function(customName, author, newCustomMessage){
|
||||||
|
const customPath = './data/customCommands.json';
|
||||||
|
let sendText = "This custom command does not exist.";
|
||||||
|
let json = fs.readFileSync(customPath, 'utf8');
|
||||||
|
let customCommands = JSON.parse(json)
|
||||||
|
customCommands.forEach(function (customCommand) {
|
||||||
|
if (customCommand.customName === customName) {
|
||||||
|
if(customCommand.author === author){
|
||||||
|
customCommand.customMessage = newCustomMessage;
|
||||||
|
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||||
|
sendText = `${customName} has been updated.`;
|
||||||
|
}else {
|
||||||
|
sendText = "You do not own this custom command.\nOnly the one who created the custom command can edit it."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return sendText;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue