const addCustomCommand = require("../util/addCustomCommand"); const deleteCustomCommand = require("../util/deleteCustomCommand"); const getAllCustomCommands = require("../util/getAllCustomCommands"); const getOwnerOfCustomCommand = require("../util/getOwnerOfCustomCommand"); const Discord = require('discord.js'); const fs = require('fs'); const editCustomCommand = require("../util/editCustomCommand"); module.exports = { name: 'custom', description: "Manage custom commands, see help custom for more", moreHelp: ["custom add - Add new custom commands", "custom edit - Edit an existing command that you own", "custom show - Show custom message unformatted.", "custom remove - Delete your custom commands.", "custom owner - check owner of custom command", "custom list - list all custom commands", "custom variables - list all variables you can use" ], execute({message, args, client, prefix, owners}) { const customPath = './data/customCommands.json'; if(!fs.existsSync(customPath)){ fs.writeFileSync(customPath,"[]") } let sendText; if (args){ let customName = args[1]; let customMessage = args.slice(2, args.length).join(" "); switch (args[0].toLowerCase()) { case "add": if(!customMessage) { message.channel.send("Message can't be empty"); return; } sendText = addCustomCommand(customName, customMessage, message.author.id); break; case "remove": case "delete": sendText = deleteCustomCommand(customName, message.author.id, owners); break; case "owner": let author = getOwnerOfCustomCommand(customName); let user; if(!author) sendText = `${customName} does not exist` else{ client.guilds.cache.each(guild => { user = guild.members.cache.get(author); }); sendText = `The owner of ${customName} is ${user.user.username} (id: ${user.user.id}).` } break; case "list": const embed = new Discord.MessageEmbed(); sendText = getAllCustomCommands(); if(sendText != ""){ embed.setColor(15780145) embed.addFields( { name: "Custom commands", value: sendText }, ) sendText = embed }else sendText = "NO CUSTOM COMMANDS" break; case "variables": sendText = "The variables you can use are:\n\n\n\n\n\n\n\n" break; case "edit": sendText = editCustomCommand(customName, message.author.id, customMessage) break; case "show": let json = fs.readFileSync(customPath, 'utf8'); let customCommands = JSON.parse(json) customCommands.forEach(function (customCommand) { if (customCommand.customName === args[1]) { sendText = `\`\`\`\n${customCommand.customMessage}\n\`\`\`` }else{ sendText = "Command not found." } }); break; default: sendText = `Argument not recognized.\n"${prefix}help custom" to see all arguments you can use.` break; } } message.channel.send(sendText); } };