fix premiumadmin command

This commit is contained in:
Lee 2024-06-27 21:12:31 +01:00
parent 73e4b58695
commit a7dc517a36
3 changed files with 10 additions and 3 deletions

@ -37,6 +37,11 @@ public abstract class BatCommand implements BatCommandExecutor {
*/ */
private Category category; private Category category;
/**
* Whether the command can only be used by the bot owner
*/
private boolean botOwnerOnly;
/** /**
* The command snowflake from Discord * The command snowflake from Discord
*/ */
@ -45,6 +50,7 @@ public abstract class BatCommand implements BatCommandExecutor {
public BatCommand() { public BatCommand() {
this.commandInfo = getClass().getAnnotation(CommandInfo.class); this.commandInfo = getClass().getAnnotation(CommandInfo.class);
this.category = this.commandInfo.category(); this.category = this.commandInfo.category();
this.botOwnerOnly = this.commandInfo.botOwnerOnly();
this.commandData = new CommandDataImpl(this.commandInfo.name(), this.commandInfo.description()) this.commandData = new CommandDataImpl(this.commandInfo.name(), this.commandInfo.description())
.setGuildOnly(this.commandInfo.guildOnly()); .setGuildOnly(this.commandInfo.guildOnly());

@ -1,6 +1,7 @@
package cc.fascinated.bat.command.impl.botadmin.premium; package cc.fascinated.bat.command.impl.botadmin.premium;
import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.Category;
import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.command.CommandInfo;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -11,7 +12,7 @@ import org.springframework.stereotype.Component;
* @author Fascinated (fascinated7) * @author Fascinated (fascinated7)
*/ */
@Component @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 { public class PremiumAdminCommand extends BatCommand {
@Autowired @Autowired
public PremiumAdminCommand(@NonNull ApplicationContext context) { public PremiumAdminCommand(@NonNull ApplicationContext context) {

@ -94,7 +94,7 @@ public class CommandService extends ListenerAdapter {
// Register all commands // Register all commands
List<Command> discordCommands = jda.updateCommands().addCommands(commands.values().stream() List<Command> discordCommands = jda.updateCommands().addCommands(commands.values().stream()
.filter(command -> !command.getCategory().isHidden()) .filter(command -> !command.getCategory().isHidden() || !command.isBotOwnerOnly())
.map(BatCommand::getCommandData).toList()).complete(); .map(BatCommand::getCommandData).toList()).complete();
for (Command discordCommand : discordCommands) { for (Command discordCommand : discordCommands) {
commands.get(discordCommand.getName()).setCommandSnowflake(discordCommand.getIdLong()); 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") Objects.requireNonNull(jda.getGuildById(Consts.ADMIN_GUILD), "Admin guild is null!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
.updateCommands().addCommands(commands.values().stream() .updateCommands().addCommands(commands.values().stream()
.filter(command -> command.getCategory().isHidden()) .filter(command -> !command.getCategory().isHidden() || !command.isBotOwnerOnly())
.map(BatCommand::getCommandData).toList()).complete(); .map(BatCommand::getCommandData).toList()).complete();
log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before); log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before);