UNPKG

zkyc

Version:

Discord command handler.

121 lines (120 loc) 5.92 kB
const fs = require("fs"); const path = require("path"); const templates = require("./utils/templates.js"); function generateCommand(projectPath, name, description) { const newName = name.split(" ").join(""); const fileName = newName + ".js"; const commandDir = path.join(projectPath, "Commands"); const filePath = path.join(commandDir, fileName); fs.exists(filePath, (exists) => { if (!exists) { const template = templates.getNewCommandTemplate(newName, description); fs.promises.writeFile(filePath, template); } else { console.log(`${filePath} already exists.`); } }) }; exports.generateCommand = generateCommand; function generateEvent(projectPath, name) { const fileName = name + ".js"; const eventDir = path.join(projectPath, "Events"); const filePath = path.join(eventDir, fileName); fs.exists(filePath, (exists) => { if (!exists) { const template = templates.getNewEventTemplate(name); fs.promises.writeFile(filePath, template); } else { console.log(`${filePath} already exists.`); } }) } exports.generateEvent = generateEvent; function generateIndexTemplate(projectPath) { const filePath = path.join(projectPath, "index.js"); const template = templates.getIndexTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateIndexTemplate = generateIndexTemplate; function generateConfigTemplate(projectPath, projectName, projectTemplate, projectToken, projectPrefix) { const filePath = path.join(projectPath, "zkyc.json"); const template = templates.getConfigTemplate(projectName, projectTemplate, projectToken, projectPrefix); fs.promises.writeFile(filePath, template); }; exports.generateConfigTemplate = generateConfigTemplate; function generateClientTemplate(projectPath) { const structuresPath = path.join(projectPath, "Structures"); const filePath = path.join(structuresPath, "Client.js"); const template = templates.getClientTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateClientTemplate = generateClientTemplate; function generateCommandTemplate(projectPath) { const structuresPath = path.join(projectPath, "Structures"); const filePath = path.join(structuresPath, "Command.js"); const template = templates.getCommandTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateCommandTemplate = generateCommandTemplate; function generateEventTemplate(projectPath) { const structuresPath = path.join(projectPath, "Structures"); const filePath = path.join(structuresPath, "Event.js"); const template = templates.getEventTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateEventTemplate = generateEventTemplate; function generateMessageCreateTemplate(projectPath) { const structuresPath = path.join(projectPath, "Events"); const filePath = path.join(structuresPath, "messageCreate.js"); const template = templates.getMessageCreateTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateMessageCreateTemplate = generateMessageCreateTemplate; function generateReadyEventTemplate(projectPath) { const structuresPath = path.join(projectPath, "Events"); const filePath = path.join(structuresPath, "ready.js"); const template = templates.getReadyEventTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateReadyEventTemplate = generateReadyEventTemplate; function generatePingCommandTemplate(projectPath) { const structuresPath = path.join(projectPath, "Commands"); const sourceFile = path.join(__dirname, "templates/ping.js"); const filePath = path.join(structuresPath, "ping.js"); fs.promises.copyFile(sourceFile, filePath); }; exports.generatePingCommandTemplate = generatePingCommandTemplate; function generateMessageCreateTemplatePrefix(projectPath) { const structuresPath = path.join(projectPath, "Events"); const filePath = path.join(structuresPath, "messageCreate.js"); const template = templates.getMessageCreateTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateMessageCreateTemplatePrefix = generateMessageCreateTemplatePrefix; function generateJoinServerTemplate(projectPath, defaultPrefix) { const structuresPath = path.join(projectPath, "Events"); const filePath = path.join(structuresPath, "guildCreate.js"); const template = templates.getJoinServerTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateJoinServerTemplate = generateJoinServerTemplate; function generateServerDataTemplate(projectPath) { const structuresPath = path.join(projectPath, "Data"); const filePath = path.join(structuresPath, "serverData.json"); const template = templates.getServerDataTemplate(); fs.promises.writeFile(filePath, template); }; exports.generateServerDataTemplate = generateServerDataTemplate; function generatePerServerPrefixConfigTemplate(projectPath, projectName, projectTemplate, projectToken, projectDefaultPrefix) { const filePath = path.join(projectPath, "zkyc.json"); const template = templates.getPerServerPrefixConfigTemplate(projectName, projectTemplate, projectToken, projectDefaultPrefix); fs.promises.writeFile(filePath, template); }; exports.generatePerServerPrefixConfigTemplate = generatePerServerPrefixConfigTemplate; function generatePrefixCommandTemplate(projectPath) { const structuresPath = path.join(projectPath, "Commands"); const filePath = path.join(structuresPath, "prefix.js"); const template = templates.getPrefixCommandTemplate(); fs.promises.writeFile(filePath, template); }; exports.generatePrefixCommandTemplate = generatePrefixCommandTemplate;