JaBa/helpers/autoUpdateDocs.js

52 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
/* THIS UPDATES THE DOCS */
module.exports = {
/**
* Update the doc
* @param {object} client The Discord Client instance
*/
update(client) {
const table = require("markdown-table");
const fs = require("fs");
const commands = client.commands;
const categories = [];
commands.forEach((cmd) => {
if (!categories.includes(cmd.help.category)) categories.push(cmd.help.category);
});
2021-12-25 00:37:51 +05:00
let text = `# JaBa имеет свыше **${Math.floor(commands.size / 10)}0 команд** в **${categories.length} категориях**! \n\n#### Содержимое таблицы \n**Название**: Название команды \n**Описание**: Описание команды \n**Использование**: Использование команды ([] - обязательно, () - необязательно) \n**Откат**: Время, через которое команду можно будет использовать повторно\n\n`;
2021-12-10 21:39:54 +05:00
// categories.sort(function(a, b) {
2022-01-03 23:20:33 +05:00
// const aCmdsLength = commands.filter((cmd) => cmd.help.category === a).size;
// const bCmdsLength = commands.filter((cmd) => cmd.help.category === b).size;
// if (aCmdsLength > bCmdsLength) return -1;
// else return 1;
// })
categories.sort().forEach((cat) => {
2021-12-10 21:39:54 +05:00
const arrCat = [
2021-12-26 19:29:37 +05:00
["Название", "Описание", "Использование", "Откат"]
2021-12-10 21:39:54 +05:00
];
2022-01-03 23:20:33 +05:00
const cmds = commands.filter((cmd) => cmd.help.category === cat);
2021-12-30 20:03:36 +05:00
text += `### ${cat} (${cmds.length} ${client.getNoun(cmds.length, "команда", "команды", "команд")})\n\n`;
2021-12-26 19:29:37 +05:00
cmds.sort(function (a, b) {
2021-12-16 23:42:58 +05:00
if (a.help.name < b.help.name) return -1;
else return 1;
2021-12-10 21:39:54 +05:00
}).forEach((cmd) => {
arrCat.push([
2021-12-13 18:27:54 +05:00
`**${cmd.help.name}** ${cmd.help.aliases.length ? `**(${cmd.help.aliases.join(", ")})**` : ""}`,
2021-12-10 21:39:54 +05:00
client.translate(`${cmd.help.category.toLowerCase()}/${cmd.help.name}:DESCRIPTION`),
client.translate(`${cmd.help.category.toLowerCase()}/${cmd.help.name}:USAGE`),
2021-12-30 20:03:36 +05:00
`${Math.ceil(cmd.conf.cooldown / 1000)} ${client.getNoun(Math.ceil(cmd.conf.cooldown / 1000), "секунда", "секунды", "секунд")}`
2021-12-10 21:39:54 +05:00
]);
});
text += `${table(arrCat)}\n\n`;
});
2021-12-25 00:37:51 +05:00
if (!fs.existsSync("./dashboard/public/docs")) {
fs.mkdirSync("./dashboard/public/docs");
fs.writeFileSync("./dashboard/public/docs/commands.md", text);
2021-12-16 23:42:58 +05:00
client.logger.log("Dashboard docs updated!");
2021-12-25 00:37:51 +05:00
} else {
fs.writeFileSync("./dashboard/public/docs/commands.md", text);
2021-12-10 21:39:54 +05:00
client.logger.log("Dashboard docs updated!");
};
}
};