const addCustomCommand = require("../../util/custom_commands/addCustomCommand"); const deleteCustomCommand = require("../../util/custom_commands/deleteCustomCommand"); const getAllCustomCommands = require("../../util/custom_commands/getAllCustomCommands"); const getOwnerOfCustomCommand = require("../../util/custom_commands/getOwnerOfCustomCommand"); const renameCustomCommand = require("../../util/custom_commands/renameCustomCommand"); const {EmbedBuilder} = require('discord.js'); const fs = require('fs'); const editCustomCommand = require("../../util/custom_commands/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 rename - Rename 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", "custom count - display the amount of custom commands" ], execute({message, args, client, prefix, owners}) { const customPath = 'data/customCommands.json'; if(!fs.existsSync(customPath)){ fs.writeFileSync(customPath,"[]") } let sendText; let isEmbed = false; 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 EmbedBuilder(); sendText = getAllCustomCommands(); if(sendText !== ""){ embed.setColor(15780145) embed.addFields( { name: "Custom commands", value: sendText }, ) sendText = embed isEmbed = true; }else sendText = "NO CUSTOM COMMANDS" break; } case "variables": { sendText = "The variables you can use are:\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) sendText = "Command not found." customCommands.forEach(function (customCommand) { if (customCommand.customName === customName) { sendText = `\`\`\`\n${customCommand.customMessage}\n\`\`\`` } }); break; } case "rename": { sendText = renameCustomCommand(customName, args[2], message.author.id); break; } case "count": { const customPath = './data/customCommands.json'; let json = fs.readFileSync(customPath, 'utf8'); let customCommands = JSON.parse(json) sendText = `There are ${customCommands.length} custom commands in total`; break; } default: { sendText = `Argument not recognized.\n"${prefix}help custom" to see all arguments you can use.` break; } } } if(isEmbed) message.channel.send({embeds :[sendText]}) else message.channel.send(sendText); } };