2024-06-24 13:56:01 +01:00
|
|
|
package cc.fascinated.bat.command;
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.NonNull;
|
|
|
|
import lombok.Setter;
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
2024-06-26 00:31:16 +01:00
|
|
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
2024-06-24 13:56:01 +01:00
|
|
|
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
|
|
|
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Fascinated (fascinated7)
|
|
|
|
*/
|
|
|
|
@Getter @Setter
|
|
|
|
public abstract class BatCommand implements BatCommandExecutor {
|
2024-06-27 16:01:27 +01:00
|
|
|
/**
|
2024-06-27 19:36:52 +01:00
|
|
|
* The information about the command
|
2024-06-24 13:56:01 +01:00
|
|
|
*/
|
2024-06-27 19:36:52 +01:00
|
|
|
private final CommandInfo commandInfo;
|
2024-06-24 13:56:01 +01:00
|
|
|
|
|
|
|
/**
|
2024-06-26 00:31:16 +01:00
|
|
|
* The command data for the slash command
|
2024-06-24 13:56:01 +01:00
|
|
|
*/
|
2024-06-26 00:31:16 +01:00
|
|
|
private final CommandDataImpl commandData;
|
2024-06-24 13:56:01 +01:00
|
|
|
|
|
|
|
/**
|
2024-06-27 19:36:52 +01:00
|
|
|
* The sub commands of the command
|
2024-06-24 13:56:01 +01:00
|
|
|
*/
|
2024-06-27 19:36:52 +01:00
|
|
|
private final Map<String, BatSubCommand> subCommands = new HashMap<>();
|
2024-06-24 13:56:01 +01:00
|
|
|
|
|
|
|
/**
|
2024-06-27 19:36:52 +01:00
|
|
|
* The category of the command
|
2024-06-24 13:56:01 +01:00
|
|
|
*/
|
2024-06-27 19:36:52 +01:00
|
|
|
private Category category;
|
2024-06-24 13:56:01 +01:00
|
|
|
|
2024-06-27 16:01:27 +01:00
|
|
|
/**
|
2024-06-27 19:36:52 +01:00
|
|
|
* The command snowflake from Discord
|
2024-06-27 16:01:27 +01:00
|
|
|
*/
|
|
|
|
private long commandSnowflake;
|
|
|
|
|
2024-06-27 19:36:52 +01:00
|
|
|
public BatCommand() {
|
|
|
|
this.commandInfo = getClass().getAnnotation(CommandInfo.class);
|
|
|
|
this.category = this.commandInfo.category();
|
2024-06-26 00:31:16 +01:00
|
|
|
|
2024-06-27 19:36:52 +01:00
|
|
|
this.commandData = new CommandDataImpl(this.commandInfo.name(), this.commandInfo.description())
|
|
|
|
.setGuildOnly(this.commandInfo.guildOnly());
|
2024-06-24 13:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a sub command to the command
|
|
|
|
*
|
|
|
|
* @param subCommand The sub command
|
|
|
|
*/
|
2024-06-27 19:36:52 +01:00
|
|
|
public void addSubCommand(@NonNull BatSubCommand subCommand) {
|
|
|
|
this.subCommands.put(subCommand.getCommandInfo().name().toLowerCase(), subCommand);
|
2024-06-26 00:31:16 +01:00
|
|
|
this.commandData.addSubcommands(subCommand.getCommandData());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an option to the sub command
|
|
|
|
*
|
|
|
|
* @param optionType the type of the option
|
|
|
|
* @param name the name of the option
|
|
|
|
* @param description the description of the option
|
|
|
|
* @param required whether the option is required
|
|
|
|
*/
|
2024-06-26 02:46:27 +01:00
|
|
|
protected void addOption(OptionType optionType, String name, String description, boolean required) {
|
2024-06-26 00:31:16 +01:00
|
|
|
this.commandData.addOption(optionType, name, description, required);
|
2024-06-24 13:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all the options for the command
|
|
|
|
*
|
|
|
|
* @param interaction The slash command interaction
|
|
|
|
* @return The option strings
|
|
|
|
*/
|
|
|
|
public List<String> getOptions(SlashCommandInteraction interaction) {
|
|
|
|
return interaction.getOptions().stream().map(OptionMapping::getName).toList();
|
|
|
|
}
|
|
|
|
}
|