update help cmd for running outside a guild
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 59s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 59s
This commit is contained in:
parent
650556079b
commit
4aae21b594
@ -45,7 +45,7 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||||
event.replyEmbeds(createHomeEmbed()).addComponents(createHomeActions()).queue();
|
event.replyEmbeds(createHomeEmbed(event.isFromGuild())).addComponents(createHomeActions(event.isFromGuild())).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,8 +56,8 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
|
|
||||||
// Get the item
|
// Get the item
|
||||||
String item = event.getSelectedOptions().get(0).getValue();
|
String item = event.getSelectedOptions().get(0).getValue();
|
||||||
if (item.equalsIgnoreCase("home")) {
|
if (item.equalsIgnoreCase("help-home")) {
|
||||||
event.editMessageEmbeds(createHomeEmbed()).queue();
|
event.editMessageEmbeds(createHomeEmbed(event.isFromGuild())).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
|
|
||||||
// Send the category
|
// Send the category
|
||||||
StringBuilder commands = new StringBuilder();
|
StringBuilder commands = new StringBuilder();
|
||||||
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category);
|
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category, event.isFromGuild());
|
||||||
if (categoryCommands.isEmpty()) {
|
if (categoryCommands.isEmpty()) {
|
||||||
commands = new StringBuilder("No commands available in this category.");
|
commands = new StringBuilder("No commands available in this category.");
|
||||||
} else {
|
} else {
|
||||||
@ -114,10 +114,13 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
*
|
*
|
||||||
* @return The home embed
|
* @return The home embed
|
||||||
*/
|
*/
|
||||||
private MessageEmbed createHomeEmbed() {
|
private MessageEmbed createHomeEmbed(boolean ranInsideGuild) {
|
||||||
StringBuilder categories = new StringBuilder();
|
StringBuilder categories = new StringBuilder();
|
||||||
for (Category category : Category.values()) {
|
for (Category category : Category.values()) {
|
||||||
long commandCount = commandService.getCommandsByCategory(category).size();
|
if (commandService.getCommandsByCategory(category, ranInsideGuild).isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
long commandCount = commandService.getCommandsByCategory(category, ranInsideGuild).size();
|
||||||
categories.append("➜ %s - **%s Command%s**\n".formatted(
|
categories.append("➜ %s - **%s Command%s**\n".formatted(
|
||||||
category.getName(),
|
category.getName(),
|
||||||
commandCount,
|
commandCount,
|
||||||
@ -127,11 +130,12 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
|
|
||||||
return EmbedUtils.genericEmbed()
|
return EmbedUtils.genericEmbed()
|
||||||
.setDescription("""
|
.setDescription("""
|
||||||
**Welcome to the Bat Help Menu!**
|
**Welcome to the Bat Help Menu!**%s
|
||||||
|
|
||||||
%s
|
%s
|
||||||
*View our [TOS](%s) and [Privacy Policy](%s) for more information.*
|
*View our [TOS](%s) and [Privacy Policy](%s) for more information.*
|
||||||
""".formatted(
|
""".formatted(
|
||||||
|
!ranInsideGuild ? "\n*guild only commands won't be shown here" : "",
|
||||||
categories.toString(),
|
categories.toString(),
|
||||||
Consts.TERMS_OF_SERVICE_URL,
|
Consts.TERMS_OF_SERVICE_URL,
|
||||||
Consts.PRIVACY_POLICY_URL
|
Consts.PRIVACY_POLICY_URL
|
||||||
@ -144,10 +148,13 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
*
|
*
|
||||||
* @return The layout components
|
* @return The layout components
|
||||||
*/
|
*/
|
||||||
private LayoutComponent[] createHomeActions() {
|
private LayoutComponent[] createHomeActions(boolean ranInsideGuild) {
|
||||||
List<SelectOption> options = new ArrayList<>();
|
List<SelectOption> options = new ArrayList<>();
|
||||||
options.add(SelectOption.of("Home", "help-home").withEmoji(Emoji.fromUnicode("U+1F3E0")));
|
options.add(SelectOption.of("Home", "help-home").withEmoji(Emoji.fromUnicode("U+1F3E0")));
|
||||||
for (Category category : Category.values()) {
|
for (Category category : Category.values()) {
|
||||||
|
if (commandService.getCommandsByCategory(category, ranInsideGuild).isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
options.add(SelectOption.of(category.getName(), "help-" + category.getName()).withEmoji(category.getEmoji()));
|
options.add(SelectOption.of(category.getName(), "help-" + category.getName()).withEmoji(category.getEmoji()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +134,17 @@ public class CommandService extends ListenerAdapter {
|
|||||||
* Gets commands that are in a specific category
|
* Gets commands that are in a specific category
|
||||||
*
|
*
|
||||||
* @param category The category
|
* @param category The category
|
||||||
|
* @param includeGuildCommands If guild commands should be included
|
||||||
* @return The commands
|
* @return The commands
|
||||||
*/
|
*/
|
||||||
public List<BatCommand> getCommandsByCategory(Category category) {
|
public List<BatCommand> getCommandsByCategory(Category category, boolean includeGuildCommands) {
|
||||||
return commands.values().stream().filter(command -> command.getInfo().getCategory() == category).toList();
|
List<BatCommand> commands = new ArrayList<>();
|
||||||
|
for (BatCommand command : this.commands.values()) {
|
||||||
|
if (command.getInfo().getCategory() == category && (includeGuildCommands || !command.getInfo().isGuildOnly())) {
|
||||||
|
commands.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user