forked from Fascinated/Bat
90 lines
2.2 KiB
Java
90 lines
2.2 KiB
Java
|
package cc.fascinated.bat.command;
|
||
|
|
||
|
import lombok.AllArgsConstructor;
|
||
|
import lombok.Getter;
|
||
|
import lombok.NonNull;
|
||
|
import lombok.Setter;
|
||
|
import net.dv8tion.jda.api.Permission;
|
||
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||
|
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 {
|
||
|
/**
|
||
|
* The name of the command
|
||
|
*/
|
||
|
private final String name;
|
||
|
|
||
|
/**
|
||
|
* The description of the command
|
||
|
*/
|
||
|
private String description;
|
||
|
|
||
|
/**
|
||
|
* The category of the command
|
||
|
*/
|
||
|
private final Category category;
|
||
|
|
||
|
/**
|
||
|
* The command data for the slash command
|
||
|
*/
|
||
|
private CommandDataImpl commandData;
|
||
|
|
||
|
/**
|
||
|
* The sub commands of the command
|
||
|
*/
|
||
|
private Map<String, BatSubCommand> subCommands = new HashMap<>();
|
||
|
|
||
|
public BatCommand(@NonNull String name) {
|
||
|
this.name = name;
|
||
|
|
||
|
// Default values
|
||
|
this.description = "No description provided.";
|
||
|
this.category = Category.GENERAL;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Adds a sub command to the command
|
||
|
*
|
||
|
* @param name The name of the sub command
|
||
|
* @param subCommand The sub command
|
||
|
*/
|
||
|
public BatCommand addSubCommand(@NonNull String name, @NonNull BatSubCommand subCommand) {
|
||
|
this.subCommands.put(name.toLowerCase(), subCommand);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* The category of the command
|
||
|
*/
|
||
|
@AllArgsConstructor @Getter
|
||
|
private enum Category {
|
||
|
GENERAL("General"),
|
||
|
MODERATION("Moderation"),
|
||
|
SERVER("Server");
|
||
|
|
||
|
/**
|
||
|
* The name of the category
|
||
|
*/
|
||
|
private final String name;
|
||
|
}
|
||
|
}
|