UNPKG

rcnlx

Version:

A cli to generate discord.js projects

175 lines (172 loc) 5.01 kB
const fs = require("fs"); const path = require("path"); const chalk = require("chalk"); const symbols = require("log-symbols"); const res = path.resolve; const inquirer = require("inquirer"); const { ban, channel, emoji, guild, member, message, roles, } = require("../projectFiles/question"); const questions = [ { title: "clientUserGuildSettingsUpdate", description: "Emitted whenever the client user's settings update.", value: "clientUserGuildSettingsUpdate", }, { title: "clientUserSettingsUpdate", description: "Emitted when the client user's settings update.", value: "clientUserSettingsUpdate", }, { title: "ready", description: "Emitted when the client becomes ready to start working.", value: "ready", }, { title: "reconnecting", description: "Emitted whenever the client tries to reconnect to the WebSocket.", value: "reconnecting", }, { title: "resume", short: "hi", description: "Emitted whenever a WebSocket resumes.", value: "resume", }, ]; module.exports = async function (init) { if (init.toLowerCase() === "client") { inquirer .prompt([ { type: "list", message: "Please choose the event", name: "client", choices: questions.map( (v, i) => v.title + " " + chalk.grey(${v.description}`) ), }, { type: "input", message: "What do you want the name of the file to be? (DO NOT INCLUDE EXTENSIONS IN THE NAME)", name: "fileName", }, ]) .then(({ client, fileName }) => { const query = client.split(" ")[0]; let name; if (fileName.includes(".js")) name = fileName.replace(".js", ""); else name = fileName; try { fs.readFile( path.join(__dirname, "..", "events", "client", `${query}.js`), "utf8", async (err, data) => { if (err) throw err; fs.writeFileSync(res(`src/events/${name}.js`), data); console.log( chalk.green(`${symbols.success} ${name}.js has been created!`) ); } ); } catch (error) { console.log( chalk.red( `${symbols.error} Command Handler has not been initialised!` ) ); } }); } if (init.toLowerCase() === "guild") { inquirer .prompt([ { type: "list", message: "Please choose a suitable category", name: "g", choices: [ "ban", "channel", "emoji", "guild", "member", "message", "roles", ], }, ]) .then(({ g }) => { inquirer.prompt; let constant; if (g === "ban") constant = ban; if (g === "channel") constant = channel; if (g === "emoji") constant = emoji; if (g === "guild") constant = guild; if (g === "member") constant = member; if (g === "message") constant = message; if (g === "roles") constant = roles; inquirer .prompt([ { type: "list", message: "Please choose an event you want to add", name: "event", choices: constant.map( (v, i) => v.title + " " + chalk.grey(${v.desc}`) ), }, { type: "input", message: "What do you want the name of the file to be? (DO NOT INCLUDE EXTENSIONS IN THE NAME)", name: "fileName", }, ]) .then(({ event, fileName }) => { fs.readFile( path.join( __dirname, "..", "events", "guild", g, `${event.split(" ")[0]}.js` ), "utf8", async (err, data) => { try { fs.writeFileSync( res(`src/events/${fileName}.js`), data, (err) => console.log(err) ); console.log( chalk.green( `${symbols.success} ${ event.split(" ")[0] }.js has been created!` ) ); } catch (error) { console.log( chalk.red( `${symbols.error} Command Handler has not been initialised!` ) ); } } ); }); }); } };