Remove the need to register slash commands separately
All checks were successful
continuous-integration/drone/push Build is passing

We modified the slash command interface to allow getting command data, and created a generic implementation of it that automatically retrieves data from the command data. The interface should not be used now. Instead, extending the implementation is preferred as it provides a semi-working command already.
This commit is contained in:
2022-11-22 16:39:31 +01:00
parent ee263a1297
commit a7ac446b0b
12 changed files with 126 additions and 65 deletions

View File

@@ -1,5 +1,6 @@
package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageHistory;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
@@ -8,22 +9,28 @@ import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.objects.SlashCommand;
import wtf.beatrice.hidekobot.objects.SlashCommandImpl;
import java.util.ArrayList;
import java.util.List;
public class ClearCommand implements SlashCommand
public class ClearCommand extends SlashCommandImpl
{
@Override
public String getCommandName() {
return "clear";
public CommandData getSlashCommandData() {
return Commands.slash("clear", "Clear the current channel's chat.")
.addOption(OptionType.INTEGER, "amount", "The amount of messages to delete.")
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MESSAGE_MANAGE));
}
@Override