dashboard-core/theme/dbd-soft-ui/utils/cmdHandler.js

45 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2023-06-19 14:21:58 +05:00
module.exports = (commands, prefix) => {
2023-06-22 19:36:52 +05:00
if (!commands) throw new Error("No commands were provided to the Soft UI cmdHandler.");
if (!prefix) prefix = "/";
const finalCategories = [];
const categories = [];
commands.map(cmd => {
if (!categories.includes(cmd.category)) categories.push(cmd.category);
});
for (const category of categories) {
2023-10-20 22:44:55 +05:00
if (category.toLowerCase().includes("admin") || category.toLowerCase().includes("owner") || category.toLowerCase().includes("development") || category.toLowerCase().includes("iat")) continue;
2023-06-22 19:36:52 +05:00
const commandsArr = [];
2024-02-06 21:51:49 +05:00
commands
.filter(cmd => cmd.category === category)
.map(cmd => {
const obj = {
commandName: cmd.name,
commandUsage: `${cmd.usage ? cmd.usage : `${prefix}${cmd.name}`}`,
commandDescription: cmd.description,
commandAlias: cmd.aliases?.join(", ") || "None",
};
commandsArr.push(obj);
});
2023-06-22 19:36:52 +05:00
const categoryObj = {
categoryId: category,
category: `${capitalizeFirstLetter(category)}`,
subTitle: `${capitalizeFirstLetter(category)} commands`,
list: commandsArr,
};
finalCategories.push(categoryObj);
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
return finalCategories;
2024-02-06 21:51:49 +05:00
};