JaBa/commands/General/help.js

101 lines
3.9 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js");
class Help extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "help",
dirname: __dirname,
enabled: true,
guildOnly: false,
aliases: ["h", "commands"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
if (args[0]) {
const isCustom = (message.guild && data.guild.customCommands ? data.guild.customCommands.find((c) => c.name === args[0]) : false);
const cmd = this.client.commands.get(args[0]) || this.client.commands.get(this.client.aliases.get(args[0]));
if (!cmd && isCustom) {
2021-12-26 19:29:37 +05:00
return message.error("general/help:CUSTOM", {
cmd: args[0]
});
2021-12-10 21:39:54 +05:00
} else if (!cmd) {
2021-12-26 19:29:37 +05:00
return message.error("general/help:NOT_FOUND", {
search: args[0]
});
2021-12-10 21:39:54 +05:00
};
const description = message.translate(`${cmd.help.category.toLowerCase()}/${cmd.help.name}:DESCRIPTION`);
2021-12-26 19:29:37 +05:00
const usage = message.translate(`${cmd.help.category.toLowerCase()}/${cmd.help.name}:USAGE`, {
prefix: message.guild ? data.guild.prefix : ""
});
const examples = message.translate(`${cmd.help.category.toLowerCase()}/${cmd.help.name}:EXAMPLES`, {
prefix: message.guild ? data.guild.prefix : ""
});
2021-12-10 21:39:54 +05:00
const groupEmbed = new Discord.MessageEmbed()
2021-12-26 19:29:37 +05:00
.setAuthor(message.translate("general/help:CMD_TITLE", {
cmd: cmd.help.name
}))
2021-12-10 21:39:54 +05:00
.addField(message.translate("general/help:FIELD_DESCRIPTION"), description)
.addField(message.translate("general/help:FIELD_USAGE"), usage)
.addField(message.translate("general/help:FIELD_EXAMPLES"), examples)
.addField(message.translate("general/help:FIELD_ALIASES"), cmd.help.aliases.length > 0 ? cmd.help.aliases.map(a => "`" + a + "`").join("\n") : message.translate("general/help:NO_ALIAS"))
2021-12-24 20:52:27 +05:00
.addField(message.translate("general/help:FIELD_PERMISSIONS"), cmd.conf.memberPermissions.length > 0 ? cmd.conf.memberPermissions.map((p) => `\`${p}\``).join("\n") : message.translate("general/help:NO_REQUIRED_PERMISSION"))
2021-12-10 21:39:54 +05:00
.setColor(this.client.config.embed.color)
.setFooter(this.client.config.embed.footer);
return message.channel.send(groupEmbed);
};
const categories = [];
const commands = this.client.commands;
commands.forEach((command) => {
if (!categories.includes(command.help.category)) {
if (command.help.category === "Owner" && message.author.id !== this.client.config.owner.id) return;
categories.push(command.help.category);
};
});
const emojis = this.client.customEmojis;
const embed = new Discord.MessageEmbed()
2021-12-26 19:29:37 +05:00
.setDescription(message.translate("general/help:INFO", {
prefix: message.guild ? data.guild.prefix : ""
}))
2021-12-10 21:39:54 +05:00
.setColor(data.config.embed.color)
.setFooter(data.config.embed.footer);
categories.sort().forEach((cat) => {
const tCommands = commands.filter((cmd) => cmd.help.category === cat);
2021-12-18 19:43:06 +05:00
embed.addField(`${emojis.categories[cat.toLowerCase()]} ${cat} - (${tCommands.size})`, `${tCommands.map((cmd) => `${cmd.help.name}`).join(", ")}`);
2021-12-10 21:39:54 +05:00
});
if (message.guild) {
2021-12-24 20:52:27 +05:00
if (data.guild.customCommands.length > 0) embed.addField(`${emojis.categories.custom} ${message.guild.name} | ${message.translate("general/help:CUSTOM_COMMANDS")} - (${data.guild.customCommands.length})`, data.guild.customCommands.map((cmd) => `\`${cmd.name}\``).join(", "));
2021-12-10 21:39:54 +05:00
};
embed.addField("\u200B", message.translate("misc:STATS_FOOTER", {
dashboardLink: "https://jaba.pp.ua/",
docsLink: "https://jaba.pp.ua/docs/",
donateLink: "https://qiwi.com/n/JONNYBRO/",
2021-12-18 19:02:50 +05:00
owner: this.client.config.owner.id
2021-12-10 21:39:54 +05:00
}));
2021-12-26 19:29:37 +05:00
embed.setAuthor(message.translate("general/help:TITLE", {
name: this.client.user.username
}), this.client.user.displayAvatarURL({
size: 512,
dynamic: true,
format: "png"
}));
2021-12-10 21:39:54 +05:00
return message.channel.send(embed);
}
};
module.exports = Help;