2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder, ActionRowBuilder, StringSelectMenuBuilder, PermissionsBitField } = require("discord.js");
|
2022-08-01 20:06:09 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Help extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2022-08-01 20:06:09 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("help")
|
|
|
|
.setDescription(client.translate("general/help:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("general/help:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("general/help:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(true)
|
2022-08-01 20:06:09 +05:00
|
|
|
.addStringOption(option =>
|
2023-07-05 00:58:06 +05:00
|
|
|
option
|
|
|
|
.setName("command")
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescription(client.translate("common:COMMAND"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("common:COMMAND", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:COMMAND", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2023-07-05 00:58:06 +05:00
|
|
|
.setAutocomplete(true),
|
|
|
|
),
|
2022-08-01 20:06:09 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-01 20:06:09 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-08-01 20:06:09 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-01 20:06:09 +05:00
|
|
|
*/
|
2023-10-31 22:24:40 +05:00
|
|
|
async onLoad(client) {
|
|
|
|
client.on("interactionCreate", async interaction => {
|
|
|
|
if (!interaction.isStringSelectMenu()) return;
|
|
|
|
|
|
|
|
if (interaction.customId === "help_category_select") {
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
interaction.data = [];
|
2024-05-24 23:11:03 +05:00
|
|
|
interaction.data.guild = await client.getGuildData(interaction.guildId);
|
2024-02-09 23:26:57 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
const arg = interaction?.values[0];
|
|
|
|
const categoryCommands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()]
|
|
|
|
.filter(cmd => cmd.category === arg)
|
|
|
|
.map(c => {
|
|
|
|
return {
|
|
|
|
name: `**${c.command.name}**`,
|
|
|
|
value: interaction.translate(`${arg.toLowerCase()}/${c.command.name}:DESCRIPTION`),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
author: {
|
2023-10-31 22:24:40 +05:00
|
|
|
name: interaction.translate("general/help:COMMANDS_IN", { category: arg }),
|
2024-02-06 21:45:53 +05:00
|
|
|
},
|
|
|
|
fields: categoryCommands.concat({
|
|
|
|
name: "\u200B",
|
|
|
|
value: interaction.translate("general/help:INFO"),
|
|
|
|
}),
|
|
|
|
});
|
2023-10-31 22:24:40 +05:00
|
|
|
|
|
|
|
return interaction.editReply({
|
|
|
|
content: null,
|
|
|
|
embeds: [embed],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-08-01 20:06:09 +05:00
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-08-01 20:06:09 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-01 20:06:09 +05:00
|
|
|
* @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()];
|
2024-02-06 21:45:53 +05:00
|
|
|
const categories = [... new Set(commands.map(c => c.category))];
|
2022-08-01 20:06:09 +05:00
|
|
|
const command = interaction.options.getString("command");
|
|
|
|
|
2023-04-06 00:14:28 +05:00
|
|
|
if (command) {
|
2024-02-06 21:45:53 +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 });
|
|
|
|
else if (commands.find(c => c.command.name === command).category === "IAT" && interaction.guildId !== "1039187019957555252") return interaction.error("misc:OWNER_ONLY", null, { edit: true });
|
|
|
|
else return interaction.editReply({ embeds: [generateCommandHelp(interaction, command)] });
|
2023-04-06 00:14:28 +05:00
|
|
|
}
|
2022-08-01 20:06:09 +05:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
const row = new ActionRowBuilder().addComponents(new StringSelectMenuBuilder().setCustomId("help_category_select").setPlaceholder(interaction.translate("common:NOTHING_SELECTED")).addOptions(categoriesRows));
|
2022-08-01 20:06:09 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
await interaction.editReply({
|
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
|
|
|
});
|
|
|
|
}
|
2023-04-06 00:14:28 +05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-04-06 00:14:28 +05:00
|
|
|
* @param {import("discord.js").AutocompleteInteraction} interaction
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
async autocompleteRun(client, interaction) {
|
|
|
|
const command = interaction.options.getString("command"),
|
|
|
|
commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()],
|
2023-04-12 14:08:56 +05:00
|
|
|
results = commands.filter(c => c.command.name.includes(command));
|
2023-04-06 00:14:28 +05:00
|
|
|
|
2024-01-15 23:19:59 +05:00
|
|
|
return await interaction.respond(
|
2023-04-06 00:14:28 +05:00
|
|
|
results.slice(0, 25).map(command => ({
|
2023-04-12 14:08:56 +05:00
|
|
|
name: command.command.name,
|
|
|
|
value: command.command.name,
|
2023-07-05 00:58:06 +05:00
|
|
|
})),
|
|
|
|
);
|
2023-04-06 00:14:28 +05:00
|
|
|
}
|
2022-08-01 20:06:09 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPermName(bitfield = 0) {
|
2023-07-05 00:58:06 +05:00
|
|
|
for (const key in PermissionsBitField.Flags) if (PermissionsBitField.Flags[key] === BigInt(bitfield)) return key;
|
2022-08-01 20:06:09 +05:00
|
|
|
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
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
if (cmd.category === "Owner" && interaction.user.id !== interaction.client.config.owner.id) return interaction.error("misc:OWNER_ONLY", null, { edit: true });
|
|
|
|
else if (cmd.category === "IAT" && interaction.guildId !== "1039187019957555252") return interaction.error("misc:OWNER_ONLY", null, { edit: true });
|
2022-08-01 20:06:09 +05:00
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = interaction.client.embed({
|
|
|
|
author: {
|
2022-08-01 20:06:09 +05:00
|
|
|
name: interaction.translate("general/help:CMD_TITLE", {
|
2022-12-15 21:02:38 +05:00
|
|
|
cmd: cmd.command.name,
|
|
|
|
}),
|
2024-02-06 21:45:53 +05:00
|
|
|
},
|
|
|
|
fields: [
|
2022-08-01 20:06:09 +05:00
|
|
|
{
|
|
|
|
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"),
|
2024-02-06 21:45:53 +05:00
|
|
|
value: `*${cmd.command.dm_permission === false ? interaction.translate("general/help:GUILD_ONLY") : interaction.translate("general/help:NOT_GUILD_ONLY")}*\n\n${
|
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
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"),
|
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
],
|
|
|
|
});
|
2022-08-01 20:06:09 +05:00
|
|
|
|
|
|
|
return embed;
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Help;
|