JaBa/helpers/autoUpdateDocs.js

43 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

const table = require("markdown-table"),
fs = require("fs");
2022-08-30 14:26:56 +05:00
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
2022-08-30 14:26:56 +05:00
*/
module.exports.update = function (client) {
const commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()],
categories = [];
2022-08-13 19:55:20 +05:00
commands.forEach(cmd => {
if (cmd.category === "Owner") return;
if (!categories.includes(cmd.category)) categories.push(cmd.category);
});
2023-10-10 20:44:42 +05:00
let text = `# JaBa has **${commands.length} ${client.functions.getNoun(commands.length, "command", "commands", "commands")}** in **${categories.length} ${client.functions.getNoun(categories.length, "category", "categories", "categories")}**! \n\n#### Table content \n**Name**: Command name \n**Description**: Command description \n**Usage**: How to use the command (*[]* - required, *()* - optional) \n**Accessible in**: Where you can use the command \n\n`;
categories.sort().forEach(cat => {
2023-10-10 20:44:42 +05:00
const categoriesArray = [["Name", "Description", "Usage", "Accessible in"]];
const cmds = [...new Map(commands.filter(cmd => cmd.category === cat).map(v => [v.constructor.name, v])).values()];
2023-10-10 20:44:42 +05:00
text += `### ${cat} (${cmds.length} ${client.functions.getNoun(cmds.length, "command", "commands", "commands")})\n\n`;
cmds.sort(function (a, b) {
if (a.command.name < b.command.name) return -1;
else return 1;
2022-08-13 19:55:20 +05:00
}).forEach(cmd => {
categoriesArray.push([
`**${cmd.command.name}**`,
client.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:DESCRIPTION`),
`${cmd.command.name} ${client.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:USAGE`).replace(/\n/, " \\| ")}`,
cmd.command.dm_permission ? "Anywhere" : "Servers only",
]);
2022-01-04 02:18:28 +05:00
});
text += `${table(categoriesArray)}\n\n`;
});
if (!fs.existsSync("./dashboard/public/docs")) fs.mkdirSync("./dashboard/public/docs");
fs.writeFileSync("./dashboard/public/docs/commands.md", text);
client.logger.log("Dashboard docs updated!");
2023-07-05 00:58:06 +05:00
};