fix help command

This commit is contained in:
Lee 2024-06-27 21:21:56 +01:00
parent deb656086a
commit ff5b83f531
3 changed files with 21 additions and 4 deletions

@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import java.util.Arrays;
import java.util.List;
/**
* @author Fascinated (fascinated7)
*/
@ -31,6 +34,12 @@ public enum Category {
*/
private final boolean hidden;
/**
* Gets a category by its name
*
* @param name the name of the category
* @return the category
*/
public static Category getByName(String name) {
for (Category category : Category.values()) {
if (category.getName().equalsIgnoreCase(name)) {
@ -39,4 +48,13 @@ public enum Category {
}
return null;
}
/**
* Gets all the visible categories
*
* @return the visible categories
*/
public static List<Category> getCategories() {
return Arrays.stream(Category.values()).filter(category -> !category.isHidden()).toList();
}
}

@ -110,7 +110,7 @@ public class HelpCommand extends BatCommand implements EventListener {
*/
private MessageEmbed createHomeEmbed() {
String categories = "";
for (Category category : Category.values()) {
for (Category category : Category.getCategories()) {
long commandCount = commandService.getCommandsByCategory(category, true).size();
categories += "➜ %s - **%s Command%s**\n".formatted(
category.getName(),
@ -132,7 +132,7 @@ public class HelpCommand extends BatCommand implements EventListener {
private LayoutComponent[] createHomeActions() {
List<SelectOption> options = new ArrayList<>();
options.add(SelectOption.of("Home", "home").withEmoji(Emoji.fromUnicode("U+1F3E0")));
options.addAll(Arrays.stream(Category.values()).map(category ->
options.addAll(Category.getCategories().stream().map(category ->
SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji()))
.toList());

@ -81,7 +81,6 @@ public class CommandService extends ListenerAdapter {
log.info("Unregistered hidden command \"{}\" from Discord", command.getName());
return;
}
if (commands.containsKey(command.getName())) {
return;
}
@ -118,7 +117,7 @@ public class CommandService extends ListenerAdapter {
* @return The commands
*/
public List<BatCommand> getCommandsByCategory(Category category, boolean hideHiddenCategories) {
return commands.values().stream().filter(command -> command.getCategory() == category && (hideHiddenCategories && category.isHidden())).toList();
return commands.values().stream().filter(command -> command.getCategory() == category && (hideHiddenCategories && !category.isHidden())).toList();
}
@Override