forked from Fascinated/Bat
cleanup commands and fix cmds in dms(???????)
This commit is contained in:
@ -4,7 +4,9 @@ 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.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
||||
|
||||
@ -25,40 +27,69 @@ public abstract class BatCommand implements BatCommandExecutor {
|
||||
/**
|
||||
* The description of the command
|
||||
*/
|
||||
private String description;
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* The command data for the slash command
|
||||
*/
|
||||
private final CommandDataImpl commandData;
|
||||
|
||||
/**
|
||||
* The required permissions for the command
|
||||
*/
|
||||
private final List<Permission> requiredPermissions;
|
||||
|
||||
/**
|
||||
* The sub commands of the command
|
||||
*/
|
||||
private final Map<String, BatSubCommand> subCommands = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The category of the command
|
||||
*/
|
||||
private 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) {
|
||||
public BatCommand(@NonNull String name, @NonNull String description, boolean guildOnly, Permission... permissions) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.requiredPermissions = List.of(permissions);
|
||||
|
||||
// Default values
|
||||
this.description = "No description provided.";
|
||||
this.category = Category.GENERAL;
|
||||
|
||||
this.commandData = new CommandDataImpl(this.name, description)
|
||||
.setGuildOnly(guildOnly);
|
||||
}
|
||||
|
||||
public BatCommand(@NonNull String name) {
|
||||
this(name, "No description provided.", false);
|
||||
}
|
||||
|
||||
public BatCommand(@NonNull String name, @NonNull String description) {
|
||||
this(name, description, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a sub command to the command
|
||||
*
|
||||
* @param name The name of the sub command
|
||||
* @param name The name of the sub command
|
||||
* @param subCommand The sub command
|
||||
*/
|
||||
public BatCommand addSubCommand(@NonNull String name, @NonNull BatSubCommand subCommand) {
|
||||
public void addSubCommand(@NonNull String name, @NonNull BatSubCommand subCommand) {
|
||||
this.subCommands.put(name.toLowerCase(), subCommand);
|
||||
return this;
|
||||
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
|
||||
*/
|
||||
private void addOption(OptionType optionType, String name, String description, boolean required) {
|
||||
this.commandData.addOption(optionType, name, description, required);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,18 +11,17 @@ import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
public interface BatCommandExecutor {
|
||||
|
||||
/**
|
||||
* Executes the command using a slash command interaction.
|
||||
*
|
||||
* @param guild the bat guild the command was executed in
|
||||
* @param guild the bat guild the command was executed in (null if the command was executed in a DM)
|
||||
* @param user the bat user that executed the command
|
||||
* @param channel the channel the command was executed in
|
||||
* @param member the member that executed the command
|
||||
* @param interaction the slash command interaction
|
||||
*/
|
||||
default void execute(
|
||||
@NonNull BatGuild guild,
|
||||
BatGuild guild,
|
||||
@NonNull BatUser user,
|
||||
@NonNull TextChannel channel,
|
||||
@NonNull Member member,
|
||||
|
@ -1,10 +1,41 @@
|
||||
package cc.fascinated.bat.command;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@AllArgsConstructor @Getter
|
||||
public class BatSubCommand implements BatCommandExecutor { }
|
||||
@Getter
|
||||
public class BatSubCommand implements BatCommandExecutor {
|
||||
/**
|
||||
* The command data for the slash command
|
||||
*/
|
||||
private final SubcommandData commandData;
|
||||
|
||||
/**
|
||||
* The required permissions for the command
|
||||
*/
|
||||
private final List<Permission> requiredPermissions;
|
||||
|
||||
public BatSubCommand(String name, String description, Permission... permissions) {
|
||||
this.commandData = new SubcommandData(name, description);
|
||||
this.requiredPermissions = List.of(permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void addOption(OptionType optionType, String name, String description, boolean required) {
|
||||
this.commandData.addOption(optionType, name, description, required);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -18,9 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
public class PingCommand extends BatCommand {
|
||||
|
||||
public PingCommand() {
|
||||
super("ping");
|
||||
super.setDescription("Gets the ping of the bot");
|
||||
super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription()));
|
||||
super("ping", "Gets the ping of the bot");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user