Skip to content

Commit

Permalink
Fix help (#287)
Browse files Browse the repository at this point in the history
* Fix /help being too long

* Fix Naming on discord commands

* Update /info to also have fixed commands
  • Loading branch information
Kathund authored Dec 4, 2024
1 parent 06ad207 commit 5a8101f
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 166 deletions.
4 changes: 2 additions & 2 deletions src/discord/commands/blacklistCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ module.exports = {
],
},
{
name: "name",
name: "username",
description: "Minecraft Username",
type: 3,
required: true,
},
],

execute: async (interaction) => {
const name = interaction.options.getString("name");
const name = interaction.options.getString("username");
const arg = interaction.options.getString("arg").toLowerCase();

if (arg == "add") {
Expand Down
4 changes: 2 additions & 2 deletions src/discord/commands/demoteCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
requiresBot: true,
options: [
{
name: "name",
name: "username",
description: "Minecraft Username",
type: 3,
required: true,
},
],

execute: async (interaction) => {
const name = interaction.options.getString("name");
const name = interaction.options.getString("username");
bot.chat(`/g demote ${name}`);

const embed = new SuccessEmbed(`Successfully demoted \`${name}\` by one guild rank.`);
Expand Down
2 changes: 1 addition & 1 deletion src/discord/commands/forceVerifyCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
required: true,
},
{
name: "name",
name: "username",
description: "Minecraft Username",
type: 3,
required: true,
Expand Down
142 changes: 64 additions & 78 deletions src/discord/commands/helpCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js")
const { EmbedBuilder } = require("discord.js");
const config = require("../../../config.json");
const fs = require("fs");
const { getCommands } = require("./infoCommand.js");

module.exports = {
name: "help",
Expand All @@ -16,92 +17,77 @@ module.exports = {
],

execute: async (interaction) => {
const commandName = interaction.options.getString("command") || undefined;
try {
const commandName = interaction.options.getString("command") || undefined;
const { discordCommands, minecraftCommands } = getCommands(interaction.client.commands);

if (commandName === undefined) {
const discordCommands = interaction.client.commands
.map(({ name, options }) => {
const optionsString = options?.map(({ name, required }) => (required ? ` (${name})` : ` [${name}]`)).join("");
return `- \`${name}${optionsString ? optionsString : ""}\`\n`;
})
.join("");
if (commandName === undefined) {
const helpMenu = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle("Hypixel Discord Chat Bridge Commands")
.setDescription("`()` = **required** argument, `[]` = **optional** argument\n`u` = Minecraft Username")
.addFields(
{
name: "**Minecraft**: ",
value: `${minecraftCommands}`,
inline: true,
},
{
name: "**Discord**: ",
value: `${discordCommands}`,
inline: true,
},
)
.setFooter({
text: "by @duckysolucky | /help [command] for more information",
iconURL: "https://imgur.com/tgwQJTX.png",
});

const minecraftCommands = fs
.readdirSync("./src/minecraft/commands")
.filter((file) => file.endsWith(".js"))
.map((file) => {
const command = new (require(`../../minecraft/commands/${file}`))();
const optionsString = command.options
?.map(({ name, required }) => (required ? ` (${name})` : ` [${name}]`))
.join("");
await interaction.followUp({ embeds: [helpMenu] });
} else {
const minecraftCommand = fs
.readdirSync("./src/minecraft/commands")
.filter((file) => file.endsWith(".js"))
.map((file) => new (require(`../../minecraft/commands/${file}`))())
.find((command) => command.name === commandName || command.aliases.includes(commandName));

return `- \`${command.name}${optionsString}\`\n`;
})
.join("");
const type = minecraftCommand ? "minecraft" : "discord";

const helpMenu = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle("Hypixel Discord Chat Bridge Commands")
.setDescription("() = required argument, [] = optional argument")
.addFields(
{
name: "**Minecraft**: ",
value: `${minecraftCommands}`,
inline: true,
},
{
name: "**Discord**: ",
value: `${discordCommands}`,
inline: true,
},
)
.setFooter({
text: "by @duckysolucky | /help [command] for more information",
iconURL: "https://imgur.com/tgwQJTX.png",
});
const command = interaction.client.commands.find((command) => command.name === commandName) ?? minecraftCommand;
if (command === undefined) {
throw new HypixelDiscordChatBridgeError(`Command ${commandName} not found.`);
}

await interaction.followUp({ embeds: [helpMenu] });
} else {
const minecraftCommand = fs
.readdirSync("./src/minecraft/commands")
.filter((file) => file.endsWith(".js"))
.map((file) => new (require(`../../minecraft/commands/${file}`))())
.find((command) => command.name === commandName || command.aliases.includes(commandName));
const description = `${
command.aliases
? `\nAliases: ${command.aliases
.map((aliase) => {
return `\`${config.minecraft.bot.prefix}${aliase}\``;
})
.join(", ")}\n\n`
: ""
}${command.description}\n\n${
command.options
?.map(({ name, required, description }) => {
const optionString = required ? `(${name})` : `[${name}]`;
return `\`${optionString}\`: ${description}\n`;
})
.join("") || ""
}`;

const type = minecraftCommand ? "minecraft" : "discord";
const embed = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle(`**${type === "discord" ? "/" : config.minecraft.bot.prefix}${command.name}**`)
.setDescription(description + "\n")
.setFooter({
text: "by @duckysolucky | () = required, [] = optional",
iconURL: "https://imgur.com/tgwQJTX.png",
});

const command = interaction.client.commands.find((command) => command.name === commandName) ?? minecraftCommand;
if (command === undefined) {
throw new HypixelDiscordChatBridgeError(`Command ${commandName} not found.`);
await interaction.followUp({ embeds: [embed] });
}

const description = `${
command.aliases
? `\nAliases: ${command.aliases
.map((aliase) => {
return `\`${config.minecraft.bot.prefix}${aliase}\``;
})
.join(", ")}\n\n`
: ""
}${command.description}\n\n${
command.options
?.map(({ name, required, description }) => {
const optionString = required ? `(${name})` : `[${name}]`;
return `\`${optionString}\`: ${description}\n`;
})
.join("") || ""
}`;

const embed = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle(`**${type === "discord" ? "/" : config.minecraft.bot.prefix}${command.name}**`)
.setDescription(description + "\n")
.setFooter({
text: "by @duckysolucky | () = required, [] = optional",
iconURL: "https://imgur.com/tgwQJTX.png",
});

await interaction.followUp({ embeds: [embed] });
} catch (error) {
console.log(error);
}
},
};
145 changes: 76 additions & 69 deletions src/discord/commands/infoCommand.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,19 @@
const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js");
const { replaceVariables } = require("../../contracts/helperFunctions.js");
const { EmbedBuilder } = require("discord.js");
const config = require("../../../config.json");
const fs = require("fs");

module.exports = {
name: "info",
description: "Shows information about the bot.",
requiresBot: true,

execute: async (interaction) => {
if (bot === undefined || bot._client.chat === undefined) {
throw new HypixelDiscordChatBridgeError("Bot doesn't seem to be connected to Hypixel. Please try again.");
}

const commands = interaction.client.commands;

const { discordCommands, minecraftCommands } = getCommands(commands);

const infoEmbed = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle("Hypixel Bridge Bot Commands")
.addFields(
{
name: "**Minecraft Commands**: ",
value: `${minecraftCommands}`,
inline: true,
},
{
name: "**Discord Commands**: ",
value: `${discordCommands}`,
inline: true,
},
{ name: "\u200B", value: "\u200B" },
{
name: "**Minecraft Information**:",
value: `Bot Username: \`${bot.username}\`\nPrefix: \`${config.minecraft.bot.prefix}\`\nSkyBlock Events: \`${
config.minecraft.skyblockEventsNotifications.enabled ? "enabled" : "disabled"
}\`\nAuto Accept: \`${
config.minecraft.guildRequirements.autoAccept ? "enabled" : "disabled"
}\`\nGuild Experience Requirement: \`${config.minecraft.guild.guildExp.toLocaleString()}\`\nUptime: Online since <t:${Math.floor(
(Date.now() - client.uptime) / 1000,
)}:R>\nVersion: \`${require("../../../package.json").version}\`\n`,
inline: true,
},
{
name: `**Discord Information**`,
value: `Guild Channel: ${
config.discord.channels.guildChatChannel ? `<#${config.discord.channels.guildChatChannel}>` : "None"
}\nOfficer Channel: ${
config.discord.channels.officerChannel ? `<#${config.discord.channels.officerChannel}>` : "None"
}\nGuild Logs Channel: ${
config.discord.channels.loggingChannel ? `<#${config.discord.channels.loggingChannel}>` : "None"
}\nDebugging Channel: ${
config.discord.channels.debugChannel ? `<#${config.discord.channels.debugChannel}>` : "None"
}\nCommand Role: <@&${config.discord.commands.commandRole}>\nMessage Mode: \`${
config.discord.other.messageMode
}\`\nFilter: \`${config.discord.other.filterMessages ? "enabled" : "disabled"}\`\nJoin Messages: \`${
config.discord.other.joinMessage ? "enabled" : "disabled"
}\``,
inline: true,
},
)
.setFooter({
text: "by @duckysolucky | /help [command] for more information",
iconURL: "https://imgur.com/tgwQJTX.png",
});
await interaction.followUp({ embeds: [infoEmbed] });
},
};
function formatOptions(name, required) {
return replaceVariables(required ? ` ({${name}})` : ` [{${name}}]`, { username: "u" })
.replaceAll("{", "")
.replaceAll("}", "");
}

function getCommands(commands) {
const discordCommands = commands
.map(({ name, options }) => {
const optionsString = options?.map(({ name, required }) => (required ? ` (${name})` : ` [${name}]`)).join("");
const optionsString = options?.map(({ name, required }) => formatOptions(name, required)).join("");
return `- \`${name}${optionsString ? optionsString : ""}\`\n`;
})
.join("");
Expand All @@ -82,13 +23,79 @@ function getCommands(commands) {
.filter((file) => file.endsWith(".js"))
.map((file) => {
const command = new (require(`../../minecraft/commands/${file}`))();
const optionsString = command.options
?.map(({ name, required }) => (required ? ` (${name})` : ` [${name}]`))
.join("");
const optionsString = command.options?.map(({ name, required }) => formatOptions(name, required)).join("");

return `- \`${command.name}${optionsString}\`\n`;
})
.join("");

return { discordCommands, minecraftCommands };
}

module.exports = {
name: "info",
description: "Shows information about the bot.",
requiresBot: true,
getCommands,
execute: async (interaction) => {
try {
if (bot === undefined || bot._client.chat === undefined) {
throw new HypixelDiscordChatBridgeError("Bot doesn't seem to be connected to Hypixel. Please try again.");
}

const { discordCommands, minecraftCommands } = getCommands(interaction.client.commands);

const infoEmbed = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle("Hypixel Bridge Bot Commands")
.addFields(
{
name: "**Minecraft Commands**: ",
value: `${minecraftCommands}`,
inline: true,
},
{
name: "**Discord Commands**: ",
value: `${discordCommands}`,
inline: true,
},
{ name: "\u200B", value: "\u200B" },
{
name: "**Minecraft Information**:",
value: `Bot Username: \`${bot.username}\`\nPrefix: \`${config.minecraft.bot.prefix}\`\nSkyBlock Events: \`${
config.minecraft.skyblockEventsNotifications.enabled ? "enabled" : "disabled"
}\`\nAuto Accept: \`${
config.minecraft.guildRequirements.autoAccept ? "enabled" : "disabled"
}\`\nGuild Experience Requirement: \`${config.minecraft.guild.guildExp.toLocaleString()}\`\nUptime: Online since <t:${Math.floor(
(Date.now() - client.uptime) / 1000,
)}:R>\nVersion: \`${require("../../../package.json").version}\`\n`,
inline: true,
},
{
name: `**Discord Information**`,
value: `Guild Channel: ${
config.discord.channels.guildChatChannel ? `<#${config.discord.channels.guildChatChannel}>` : "None"
}\nOfficer Channel: ${
config.discord.channels.officerChannel ? `<#${config.discord.channels.officerChannel}>` : "None"
}\nGuild Logs Channel: ${
config.discord.channels.loggingChannel ? `<#${config.discord.channels.loggingChannel}>` : "None"
}\nDebugging Channel: ${
config.discord.channels.debugChannel ? `<#${config.discord.channels.debugChannel}>` : "None"
}\nCommand Role: <@&${config.discord.commands.commandRole}>\nMessage Mode: \`${
config.discord.other.messageMode
}\`\nFilter: \`${config.discord.other.filterMessages ? "enabled" : "disabled"}\`\nJoin Messages: \`${
config.discord.other.joinMessage ? "enabled" : "disabled"
}\``,
inline: true,
},
)
.setFooter({
text: "by @duckysolucky | /help [command] for more information",
iconURL: "https://imgur.com/tgwQJTX.png",
});
await interaction.followUp({ embeds: [infoEmbed] });
} catch (e) {
console.log(e);
}
},
};
4 changes: 2 additions & 2 deletions src/discord/commands/inviteCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
requiresBot: true,
options: [
{
name: "name",
name: "username",
description: "Minecraft Username",
type: 3,
required: true,
},
],

execute: async (interaction) => {
const name = interaction.options.getString("name");
const name = interaction.options.getString("username");
bot.chat(`/g invite ${name}`);

const embed = new SuccessEmbed(`Successfully invited **${name}** to the guild.`);
Expand Down
Loading

0 comments on commit 5a8101f

Please sign in to comment.