2022-12-17 13:33:33 +05:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, PermissionsBitField } = require("discord.js");
|
2022-08-01 20:06:09 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Help extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("help")
|
|
|
|
.setDescription(client.translate("general/help:DESCRIPTION"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("general/help:DESCRIPTION", null, "uk-UA") })
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(true)
|
2022-08-01 20:06:09 +05:00
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName("command")
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescription(client.translate("common:COMMAND"))
|
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("common:COMMAND", null, "uk-UA") })),
|
2022-08-01 20:06:09 +05:00
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-01 20:06:09 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {Object} data
|
2022-08-01 20:06:09 +05:00
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
2022-08-28 21:53:54 +05:00
|
|
|
await interaction.deferReply();
|
|
|
|
|
2022-08-01 20:06:09 +05:00
|
|
|
const commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()];
|
|
|
|
const categories = [];
|
|
|
|
const command = interaction.options.getString("command");
|
2023-03-26 18:31:19 +05:00
|
|
|
if ((commands.find(c => c.command.name === command).category === "Owner") && interaction.user.id !== client.config.owner.id) return interaction.error("misc:OWNER_ONLY", null, { edit: true, ephemeral: true });
|
2022-08-01 20:06:09 +05:00
|
|
|
|
2022-12-07 18:43:20 +05:00
|
|
|
if (command) return interaction.editReply({ embeds: [ generateCommandHelp(interaction, command) ] });
|
2022-08-01 20:06:09 +05:00
|
|
|
|
|
|
|
commands.forEach(c => {
|
|
|
|
if (!categories.includes(c.category)) {
|
2022-10-13 00:10:08 +05:00
|
|
|
if (c.category === "Owner" && interaction.user.id !== client.config.owner.id) return;
|
2022-08-01 20:06:09 +05:00
|
|
|
categories.push(c.category);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const categoriesRows = categories.sort().map(c => {
|
|
|
|
return {
|
|
|
|
label: `${c} (${commands.filter(cmd => cmd.category === c).length})`,
|
2022-12-15 21:02:38 +05:00
|
|
|
value: c,
|
2022-08-01 20:06:09 +05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const row = new ActionRowBuilder()
|
|
|
|
.addComponents(
|
2022-12-17 13:33:33 +05:00
|
|
|
new StringSelectMenuBuilder()
|
2022-08-01 20:06:09 +05:00
|
|
|
.setCustomId("help_category_select")
|
|
|
|
.setPlaceholder(client.translate("common:NOTHING_SELECTED"))
|
2022-12-15 21:02:38 +05:00
|
|
|
.addOptions(categoriesRows),
|
2022-08-01 20:06:09 +05:00
|
|
|
);
|
|
|
|
|
2022-10-13 00:11:31 +05:00
|
|
|
const msg = await interaction.editReply({
|
2022-08-08 18:19:56 +05:00
|
|
|
content: interaction.translate("common:AVAILABLE_OPTIONS"),
|
2022-10-13 00:11:31 +05:00
|
|
|
fetchReply: true,
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-01 20:06:09 +05:00
|
|
|
});
|
|
|
|
|
2022-08-28 21:53:54 +05:00
|
|
|
const filter = i => i.user.id === interaction.user.id;
|
2022-10-13 00:11:31 +05:00
|
|
|
const collector = msg.createMessageComponentCollector({ filter, idle: (15 * 1000) });
|
2022-08-28 21:53:54 +05:00
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
2022-12-17 13:33:33 +05:00
|
|
|
if (i.isStringSelectMenu() && i.customId === "help_category_select") {
|
2022-08-28 21:53:54 +05:00
|
|
|
i.deferUpdate();
|
|
|
|
|
|
|
|
const arg = i?.values[0];
|
2022-12-07 18:43:20 +05:00
|
|
|
const categoryCommands = commands.filter(cmd => cmd.category === arg).map(c => {
|
|
|
|
return {
|
|
|
|
name: `**${c.command.name}**`,
|
2022-12-15 21:02:38 +05:00
|
|
|
value: interaction.translate(`${arg.toLowerCase()}/${c.command.name}:DESCRIPTION`),
|
2022-12-07 18:43:20 +05:00
|
|
|
};
|
|
|
|
});
|
2022-08-28 21:53:54 +05:00
|
|
|
|
2022-12-07 18:43:20 +05:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor(client.config.embed.color)
|
|
|
|
.setFooter({
|
2022-12-15 21:02:38 +05:00
|
|
|
text: client.config.embed.footer,
|
2022-12-07 18:43:20 +05:00
|
|
|
})
|
|
|
|
.setAuthor({
|
2022-12-15 21:02:38 +05:00
|
|
|
name: interaction.translate("general/help:COMMANDS_IN", { category: arg }),
|
2022-12-07 18:43:20 +05:00
|
|
|
})
|
|
|
|
.addFields(categoryCommands)
|
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: "\u200B",
|
2022-12-15 21:02:38 +05:00
|
|
|
value: interaction.translate("general/help:INFO"),
|
|
|
|
},
|
2022-12-07 18:43:20 +05:00
|
|
|
]);
|
2022-08-28 21:53:54 +05:00
|
|
|
|
2022-12-07 18:43:20 +05:00
|
|
|
return interaction.editReply({
|
|
|
|
content: null,
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-12-07 18:43:20 +05:00
|
|
|
});
|
2022-08-01 20:06:09 +05:00
|
|
|
}
|
|
|
|
});
|
2022-08-26 00:21:26 +05:00
|
|
|
|
2022-08-28 21:53:54 +05:00
|
|
|
collector.on("end", () => {
|
|
|
|
return interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [],
|
2022-08-28 21:53:54 +05:00
|
|
|
});
|
2022-08-26 00:21:26 +05:00
|
|
|
});
|
2022-08-01 20:06:09 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPermName(bitfield = 0) {
|
|
|
|
for (const key in PermissionsBitField.Flags)
|
|
|
|
if (PermissionsBitField.Flags[key] === BigInt(bitfield)) return key;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-08-28 21:53:54 +05:00
|
|
|
function generateCommandHelp(interaction, command) {
|
|
|
|
const cmd = interaction.client.commands.get(command);
|
2022-09-13 12:25:57 +05:00
|
|
|
if (!cmd) return interaction.error("general/help:NOT_FOUND", { command }, { edit: true });
|
2023-03-26 18:31:19 +05:00
|
|
|
|
2022-09-13 12:18:42 +05:00
|
|
|
const usage = interaction.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:USAGE`) === "" ?
|
|
|
|
interaction.translate("misc:NO_ARGS")
|
|
|
|
: interaction.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:USAGE`);
|
2022-08-01 20:06:09 +05:00
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setAuthor({
|
|
|
|
name: interaction.translate("general/help:CMD_TITLE", {
|
2022-12-15 21:02:38 +05:00
|
|
|
cmd: cmd.command.name,
|
|
|
|
}),
|
2022-08-01 20:06:09 +05:00
|
|
|
})
|
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/help:FIELD_DESCRIPTION"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: interaction.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:DESCRIPTION`),
|
2022-08-01 20:06:09 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/help:FIELD_USAGE"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: `*${cmd.command.dm_permission === false ? interaction.translate("general/help:GUILD_ONLY") : interaction.translate("general/help:NOT_GUILD_ONLY")}*\n\n` + usage,
|
2022-08-01 20:06:09 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/help:FIELD_EXAMPLES"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: interaction.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:EXAMPLES`),
|
2022-08-01 20:06:09 +05:00
|
|
|
},
|
2022-11-18 16:04:04 +05:00
|
|
|
// {
|
|
|
|
// name: interaction.translate("general/help:FIELD_ALIASES"),
|
|
|
|
// value: cmd.aliases.length > 0 ? cmd.aliases.map(a => `${a}`).join("\n") : interaction.translate("general/help:NO_ALIAS")
|
|
|
|
// },
|
2022-08-01 20:06:09 +05:00
|
|
|
{
|
|
|
|
name: interaction.translate("general/help:FIELD_PERMISSIONS"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: cmd.command.default_member_permissions > 0 ? interaction.translate(`misc:PERMISSIONS:${getPermName(cmd.command.default_member_permissions)}`) : interaction.translate("general/help:NO_REQUIRED_PERMISSION"),
|
|
|
|
},
|
2022-08-01 20:06:09 +05:00
|
|
|
])
|
2022-08-28 21:53:54 +05:00
|
|
|
.setColor(interaction.client.config.embed.color)
|
2022-08-01 20:06:09 +05:00
|
|
|
.setFooter({
|
2022-12-15 21:02:38 +05:00
|
|
|
text: interaction.client.config.embed.footer,
|
2022-08-01 20:06:09 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
return embed;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Help;
|