From a7dc517a361c0df3685540cffea611890625fc41 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 27 Jun 2024 21:12:31 +0100 Subject: [PATCH] fix premiumadmin command --- src/main/java/cc/fascinated/bat/command/BatCommand.java | 6 ++++++ .../command/impl/botadmin/premium/PremiumAdminCommand.java | 3 ++- src/main/java/cc/fascinated/bat/service/CommandService.java | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/command/BatCommand.java b/src/main/java/cc/fascinated/bat/command/BatCommand.java index 7efb8fa..3fc7d4d 100644 --- a/src/main/java/cc/fascinated/bat/command/BatCommand.java +++ b/src/main/java/cc/fascinated/bat/command/BatCommand.java @@ -37,6 +37,11 @@ public abstract class BatCommand implements BatCommandExecutor { */ private Category category; + /** + * Whether the command can only be used by the bot owner + */ + private boolean botOwnerOnly; + /** * The command snowflake from Discord */ @@ -45,6 +50,7 @@ public abstract class BatCommand implements BatCommandExecutor { public BatCommand() { this.commandInfo = getClass().getAnnotation(CommandInfo.class); this.category = this.commandInfo.category(); + this.botOwnerOnly = this.commandInfo.botOwnerOnly(); this.commandData = new CommandDataImpl(this.commandInfo.name(), this.commandInfo.description()) .setGuildOnly(this.commandInfo.guildOnly()); diff --git a/src/main/java/cc/fascinated/bat/command/impl/botadmin/premium/PremiumAdminCommand.java b/src/main/java/cc/fascinated/bat/command/impl/botadmin/premium/PremiumAdminCommand.java index dc9b2cb..de4891a 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/botadmin/premium/PremiumAdminCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/botadmin/premium/PremiumAdminCommand.java @@ -1,6 +1,7 @@ package cc.fascinated.bat.command.impl.botadmin.premium; import cc.fascinated.bat.command.BatCommand; +import cc.fascinated.bat.command.Category; import cc.fascinated.bat.command.CommandInfo; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; @@ -11,7 +12,7 @@ import org.springframework.stereotype.Component; * @author Fascinated (fascinated7) */ @Component -@CommandInfo(name = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true) +@CommandInfo(name = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true, category = Category.BOT_ADMIN) public class PremiumAdminCommand extends BatCommand { @Autowired public PremiumAdminCommand(@NonNull ApplicationContext context) { diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 636d577..d34b24f 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -94,7 +94,7 @@ public class CommandService extends ListenerAdapter { // Register all commands List discordCommands = jda.updateCommands().addCommands(commands.values().stream() - .filter(command -> !command.getCategory().isHidden()) + .filter(command -> !command.getCategory().isHidden() || !command.isBotOwnerOnly()) .map(BatCommand::getCommandData).toList()).complete(); for (Command discordCommand : discordCommands) { commands.get(discordCommand.getName()).setCommandSnowflake(discordCommand.getIdLong()); @@ -107,7 +107,7 @@ public class CommandService extends ListenerAdapter { Objects.requireNonNull(jda.getGuildById(Consts.ADMIN_GUILD), "Admin guild is null!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") .updateCommands().addCommands(commands.values().stream() - .filter(command -> command.getCategory().isHidden()) + .filter(command -> !command.getCategory().isHidden() || !command.isBotOwnerOnly()) .map(BatCommand::getCommandData).toList()).complete(); log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before);